bump version
[gitmo/MooseX-Types-Common.git] / lib / MooseX / Types / Common / String.pm
CommitLineData
ac73ab52 1package MooseX::Types::Common::String;
2
3use strict;
4use warnings;
5
c89e0261 6our $VERSION = '0.001003';
ac73ab52 7
8use MooseX::Types -declare => [
9 qw(SimpleStr NonEmptySimpleStr Password StrongPassword NonEmptyStr)
10];
11
12use MooseX::Types::Moose qw/Str/;
13
14subtype SimpleStr,
15 as Str,
16 where { (length($_) <= 255) && ($_ !~ m/\n/) },
d2461fda 17 message { "Must be a single line of no more than 255 chars" },
18 ( $Moose::VERSION >= 2.0200
19 ? inline_as {
20 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
21 . qq{ ( (length($_[1]) <= 255) && ($_[1] !~ m/\n/) ) };
22 }
23 : ()
24 );
ac73ab52 25
26subtype NonEmptySimpleStr,
27 as SimpleStr,
28 where { length($_) > 0 },
d2461fda 29 message { "Must be a non-empty single line of no more than 255 chars" },
30 ( $Moose::VERSION >= 2.0200
31 ? inline_as {
32 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
33 . qq{ (length($_[1]) > 0) };
34 }
35 : ()
36 );
ac73ab52 37
38# XXX duplicating constraint msges since moose only uses last message
39subtype Password,
40 as NonEmptySimpleStr,
41 where { length($_) > 3 },
d2461fda 42 message { "Must be between 4 and 255 chars" },
43 ( $Moose::VERSION >= 2.0200
44 ? inline_as {
45 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
46 . qq{ (length($_[1]) > 3) };
47 }
48 : ()
49 );
ac73ab52 50
51subtype StrongPassword,
52 as Password,
53 where { (length($_) > 7) && (m/[^a-zA-Z]/) },
d2461fda 54 message {"Must be between 8 and 255 chars, and contain a non-alpha char" },
55 ( $Moose::VERSION >= 2.0200
56 ? inline_as {
57 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
58 . qq{ ( (length($_[1]) > 7) && ($_[1] =~ m/[^a-zA-Z]/) ) };
59 }
60 : ()
61 );
ac73ab52 62
63subtype NonEmptyStr,
64 as Str,
65 where { length($_) > 0 },
d2461fda 66 message { "Must not be empty" },
67 ( $Moose::VERSION >= 2.0200
68 ? inline_as {
69 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
70 . qq{ (length($_[1]) > 0) };
71 }
72 : ()
73 );
ac73ab52 74
75
761;
77
78=head1 NAME
79
6820e939 80MooseX::Types::Common::String - Commonly used string types
ac73ab52 81
82=head1 SYNOPSIS
83
84 use MooseX::Types::Common::String qw/SimpleStr/;
85 has short_str => (is => 'rw', isa => SimpleStr);
86
87 ...
88 #this will fail
89 $object->short_str("string\nwith\nbreaks");
90
91=head1 DESCRIPTION
92
93A set of commonly-used string type constraints that do not ship with Moose by
94default.
95
96=over
97
98=item * SimpleStr
99
100A Str with no new-line characters.
101
102=item * NonEmptySimpleStr
103
104Does what it says on the tin.
105
106=item * Password
107
108=item * StrongPassword
109
110=item * NonEmptyStr
111
112=back
113
114=head1 SEE ALSO
115
116=over
117
118=item * L<MooseX::Types::Common::Numeric>
119
120=back
121
122=head1 AUTHORS
123
124Please see:: L<MooseX::Types::Common>
125
126=cut