1 package MooseX::Types::Common::String;
6 our $VERSION = '0.001003';
8 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 { length($_) > 3 },
49 message { "Must be between 4 and 255 chars" },
50 ( $Moose::VERSION >= 2.0200
52 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
53 . qq{ (length($_[1]) > 3) };
58 subtype StrongPassword,
60 where { (length($_) > 7) && (m/[^a-zA-Z]/) },
61 message {"Must be between 8 and 255 chars, and contain a non-alpha char" },
62 ( $Moose::VERSION >= 2.0200
64 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
65 . qq{ ( (length($_[1]) > 7) && ($_[1] =~ m/[^a-zA-Z]/) ) };
72 where { length($_) > 0 },
73 message { "Must not be empty" },
74 ( $Moose::VERSION >= 2.0200
76 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
77 . qq{ (length($_[1]) > 0) };
84 where { /^[a-z]+$/xms },
85 message { "Must only contain lower case letters" },
86 ( $Moose::VERSION >= 2.0200
88 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
89 . qq{ ( $_[1] =~ m/^[a-z]+\$/xms ) };
100 where { /^[A-Z]+$/xms },
101 message { "Must only contain upper case letters" },
102 ( $Moose::VERSION >= 2.0200
104 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
105 . qq{ ( $_[1] =~ m/^[A-Z]+\$/xms ) };
114 subtype LowerCaseSimpleStr,
115 as NonEmptySimpleStr,
116 where { /^[a-z]+$/x },
117 message { "Must only contain lower case letters" },
118 ( $Moose::VERSION >= 2.0200
120 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
121 . qq{ ( $_[1] =~ m/^[a-z]+\$/x ) };
126 coerce LowerCaseSimpleStr,
127 from NonEmptySimpleStr,
130 subtype UpperCaseSimpleStr,
131 as NonEmptySimpleStr,
132 where { /^[A-Z]+$/x },
133 message { "Must only contain upper case letters" },
134 ( $Moose::VERSION >= 2.0200
136 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
137 . qq{ ( $_[1] =~ m/^[A-Z]+\$/x ) };
142 coerce UpperCaseSimpleStr,
143 from NonEmptySimpleStr,
150 MooseX::Types::Common::String - Commonly used string types
154 use MooseX::Types::Common::String qw/SimpleStr/;
155 has short_str => (is => 'rw', isa => SimpleStr);
159 $object->short_str("string\nwith\nbreaks");
163 A set of commonly-used string type constraints that do not ship with Moose by
170 A Str with no new-line characters.
172 =item * NonEmptySimpleStr
174 A Str with no new-line characters and length > 0
176 =item * LowerCaseSimpleStr
178 A Str with no new-line characters, length > 0 and all lowercase characters
179 A coercion exists via C<lc> from NonEmptySimpleStr
181 =item * UpperCaseSimpleStr
183 A Str with no new-line characters, length > 0 and all uppercase characters
184 A coercion exists via C<uc> from NonEmptySimpleStr
188 =item * StrongPassword
192 A Str with length > 0
196 A Str with length > 0 and all lowercase characters.
197 A coercion exists via C<lc> from NonEmptyStr
201 A Str with length > 0 and all uppercase characters.
202 A coercion exists via C<uc> from NonEmptyStr
210 =item * L<MooseX::Types::Common::Numeric>
216 Please see:: L<MooseX::Types::Common>