Commit | Line | Data |
ac73ab52 |
1 | package MooseX::Types::Common::String; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | our $VERSION = '0.001000'; |
7 | |
8 | use MooseX::Types -declare => [ |
9 | qw(SimpleStr NonEmptySimpleStr Password StrongPassword NonEmptyStr) |
10 | ]; |
11 | |
12 | use MooseX::Types::Moose qw/Str/; |
13 | |
14 | subtype SimpleStr, |
15 | as Str, |
16 | where { (length($_) <= 255) && ($_ !~ m/\n/) }, |
17 | message { "Must be a single line of no more than 255 chars" }; |
18 | |
19 | subtype 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 |
25 | subtype Password, |
26 | as NonEmptySimpleStr, |
27 | where { length($_) > 3 }, |
28 | message { "Must be between 4 and 255 chars" }; |
29 | |
30 | subtype 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 | |
35 | subtype NonEmptyStr, |
36 | as Str, |
37 | where { length($_) > 0 }, |
38 | message { "Must not be empty" }; |
39 | |
40 | |
41 | 1; |
42 | |
43 | =head1 NAME |
44 | |
45 | MooseX::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 | |
58 | A set of commonly-used string type constraints that do not ship with Moose by |
59 | default. |
60 | |
61 | =over |
62 | |
63 | =item * SimpleStr |
64 | |
65 | A Str with no new-line characters. |
66 | |
67 | =item * NonEmptySimpleStr |
68 | |
69 | Does 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 | |
89 | Please see:: L<MooseX::Types::Common> |
90 | |
91 | =cut |