line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Types::Common::String; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$MooseX::Types::Common::String::VERSION = '0.001012'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
BEGIN { |
6
|
4
|
|
|
4
|
|
121486
|
$MooseX::Types::Common::String::AUTHORITY = 'cpan:GRODITI'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
# ABSTRACT: Commonly used string types |
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
38
|
use strict; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
134
|
|
11
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
198
|
|
12
|
|
|
|
|
|
|
|
13
|
4
|
|
|
|
|
61
|
use MooseX::Types -declare => [ |
14
|
|
|
|
|
|
|
qw(SimpleStr |
15
|
|
|
|
|
|
|
NonEmptySimpleStr |
16
|
|
|
|
|
|
|
NumericCode |
17
|
|
|
|
|
|
|
LowerCaseSimpleStr |
18
|
|
|
|
|
|
|
UpperCaseSimpleStr |
19
|
|
|
|
|
|
|
Password |
20
|
|
|
|
|
|
|
StrongPassword |
21
|
|
|
|
|
|
|
NonEmptyStr |
22
|
|
|
|
|
|
|
LowerCaseStr |
23
|
|
|
|
|
|
|
UpperCaseStr) |
24
|
4
|
|
|
4
|
|
4525
|
]; |
|
4
|
|
|
|
|
2433481
|
|
25
|
|
|
|
|
|
|
|
26
|
4
|
|
|
4
|
|
41659
|
use MooseX::Types::Moose qw/Str/; |
|
4
|
|
|
|
|
69397
|
|
|
4
|
|
|
|
|
53
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
subtype SimpleStr, |
29
|
|
|
|
|
|
|
as Str, |
30
|
|
|
|
|
|
|
where { (length($_) <= 255) && ($_ !~ m/\n/) }, |
31
|
|
|
|
|
|
|
message { "Must be a single line of no more than 255 chars" }, |
32
|
|
|
|
|
|
|
( $Moose::VERSION >= 2.0200 |
33
|
|
|
|
|
|
|
? inline_as { |
34
|
|
|
|
|
|
|
$_[0]->parent()->_inline_check( $_[1] ) . ' && ' |
35
|
|
|
|
|
|
|
. qq{ ( (length($_[1]) <= 255) && ($_[1] !~ m/\n/) ) }; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
: () |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
subtype NonEmptySimpleStr, |
41
|
|
|
|
|
|
|
as SimpleStr, |
42
|
|
|
|
|
|
|
where { length($_) > 0 }, |
43
|
|
|
|
|
|
|
message { "Must be a non-empty single line of no more than 255 chars" }, |
44
|
|
|
|
|
|
|
( $Moose::VERSION >= 2.0200 |
45
|
|
|
|
|
|
|
? inline_as { |
46
|
|
|
|
|
|
|
$_[0]->parent()->_inline_check( $_[1] ) . ' && ' |
47
|
|
|
|
|
|
|
. qq{ (length($_[1]) > 0) }; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
: () |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
subtype NumericCode, |
53
|
|
|
|
|
|
|
as NonEmptySimpleStr, |
54
|
|
|
|
|
|
|
where { $_ =~ m/^[0-9]+$/ }, |
55
|
|
|
|
|
|
|
message { |
56
|
|
|
|
|
|
|
'Must be a non-empty single line of no more than 255 chars that consists ' |
57
|
|
|
|
|
|
|
. 'of numeric characters only' |
58
|
|
|
|
|
|
|
}; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
coerce NumericCode, |
61
|
|
|
|
|
|
|
from NonEmptySimpleStr, |
62
|
|
|
|
|
|
|
via { my $code = $_; $code =~ s/[[:punct:]]//g; return $code }; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
subtype Password, |
65
|
|
|
|
|
|
|
as NonEmptySimpleStr, |
66
|
|
|
|
|
|
|
where { length($_) > 3 }, |
67
|
|
|
|
|
|
|
message { "Must be between 4 and 255 chars" }, |
68
|
|
|
|
|
|
|
( $Moose::VERSION >= 2.0200 |
69
|
|
|
|
|
|
|
? inline_as { |
70
|
|
|
|
|
|
|
$_[0]->parent()->_inline_check( $_[1] ) . ' && ' |
71
|
|
|
|
|
|
|
. qq{ (length($_[1]) > 3) }; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
: () |
74
|
|
|
|
|
|
|
); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
subtype StrongPassword, |
77
|
|
|
|
|
|
|
as Password, |
78
|
|
|
|
|
|
|
where { (length($_) > 7) && (m/[^a-zA-Z]/) }, |
79
|
|
|
|
|
|
|
message {"Must be between 8 and 255 chars, and contain a non-alpha char" }, |
80
|
|
|
|
|
|
|
( $Moose::VERSION >= 2.0200 |
81
|
|
|
|
|
|
|
? inline_as { |
82
|
|
|
|
|
|
|
$_[0]->parent()->_inline_check( $_[1] ) . ' && ' |
83
|
|
|
|
|
|
|
. qq{ ( (length($_[1]) > 7) && ($_[1] =~ m/[^a-zA-Z]/) ) }; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
: () |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
subtype NonEmptyStr, |
89
|
|
|
|
|
|
|
as Str, |
90
|
|
|
|
|
|
|
where { length($_) > 0 }, |
91
|
|
|
|
|
|
|
message { "Must not be empty" }, |
92
|
|
|
|
|
|
|
( $Moose::VERSION >= 2.0200 |
93
|
|
|
|
|
|
|
? inline_as { |
94
|
|
|
|
|
|
|
$_[0]->parent()->_inline_check( $_[1] ) . ' && ' |
95
|
|
|
|
|
|
|
. qq{ (length($_[1]) > 0) }; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
: () |
98
|
|
|
|
|
|
|
); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
subtype LowerCaseStr, |
101
|
|
|
|
|
|
|
as NonEmptyStr, |
102
|
4
|
|
|
4
|
|
30415
|
where { !/\p{Upper}/ms }, |
|
4
|
|
|
|
|
39
|
|
|
4
|
|
|
|
|
65
|
|
103
|
|
|
|
|
|
|
message { "Must not contain upper case letters" }, |
104
|
|
|
|
|
|
|
( $Moose::VERSION >= 2.0200 |
105
|
|
|
|
|
|
|
? inline_as { |
106
|
|
|
|
|
|
|
$_[0]->parent()->_inline_check( $_[1] ) . ' && ' |
107
|
|
|
|
|
|
|
. qq{ ( $_[1] !~ /\\p{Upper}/ms ) }; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
: () |
110
|
|
|
|
|
|
|
); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
coerce LowerCaseStr, |
113
|
|
|
|
|
|
|
from NonEmptyStr, |
114
|
|
|
|
|
|
|
via { lc }; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
subtype UpperCaseStr, |
117
|
|
|
|
|
|
|
as NonEmptyStr, |
118
|
|
|
|
|
|
|
where { !/\p{Lower}/ms }, |
119
|
|
|
|
|
|
|
message { "Must not contain lower case letters" }, |
120
|
|
|
|
|
|
|
( $Moose::VERSION >= 2.0200 |
121
|
|
|
|
|
|
|
? inline_as { |
122
|
|
|
|
|
|
|
$_[0]->parent()->_inline_check( $_[1] ) . ' && ' |
123
|
|
|
|
|
|
|
. qq{ ( $_[1] !~ /\\p{Lower}/ms ) }; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
: () |
126
|
|
|
|
|
|
|
); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
coerce UpperCaseStr, |
129
|
|
|
|
|
|
|
from NonEmptyStr, |
130
|
|
|
|
|
|
|
via { uc }; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
subtype LowerCaseSimpleStr, |
133
|
|
|
|
|
|
|
as NonEmptySimpleStr, |
134
|
|
|
|
|
|
|
where { !/\p{Upper}/ }, |
135
|
|
|
|
|
|
|
message { "Must not contain upper case letters" }, |
136
|
|
|
|
|
|
|
( $Moose::VERSION >= 2.0200 |
137
|
|
|
|
|
|
|
? inline_as { |
138
|
|
|
|
|
|
|
$_[0]->parent()->_inline_check( $_[1] ) . ' && ' |
139
|
|
|
|
|
|
|
. qq{ ( $_[1] !~ /\\p{Upper}/ ) }; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
: () |
142
|
|
|
|
|
|
|
); |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
coerce LowerCaseSimpleStr, |
145
|
|
|
|
|
|
|
from NonEmptySimpleStr, |
146
|
|
|
|
|
|
|
via { lc }; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
subtype UpperCaseSimpleStr, |
149
|
|
|
|
|
|
|
as NonEmptySimpleStr, |
150
|
|
|
|
|
|
|
where { !/\p{Lower}/ }, |
151
|
|
|
|
|
|
|
message { "Must not contain lower case letters" }, |
152
|
|
|
|
|
|
|
( $Moose::VERSION >= 2.0200 |
153
|
|
|
|
|
|
|
? inline_as { |
154
|
|
|
|
|
|
|
$_[0]->parent()->_inline_check( $_[1] ) . ' && ' |
155
|
|
|
|
|
|
|
. qq{ ( $_[1] !~ /\\p{Lower}/ ) }; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
: () |
158
|
|
|
|
|
|
|
); |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
coerce UpperCaseSimpleStr, |
161
|
|
|
|
|
|
|
from NonEmptySimpleStr, |
162
|
|
|
|
|
|
|
via { uc }; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
1; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
__END__ |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=pod |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=encoding UTF-8 |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=for :stopwords Matt S Trout - mst (at) shadowcatsystems.co.uk |
173
|
|
|
|
|
|
|
(L<http://www.shadowcatsystems.co.uk/>) K. James Cheetham Guillermo Roditi |
174
|
|
|
|
|
|
|
Caleb Toby Inkster Tomas Doran Cushing Dave Rolsky Graham Knop Justin |
175
|
|
|
|
|
|
|
Hunter Karen Etheridge |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 NAME |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
MooseX::Types::Common::String - Commonly used string types |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 VERSION |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
version 0.001012 |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 SYNOPSIS |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
use MooseX::Types::Common::String qw/SimpleStr/; |
188
|
|
|
|
|
|
|
has short_str => (is => 'rw', isa => SimpleStr); |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
... |
191
|
|
|
|
|
|
|
#this will fail |
192
|
|
|
|
|
|
|
$object->short_str("string\nwith\nbreaks"); |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 DESCRIPTION |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
A set of commonly-used string type constraints that do not ship with Moose by |
197
|
|
|
|
|
|
|
default. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=over |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=item * C<SimpleStr> |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
A C<Str> with no new-line characters. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=item * C<NonEmptySimpleStr> |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
A C<Str> with no new-line characters and length > 0 |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=item * C<LowerCaseSimpleStr> |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
A C<Str> with no new-line characters, length > 0 and no uppercase characters |
212
|
|
|
|
|
|
|
A coercion exists via C<lc> from C<NonEmptySimpleStr> |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item * C<UpperCaseSimpleStr> |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
A C<Str> with no new-line characters, length > 0 and no lowercase characters |
217
|
|
|
|
|
|
|
A coercion exists via C<uc> from C<NonEmptySimpleStr> |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=item * C<Password> |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=item * C<StrongPassword> |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item * C<NonEmptyStr> |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
A C<Str> with length > 0 |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=item * C<LowerCaseStr> |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
A C<Str> with length > 0 and no uppercase characters. |
230
|
|
|
|
|
|
|
A coercion exists via C<lc> from C<NonEmptyStr> |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=item * C<UpperCaseStr> |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
A C<Str> with length > 0 and no lowercase characters. |
235
|
|
|
|
|
|
|
A coercion exists via C<uc> from C<NonEmptyStr> |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=item * C<NumericCode> |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
A C<Str> with no new-line characters that consists of only Numeric characters. |
240
|
|
|
|
|
|
|
Examples include, Social Security Numbers, Personal Identification Numbers, Postal Codes, HTTP Status |
241
|
|
|
|
|
|
|
Codes, etc. Supports attempting to coerce from a string that has punctuation |
242
|
|
|
|
|
|
|
in it ( e.g credit card number 4111-1111-1111-1111 ). |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=back |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head1 SEE ALSO |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=over |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=item * L<MooseX::Types::Common::Numeric> |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=back |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head1 AUTHORS |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=over 4 |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=item * |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
Matt S Trout - mst (at) shadowcatsystems.co.uk (L<http://www.shadowcatsystems.co.uk/>) |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=item * |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
K. James Cheetham <jamie@shadowcatsystems.co.uk> |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=item * |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
Guillermo Roditi <groditi@gmail.com> |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=back |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
This software is copyright (c) 2013 by Matt S Trout - mst (at) shadowcatsystems.co.uk (L<http://www.shadowcatsystems.co.uk/>). |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
277
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=cut |