new URI type
[catagits/Reaction.git] / lib / Reaction / Types / Core.pm
CommitLineData
7adfd53f 1package Reaction::Types::Core;
2
e739c9a2 3use MooseX::Types
4 -declare => [qw/SimpleStr NonEmptySimpleStr Password StrongPassword
fb32a4e0 5 NonEmptyStr PositiveNum PositiveInt SingleDigit URI/];
e739c9a2 6
fb32a4e0 7use MooseX::Types::Moose qw/Str Num Int Object/;
7adfd53f 8
d9a3266f 9subtype SimpleStr,
10 as Str,
11 where { (length($_) <= 255) && ($_ !~ m/\n/) },
12 message { "Must be a single line of no more than 255 chars" };
7adfd53f 13
d9a3266f 14subtype NonEmptySimpleStr,
15 as SimpleStr,
16 where { length($_) > 0 },
17 message { "Must be a non-empty single line of no more than 255 chars" };
7adfd53f 18
19# XXX duplicating constraint msges since moose only uses last message
20
d9a3266f 21subtype Password,
22 as NonEmptySimpleStr,
23 where { length($_) > 3 },
24 message { "Must be between 4 and 255 chars" };
7adfd53f 25
d9a3266f 26subtype StrongPassword,
27 as Password,
28 where { (length($_) > 7) && (m/[^a-zA-Z]/) },
29 message {
e739c9a2 30 "Must be between 8 and 255 chars, and contain a non-alpha char" };
7adfd53f 31
d9a3266f 32subtype NonEmptyStr,
33 as Str,
34 where { length($_) > 0 },
35 message { "Must not be empty" };
36
37subtype PositiveNum,
38 as Num,
39 where { $_ >= 0 },
40 message { "Must be a positive number" };
41
42subtype PositiveInt,
43 as Int,
44 where { $_ >= 0 },
45 message { "Must be a positive integer" };
46
47subtype SingleDigit,
48 as PositiveInt,
49 where { $_ <= 9 },
50 message { "Must be a single digit" };
7adfd53f 51
fb32a4e0 52
53class_type 'URI', message { 'Must be an URI object'};
54coerce 'URI', from 'Str', via { URI->new($_) };
55
7adfd53f 561;
57
58=head1 NAME
59
60Reaction::Types::Core
61
62=head1 SYNOPSIS
63
64=head1 DESCRIPTION
65
66Reaction uses the L<Moose> attributes as a base and adds a few of it's own.
67
fb32a4e0 68=over
7adfd53f 69
70=item * SimpleStr
71
72A Str with no new-line characters.
73
74=item * NonEmptySimpleStr
75
76Does what it says on the tin.
77
78=item * Password
79
80=item * StrongPassword
81
82=item * NonEmptyStr
83
84=item * PositiveNum
85
86=item * PositiveInt
87
88=item * SingleDigit
89
90=back
91
92=head1 SEE ALSO
93
fb32a4e0 94=over
7adfd53f 95
96=item * L<Moose::Util::TypeConstraints>
97
98=item * L<Reaction::Types::DBIC>
99
100=item * L<Reaction::Types::DateTime>
101
102=item * L<Reaction::Types::Email>
103
104=item * L<Reaction::Types::File>
105
106=back
107
108=head1 AUTHORS
109
110See L<Reaction::Class> for authors.
111
112=head1 LICENSE
113
114See L<Reaction::Class> for the license.
115
116=cut