Data::Sah::Type::str - Specification for type 'str'
version 0.03
str stores text. Elements of str are characters. The default encoding is utf8.
Unless specified otherwise, all clauses have a priority of 50 (normal).
str assumes the following roles: Data::Sah::Type::Base, Data::Sah::Type::Comparable, Data::Sah::Type::Sortable, and Data::Sah::Type::HasElems. Consult the documentation of those role(s) to see what clauses are available.
In addition, str defines these clauses:
Require that string match the specified regular expression.
Since regular expressions might not be 100% compatible from language to language due to different flavors/implementations, instead of avoiding the use of regex entirely, you can specify different regex for each target language, e.g.:
[str => {match => { js => '...', perl => '...', python => '...', }}]
Note that to match multiple regexes, you can utilize the clause attributes 'vals':
# string must match a, b, and c [str => {"match.vals"=>[a, b, c]}] # idem, shortcut form [str => {"match&"=>[a, b, c]}] # string must match either a or b or c [str => {"match.vals"=>[a, b, c], "match.min_ok"=>1}] # idem, shortcut form [str => {"match|"=>[a, b, c]}] # string must NOT match a [str => {match=>a, "match.max_ok"=>0}] # idem, shortcut form [str => {"!match"=>a}] # string must NOT match a nor b nor c (i.e. must match none of those) [str => {"match.vals"=>[a, b, c], "match.max_ok"=>0}] # string must at least not match a or b or c (i.e. if all match, schema fail; # if at least one does not match, schema succeeds) [str => {"match.vals"=>[a, b, c], "match.max_ok"=>2}]
If value is true, require that the string be a valid regular expression string. If value is false, require that the string not be a valid regular expression string.
Steven Haryanto <stevenharyanto@gmail.com>
This software is copyright (c) 2012 by Steven Haryanto.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Data::Sah, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Sah
CPAN shell
perl -MCPAN -e shell install Data::Sah
For more information on module installation, please visit the detailed CPAN module installation guide.