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