add manifest skip file
[gitmo/MooseX-Types-Common.git] / lib / MooseX / Types / Common / String.pm
CommitLineData
ac73ab52 1package MooseX::Types::Common::String;
2
3use strict;
4use warnings;
5
6our $VERSION = '0.001000';
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/) },
17 message { "Must be a single line of no more than 255 chars" };
18
19subtype NonEmptySimpleStr,
20 as SimpleStr,
21 where { length($_) > 0 },
22 message { "Must be a non-empty single line of no more than 255 chars" };
23
24# XXX duplicating constraint msges since moose only uses last message
25subtype Password,
26 as NonEmptySimpleStr,
27 where { length($_) > 3 },
28 message { "Must be between 4 and 255 chars" };
29
30subtype StrongPassword,
31 as Password,
32 where { (length($_) > 7) && (m/[^a-zA-Z]/) },
33 message {"Must be between 8 and 255 chars, and contain a non-alpha char" };
34
35subtype NonEmptyStr,
36 as Str,
37 where { length($_) > 0 },
38 message { "Must not be empty" };
39
40
411;
42
43=head1 NAME
44
45MooseX::Types::Common::String
46
47=head1 SYNOPSIS
48
49 use MooseX::Types::Common::String qw/SimpleStr/;
50 has short_str => (is => 'rw', isa => SimpleStr);
51
52 ...
53 #this will fail
54 $object->short_str("string\nwith\nbreaks");
55
56=head1 DESCRIPTION
57
58A set of commonly-used string type constraints that do not ship with Moose by
59default.
60
61=over
62
63=item * SimpleStr
64
65A Str with no new-line characters.
66
67=item * NonEmptySimpleStr
68
69Does what it says on the tin.
70
71=item * Password
72
73=item * StrongPassword
74
75=item * NonEmptyStr
76
77=back
78
79=head1 SEE ALSO
80
81=over
82
83=item * L<MooseX::Types::Common::Numeric>
84
85=back
86
87=head1 AUTHORS
88
89Please see:: L<MooseX::Types::Common>
90
91=cut