1 package MooseX::Types::Common::String;
6 our $VERSION = '0.001001';
8 use MooseX::Types -declare => [
9 qw(SimpleStr NonEmptySimpleStr Password StrongPassword NonEmptyStr)
12 use MooseX::Types::Moose qw/Str/;
16 where { (length($_) <= 255) && ($_ !~ m/\n/) },
17 message { "Must be a single line of no more than 255 chars" },
18 ( $Moose::VERSION >= 2.0200
20 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
21 . qq{ ( (length($_[1]) <= 255) && ($_[1] !~ m/\n/) ) };
26 subtype NonEmptySimpleStr,
28 where { length($_) > 0 },
29 message { "Must be a non-empty single line of no more than 255 chars" },
30 ( $Moose::VERSION >= 2.0200
32 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
33 . qq{ (length($_[1]) > 0) };
38 # XXX duplicating constraint msges since moose only uses last message
41 where { length($_) > 3 },
42 message { "Must be between 4 and 255 chars" },
43 ( $Moose::VERSION >= 2.0200
45 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
46 . qq{ (length($_[1]) > 3) };
51 subtype StrongPassword,
53 where { (length($_) > 7) && (m/[^a-zA-Z]/) },
54 message {"Must be between 8 and 255 chars, and contain a non-alpha char" },
55 ( $Moose::VERSION >= 2.0200
57 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
58 . qq{ ( (length($_[1]) > 7) && ($_[1] =~ m/[^a-zA-Z]/) ) };
65 where { length($_) > 0 },
66 message { "Must not be empty" },
67 ( $Moose::VERSION >= 2.0200
69 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
70 . qq{ (length($_[1]) > 0) };
80 MooseX::Types::Common::String - Commonly used string types
84 use MooseX::Types::Common::String qw/SimpleStr/;
85 has short_str => (is => 'rw', isa => SimpleStr);
89 $object->short_str("string\nwith\nbreaks");
93 A set of commonly-used string type constraints that do not ship with Moose by
100 A Str with no new-line characters.
102 =item * NonEmptySimpleStr
104 Does what it says on the tin.
108 =item * StrongPassword
118 =item * L<MooseX::Types::Common::Numeric>
124 Please see:: L<MooseX::Types::Common>