aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/Types/Core.pm
blob: afd7454e44381407138046e7a3d0d58a5217152c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package Reaction::Types::Core;

use MooseX::Types
    -declare => [qw/SimpleStr NonEmptySimpleStr Password StrongPassword
                    NonEmptyStr PositiveNum PositiveInt SingleDigit/];

use MooseX::Types::Moose qw/Str Num Int/;

subtype SimpleStr,
  as Str,
  where { (length($_) <= 255) && ($_ !~ m/\n/) },
  message { "Must be a single line of no more than 255 chars" };

subtype NonEmptySimpleStr,
  as SimpleStr,
  where { length($_) > 0 },
  message { "Must be a non-empty single line of no more than 255 chars" };

# XXX duplicating constraint msges since moose only uses last message

subtype Password,
  as NonEmptySimpleStr,
  where { length($_) > 3 },
  message { "Must be between 4 and 255 chars" };

subtype StrongPassword,
  as Password,
  where { (length($_) > 7) && (m/[^a-zA-Z]/) },
  message {
       "Must be between 8 and 255 chars, and contain a non-alpha char" };

subtype NonEmptyStr,
  as Str,
  where { length($_) > 0 },
  message { "Must not be empty" };

subtype PositiveNum,
  as Num,
  where { $_ >= 0 },
  message { "Must be a positive number" };

subtype PositiveInt,
  as Int,
  where { $_ >= 0 },
  message { "Must be a positive integer" };

subtype SingleDigit,
  as PositiveInt,
  where { $_ <= 9 },
  message { "Must be a single digit" };

1;

=head1 NAME

Reaction::Types::Core

=head1 SYNOPSIS

=head1 DESCRIPTION

Reaction uses the L<Moose> attributes as a base and adds a few of it's own.

=over 

=item * SimpleStr

A Str with no new-line characters.

=item * NonEmptySimpleStr

Does what it says on the tin.

=item * Password

=item * StrongPassword

=item * NonEmptyStr

=item * PositiveNum

=item * PositiveInt

=item * SingleDigit

=back

=head1 SEE ALSO

=over 

=item * L<Moose::Util::TypeConstraints>

=item * L<Reaction::Types::DBIC>

=item * L<Reaction::Types::DateTime>

=item * L<Reaction::Types::Email>

=item * L<Reaction::Types::File>

=back

=head1 AUTHORS

See L<Reaction::Class> for authors.

=head1 LICENSE

See L<Reaction::Class> for the license.

=cut