1 package MooseX::Types::Common::String;
6 our $VERSION = '0.001005';
8 use MooseX::Types -declare => [
21 use MooseX::Types::Moose qw/Str/;
25 where { (length($_) <= 255) && ($_ !~ m/\n/) },
26 message { "Must be a single line of no more than 255 chars" },
27 ( $Moose::VERSION >= 2.0200
29 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
30 . qq{ ( (length($_[1]) <= 255) && ($_[1] !~ m/\n/) ) };
35 subtype NonEmptySimpleStr,
37 where { length($_) > 0 },
38 message { "Must be a non-empty single line of no more than 255 chars" },
39 ( $Moose::VERSION >= 2.0200
41 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
42 . qq{ (length($_[1]) > 0) };
49 where { $_ =~ m/^[0-9]+$/ },
51 'Must be a non-empty single line of no more than 255 chars that consists '
52 . 'of numeric characters only'
56 from NonEmptySimpleStr,
57 via { my $code = $_; $code =~ s/[[:punct:]]//g; return $code };
61 where { length($_) > 3 },
62 message { "Must be between 4 and 255 chars" },
63 ( $Moose::VERSION >= 2.0200
65 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
66 . qq{ (length($_[1]) > 3) };
71 subtype StrongPassword,
73 where { (length($_) > 7) && (m/[^a-zA-Z]/) },
74 message {"Must be between 8 and 255 chars, and contain a non-alpha char" },
75 ( $Moose::VERSION >= 2.0200
77 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
78 . qq{ ( (length($_[1]) > 7) && ($_[1] =~ m/[^a-zA-Z]/) ) };
85 where { length($_) > 0 },
86 message { "Must not be empty" },
87 ( $Moose::VERSION >= 2.0200
89 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
90 . qq{ (length($_[1]) > 0) };
97 where { /^[a-z]+$/xms },
98 message { "Must only contain lower case letters" },
99 ( $Moose::VERSION >= 2.0200
101 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
102 . qq{ ( $_[1] =~ m/^[a-z]+\$/xms ) };
111 subtype UpperCaseStr,
113 where { /^[A-Z]+$/xms },
114 message { "Must only contain upper case letters" },
115 ( $Moose::VERSION >= 2.0200
117 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
118 . qq{ ( $_[1] =~ m/^[A-Z]+\$/xms ) };
127 subtype LowerCaseSimpleStr,
128 as NonEmptySimpleStr,
129 where { /^[a-z]+$/x },
130 message { "Must only contain lower case letters" },
131 ( $Moose::VERSION >= 2.0200
133 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
134 . qq{ ( $_[1] =~ m/^[a-z]+\$/x ) };
139 coerce LowerCaseSimpleStr,
140 from NonEmptySimpleStr,
143 subtype UpperCaseSimpleStr,
144 as NonEmptySimpleStr,
145 where { /^[A-Z]+$/x },
146 message { "Must only contain upper case letters" },
147 ( $Moose::VERSION >= 2.0200
149 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
150 . qq{ ( $_[1] =~ m/^[A-Z]+\$/x ) };
155 coerce UpperCaseSimpleStr,
156 from NonEmptySimpleStr,
163 MooseX::Types::Common::String - Commonly used string types
167 use MooseX::Types::Common::String qw/SimpleStr/;
168 has short_str => (is => 'rw', isa => SimpleStr);
172 $object->short_str("string\nwith\nbreaks");
176 A set of commonly-used string type constraints that do not ship with Moose by
183 A Str with no new-line characters.
185 =item * NonEmptySimpleStr
187 A Str with no new-line characters and length > 0
189 =item * LowerCaseSimpleStr
191 A Str with no new-line characters, length > 0 and all lowercase characters
192 A coercion exists via C<lc> from NonEmptySimpleStr
194 =item * UpperCaseSimpleStr
196 A Str with no new-line characters, length > 0 and all uppercase characters
197 A coercion exists via C<uc> from NonEmptySimpleStr
201 =item * StrongPassword
205 A Str with length > 0
209 A Str with length > 0 and all lowercase characters.
210 A coercion exists via C<lc> from NonEmptyStr
214 A Str with length > 0 and all uppercase characters.
215 A coercion exists via C<uc> from NonEmptyStr
219 A Str with no new-line characters that consists of only Numeric characters.
220 Examples include, Social Security Numbers, PINs, Postal Codes, HTTP Status
221 Codes, etc. Supports attempting to coerce from a string that has punctuation
222 in it ( e.g credit card number 4111-1111-1111-1111 ).
230 =item * L<MooseX::Types::Common::Numeric>
236 Please see:: L<MooseX::Types::Common>