NAME
Sah::Schemas::Str - Various string schemas
VERSION
This document describes version 0.016 of Sah::Schemas::Str (from Perl distribution Sah-Schemas-Str), released on 2023-10-23.
SAH SCHEMAS
The following schemas are included in this distribution:
-
String of bytes in hexadecimal notation, e.g. "ab99" or "CAFE".
Whitespace is allowed and will be removed.
-
String containing only zero or more Latin letters, i.e. A-Z or a-z.
-
String containing only zero or more Latin letters/digits, i.e. A-Za-z0-9.
-
A single latin letter, i.e. A-Z or a-z.
-
String containing only zero or more lowercases Latin letters, i.e. a-z.
Uppercase letters will be coerced to lowercase.
-
A single latin lowercase letter, i.e. a-z.
-
String containing only zero or more uppercase Latin letters, i.e. A-Z.
Uppercase letters will be coerced to lowercase.
-
A single latin uppercase letter, i.e. A-Z.
-
String containing only zero or more lowercase letters.
Uppercase letters will be coerced to lowercase.
-
A non-empty string (length >= 1) (alias for str1).
-
A number in percent form, e.g. "10.5%".
This schema accepts floating number followed by percent sign. Unlike the
percent
schema from Sah::Schemas::Float, The percent sign will not be removed nor the number be converted to decimal (e.g. 50% to 0.5). -
A non-empty string (length >= 1).
-
String or array (0+ length) of (defined) string.
-
String or array (1+ length) of (defined) string.
-
String or coderef (if string is of the form `sub {...}`).
Either string or coderef is accepted.
If string matches the regex
qr/\Asub\s*\{.*\}\z/s
, then it will be eval'ed into a coderef. If the code fails to compile, the value will be rejected. Note that this means you accept arbitrary code from the user to execute! Please make sure first and foremost that this is acceptable in your case.Currently string is eval'ed in the
main
package, withoutuse strict
oruse warnings
.This schema is handy if you want to accept string or coderef from the command-line.
-
String or regex (if string is of the form `/.../`).
Either string or Regexp object is accepted.
If string is of the form of
/.../
orqr(...)
, then it will be compiled into a Regexp object. If the regex pattern inside/.../
orqr(...)
is invalid, value will be rejected.Currently, unlike in normal Perl, for the
qr(...)
form, only parentheses(
and)
are allowed as the delimiter.Currently modifiers
i
,m
, ands
after the second/
are allowed. -
String, or regex (if string is of the form `/.../`), or coderef (if string is in the form of `sub { ... }`).
Either string, Regexp object, or coderef is accepted.
If string is of the form of
/.../
orqr(...)
, then it will be compiled into a Regexp object. If the regex pattern inside/.../
orqr(...)
is invalid, value will be rejected. Currently, unlike in normal Perl, for theqr(...)
form, only parentheses(
and)
are allowed as the delimiter. Currently modifiersi
,m
, ands
after the second/
are allowed.If string matches the regex
qr/\Asub\s*\{.*\}\z/s
, then it will be eval'ed into a coderef. If the code fails to compile, the value will be rejected. Note that this means you accept arbitrary code from the user to execute! Please make sure first and foremost that this is acceptable in your case. Currently string is eval'ed in themain
package, withoutuse strict
oruse warnings
.This schema is handy if you want to accept string or regex or coderef from the command-line.
-
String containing only zero or more uppercase letters.
Uppercase letters will be coerced to lowercase.
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/Sah-Schemas-Str.
SOURCE
Source repository is at https://github.com/perlancar/perl-Sah-Schemas-Str.
SEE ALSO
Sah - schema specification
Data::Sah - Perl implementation of Sah
Related schemas from Sah::Schemas::Re
AUTHOR
perlancar <perlancar@cpan.org>
CONTRIBUTING
To contribute, you can send patches by email/via RT, or send pull requests on GitHub.
Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:
% prove -l
If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me.
COPYRIGHT AND LICENSE
This software is copyright (c) 2023, 2022, 2020 by perlancar <perlancar@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Sah-Schemas-Str
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.