1 package MooseX::Types::Common::String;
2 # ABSTRACT: Commonly used string types
7 use MooseX::Types -declare => [
20 use MooseX::Types::Moose qw/Str/;
24 where { (length($_) <= 255) && ($_ !~ m/\n/) },
25 message { "Must be a single line of no more than 255 chars" },
26 ( $Moose::VERSION >= 2.0200
28 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
29 . qq{ ( (length($_[1]) <= 255) && ($_[1] !~ m/\n/) ) };
34 subtype NonEmptySimpleStr,
36 where { length($_) > 0 },
37 message { "Must be a non-empty single line of no more than 255 chars" },
38 ( $Moose::VERSION >= 2.0200
40 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
41 . qq{ (length($_[1]) > 0) };
48 where { $_ =~ m/^[0-9]+$/ },
50 'Must be a non-empty single line of no more than 255 chars that consists '
51 . 'of numeric characters only'
55 from NonEmptySimpleStr,
56 via { my $code = $_; $code =~ s/[[:punct:]]//g; return $code };
60 where { length($_) > 3 },
61 message { "Must be between 4 and 255 chars" },
62 ( $Moose::VERSION >= 2.0200
64 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
65 . qq{ (length($_[1]) > 3) };
70 subtype StrongPassword,
72 where { (length($_) > 7) && (m/[^a-zA-Z]/) },
73 message {"Must be between 8 and 255 chars, and contain a non-alpha char" },
74 ( $Moose::VERSION >= 2.0200
76 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
77 . qq{ ( (length($_[1]) > 7) && ($_[1] =~ m/[^a-zA-Z]/) ) };
84 where { length($_) > 0 },
85 message { "Must not be empty" },
86 ( $Moose::VERSION >= 2.0200
88 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
89 . qq{ (length($_[1]) > 0) };
97 message { "Must not contain upper case letters" },
98 ( $Moose::VERSION >= 2.0200
100 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
101 . qq{ ( $_[1] !~ /[A-Z]/ms ) };
110 subtype UpperCaseStr,
112 where { !/[a-z]/ms },
113 message { "Must not contain lower case letters" },
114 ( $Moose::VERSION >= 2.0200
116 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
117 . qq{ ( $_[1] !~ m/[a-z]/ms ) };
126 subtype LowerCaseSimpleStr,
127 as NonEmptySimpleStr,
129 message { "Must not contain upper case letters" },
130 ( $Moose::VERSION >= 2.0200
132 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
133 . qq{ ( $_[1] !~ m/[A-Z]/ ) };
138 coerce LowerCaseSimpleStr,
139 from NonEmptySimpleStr,
142 subtype UpperCaseSimpleStr,
143 as NonEmptySimpleStr,
145 message { "Must not contain lower case letters" },
146 ( $Moose::VERSION >= 2.0200
148 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
149 . qq{ ( $_[1] !~ m/[a-z]/ ) };
154 coerce UpperCaseSimpleStr,
155 from NonEmptySimpleStr,
165 use MooseX::Types::Common::String qw/SimpleStr/;
166 has short_str => (is => 'rw', isa => SimpleStr);
170 $object->short_str("string\nwith\nbreaks");
174 A set of commonly-used string type constraints that do not ship with Moose by
181 A C<Str> with no new-line characters.
183 =item * C<NonEmptySimpleStr>
185 A C<Str> with no new-line characters and length > 0
187 =item * C<LowerCaseSimpleStr>
189 A C<Str> with no new-line characters, length > 0 and no uppercase characters
190 A coercion exists via C<lc> from C<NonEmptySimpleStr>
192 =item * C<UpperCaseSimpleStr>
194 A C<Str> with no new-line characters, length > 0 and no lowercase characters
195 A coercion exists via C<uc> from C<NonEmptySimpleStr>
199 =item * C<StrongPassword>
201 =item * C<NonEmptyStr>
203 A C<Str> with length > 0
205 =item * C<LowerCaseStr>
207 A C<Str> with length > 0 and no uppercase characters.
208 A coercion exists via C<lc> from C<NonEmptyStr>
210 =item * C<UpperCaseStr>
212 A C<Str> with length > 0 and no lowercase characters.
213 A coercion exists via C<uc> from C<NonEmptyStr>
215 =item * C<NumericCode>
217 A C<Str> with no new-line characters that consists of only Numeric characters.
218 Examples include, Social Security Numbers, Personal Identification Numbers, Postal Codes, HTTP Status
219 Codes, etc. Supports attempting to coerce from a string that has punctuation
220 in it ( e.g credit card number 4111-1111-1111-1111 ).
228 =item * L<MooseX::Types::Common::Numeric>