The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Data::Sah::Type::str - Specification for type 'str'

VERSION

version 0.03

DESCRIPTION

str stores text. Elements of str are characters. The default encoding is utf8.

CLAUSES

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:

match => REGEX|{COMPILER=>REGEX, ...}

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}]

is_regex => BOOL

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.

AUTHOR

Steven Haryanto <stevenharyanto@gmail.com>

COPYRIGHT AND LICENSE

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.