line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Types::Perl; |
2
|
|
|
|
|
|
|
# ABSTRACT: Moose types that check against Perl syntax |
3
|
|
|
|
|
|
|
$MooseX::Types::Perl::VERSION = '0.101343'; |
4
|
1
|
|
|
|
|
12
|
use MooseX::Types -declare => [ qw( |
5
|
|
|
|
|
|
|
DistName |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
ModuleName |
8
|
|
|
|
|
|
|
PackageName |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Identifier |
11
|
|
|
|
|
|
|
SafeIdentifier |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
LaxVersionStr |
14
|
|
|
|
|
|
|
StrictVersionStr |
15
|
|
|
|
|
|
|
VersionObject |
16
|
1
|
|
|
1
|
|
114955
|
) ]; |
|
1
|
|
|
|
|
1102720
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# =head1 SYNOPSIS |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
# use MooseX::Types::Perl qw( |
21
|
|
|
|
|
|
|
# DistName |
22
|
|
|
|
|
|
|
# |
23
|
|
|
|
|
|
|
# ModuleName |
24
|
|
|
|
|
|
|
# PackageName |
25
|
|
|
|
|
|
|
# |
26
|
|
|
|
|
|
|
# Identifier |
27
|
|
|
|
|
|
|
# SafeIdentifier |
28
|
|
|
|
|
|
|
# |
29
|
|
|
|
|
|
|
# LaxVersionStr |
30
|
|
|
|
|
|
|
# StrictVersionStr |
31
|
|
|
|
|
|
|
# VersionObject |
32
|
|
|
|
|
|
|
# ); |
33
|
|
|
|
|
|
|
# |
34
|
|
|
|
|
|
|
# =head1 DESCRIPTION |
35
|
|
|
|
|
|
|
# |
36
|
|
|
|
|
|
|
# This library provides L<Moose types|MooseX::Types> for checking things (mostly |
37
|
|
|
|
|
|
|
# strings) against syntax that is, or is a reasonable subset of, Perl syntax. |
38
|
|
|
|
|
|
|
# |
39
|
|
|
|
|
|
|
# =cut |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
1
|
|
9385
|
use MooseX::Types::Moose qw(Object Str); |
|
1
|
|
|
|
|
16410
|
|
|
1
|
|
|
|
|
14
|
|
42
|
1
|
|
|
1
|
|
5515
|
use Params::Util qw(_CLASS); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
64
|
|
43
|
1
|
|
|
1
|
|
946
|
use version 0.82; |
|
1
|
|
|
|
|
2173
|
|
|
1
|
|
|
|
|
7
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# =head1 TYPES |
46
|
|
|
|
|
|
|
# |
47
|
|
|
|
|
|
|
# =head2 ModuleName |
48
|
|
|
|
|
|
|
# |
49
|
|
|
|
|
|
|
# =head2 PackageName |
50
|
|
|
|
|
|
|
# |
51
|
|
|
|
|
|
|
# These types are identical, and expect a string that could be a package or |
52
|
|
|
|
|
|
|
# module name. That's basically a bunch of identifiers stuck together with |
53
|
|
|
|
|
|
|
# double-colons. One key quirk is that parts of the package name after the |
54
|
|
|
|
|
|
|
# first may begin with digits. |
55
|
|
|
|
|
|
|
# |
56
|
|
|
|
|
|
|
# The use of an apostrophe as a package separator is not permitted. |
57
|
|
|
|
|
|
|
# |
58
|
|
|
|
|
|
|
# =cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
subtype ModuleName, as Str, where { ! /\P{ASCII}/ && _CLASS($_) }; |
61
|
|
|
|
|
|
|
subtype PackageName, as Str, where { ! /\P{ASCII}/ && _CLASS($_) }; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# =head2 DistName |
64
|
|
|
|
|
|
|
# |
65
|
|
|
|
|
|
|
# The DistName type checks for a string like C<MooseX-Types-Perl>, the sort of |
66
|
|
|
|
|
|
|
# thing used to name CPAN distributions. In general, it's like the more familiar |
67
|
|
|
|
|
|
|
# L<ModuleName>, but with hyphens instead of double-colons. |
68
|
|
|
|
|
|
|
# |
69
|
|
|
|
|
|
|
# In reality, a few distribution names may not match this pattern -- most |
70
|
|
|
|
|
|
|
# famously, C<CGI.pm> is the name of the distribution that contains CGI. These |
71
|
|
|
|
|
|
|
# exceptions are few and far between, and deciding what a C<LaxDistName> type |
72
|
|
|
|
|
|
|
# would look like has not seemed worth it, yet. |
73
|
|
|
|
|
|
|
# |
74
|
|
|
|
|
|
|
# =cut |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
subtype DistName, |
77
|
|
|
|
|
|
|
as Str, |
78
|
|
|
|
|
|
|
where { |
79
|
|
|
|
|
|
|
return if /:/; |
80
|
|
|
|
|
|
|
(my $str = $_) =~ s/-/::/g; |
81
|
|
|
|
|
|
|
$str !~ /\P{ASCII}/ && _CLASS($str) |
82
|
|
|
|
|
|
|
}, |
83
|
|
|
|
|
|
|
message { |
84
|
|
|
|
|
|
|
/::/ |
85
|
|
|
|
|
|
|
? "$_ looks like a module name, not a dist name" |
86
|
|
|
|
|
|
|
: "$_ is not a valid dist name" |
87
|
|
|
|
|
|
|
}; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# LaxDistName -- how does this work, other than "like some characters, okay?" |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# =head2 Identifier |
92
|
|
|
|
|
|
|
# |
93
|
|
|
|
|
|
|
# An L<Identifier|perldata/Variable names> is something that could be used as a |
94
|
|
|
|
|
|
|
# symbol name or other identifier (filehandle, directory handle, subroutine name, |
95
|
|
|
|
|
|
|
# format name, or label). It's what you put after the sigil (dollar sign, at |
96
|
|
|
|
|
|
|
# sign, percent sign) in a variable name. Generally, it's a bunch of |
97
|
|
|
|
|
|
|
# alphanumeric characters not starting with a digit. |
98
|
|
|
|
|
|
|
# |
99
|
|
|
|
|
|
|
# Although Perl identifiers may contain non-ASCII characters in some |
100
|
|
|
|
|
|
|
# circumstances, this type does not allow it. A C<UnicodeIdentifier> type may be |
101
|
|
|
|
|
|
|
# added in the future. |
102
|
|
|
|
|
|
|
# |
103
|
|
|
|
|
|
|
# =cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
subtype Identifier, |
106
|
|
|
|
|
|
|
as Str, |
107
|
|
|
|
|
|
|
where { / \A [_a-z] [_a-z0-9]* \z /xi; }; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# =head2 SafeIdentifier |
110
|
|
|
|
|
|
|
# |
111
|
|
|
|
|
|
|
# SafeIdentifiers are just like Identifiers, but omit the single-letter variables |
112
|
|
|
|
|
|
|
# underscore, a, and b, as these have special significance. |
113
|
|
|
|
|
|
|
# |
114
|
|
|
|
|
|
|
# =cut |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
subtype SafeIdentifier, |
117
|
|
|
|
|
|
|
as Identifier, |
118
|
|
|
|
|
|
|
where { ! / \A [_ab] \z /x; }; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# =head2 LaxVersionStr |
121
|
|
|
|
|
|
|
# |
122
|
|
|
|
|
|
|
# =head2 StrictVersionStr |
123
|
|
|
|
|
|
|
# |
124
|
|
|
|
|
|
|
# Lax and strict version strings use the L<is_lax|version/is_lax> and |
125
|
|
|
|
|
|
|
# L<is_strict|version/is_strict> methods from C<version> to check if the given |
126
|
|
|
|
|
|
|
# string would be a valid lax or strict version. L<version::Internals> covers |
127
|
|
|
|
|
|
|
# the details but basically: lax versions are everything you may do, and strict |
128
|
|
|
|
|
|
|
# omit many of the usages best avoided. |
129
|
|
|
|
|
|
|
# |
130
|
|
|
|
|
|
|
# =cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
subtype LaxVersionStr, |
133
|
|
|
|
|
|
|
as Str, |
134
|
|
|
|
|
|
|
where { version::is_lax($_) }, |
135
|
|
|
|
|
|
|
message { "$_ is not a valid lax version string" }; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
subtype StrictVersionStr, |
138
|
|
|
|
|
|
|
as LaxVersionStr, |
139
|
|
|
|
|
|
|
where { version::is_strict($_) }, |
140
|
|
|
|
|
|
|
message { "$_ is not a valid strict version string" }; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# =head2 VersionObject |
143
|
|
|
|
|
|
|
# |
144
|
|
|
|
|
|
|
# Just for good measure, this type is included to check if a value is a version |
145
|
|
|
|
|
|
|
# object. Coercions from LaxVersionStr (and thus StrictVersionStr) are provided. |
146
|
|
|
|
|
|
|
# |
147
|
|
|
|
|
|
|
# =cut |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
subtype VersionObject, |
150
|
|
|
|
|
|
|
as Object, |
151
|
|
|
|
|
|
|
where { $_->isa('version') }; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
coerce VersionObject, |
154
|
|
|
|
|
|
|
from LaxVersionStr, |
155
|
|
|
|
|
|
|
via { version->parse($_) }; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
1; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
__END__ |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=pod |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=encoding UTF-8 |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 NAME |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
MooseX::Types::Perl - Moose types that check against Perl syntax |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 VERSION |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
version 0.101343 |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 SYNOPSIS |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
use MooseX::Types::Perl qw( |
176
|
|
|
|
|
|
|
DistName |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
ModuleName |
179
|
|
|
|
|
|
|
PackageName |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Identifier |
182
|
|
|
|
|
|
|
SafeIdentifier |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
LaxVersionStr |
185
|
|
|
|
|
|
|
StrictVersionStr |
186
|
|
|
|
|
|
|
VersionObject |
187
|
|
|
|
|
|
|
); |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 DESCRIPTION |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
This library provides L<Moose types|MooseX::Types> for checking things (mostly |
192
|
|
|
|
|
|
|
strings) against syntax that is, or is a reasonable subset of, Perl syntax. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 TYPES |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head2 ModuleName |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head2 PackageName |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
These types are identical, and expect a string that could be a package or |
201
|
|
|
|
|
|
|
module name. That's basically a bunch of identifiers stuck together with |
202
|
|
|
|
|
|
|
double-colons. One key quirk is that parts of the package name after the |
203
|
|
|
|
|
|
|
first may begin with digits. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
The use of an apostrophe as a package separator is not permitted. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head2 DistName |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
The DistName type checks for a string like C<MooseX-Types-Perl>, the sort of |
210
|
|
|
|
|
|
|
thing used to name CPAN distributions. In general, it's like the more familiar |
211
|
|
|
|
|
|
|
L<ModuleName>, but with hyphens instead of double-colons. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
In reality, a few distribution names may not match this pattern -- most |
214
|
|
|
|
|
|
|
famously, C<CGI.pm> is the name of the distribution that contains CGI. These |
215
|
|
|
|
|
|
|
exceptions are few and far between, and deciding what a C<LaxDistName> type |
216
|
|
|
|
|
|
|
would look like has not seemed worth it, yet. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head2 Identifier |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
An L<Identifier|perldata/Variable names> is something that could be used as a |
221
|
|
|
|
|
|
|
symbol name or other identifier (filehandle, directory handle, subroutine name, |
222
|
|
|
|
|
|
|
format name, or label). It's what you put after the sigil (dollar sign, at |
223
|
|
|
|
|
|
|
sign, percent sign) in a variable name. Generally, it's a bunch of |
224
|
|
|
|
|
|
|
alphanumeric characters not starting with a digit. |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Although Perl identifiers may contain non-ASCII characters in some |
227
|
|
|
|
|
|
|
circumstances, this type does not allow it. A C<UnicodeIdentifier> type may be |
228
|
|
|
|
|
|
|
added in the future. |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head2 SafeIdentifier |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
SafeIdentifiers are just like Identifiers, but omit the single-letter variables |
233
|
|
|
|
|
|
|
underscore, a, and b, as these have special significance. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head2 LaxVersionStr |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head2 StrictVersionStr |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
Lax and strict version strings use the L<is_lax|version/is_lax> and |
240
|
|
|
|
|
|
|
L<is_strict|version/is_strict> methods from C<version> to check if the given |
241
|
|
|
|
|
|
|
string would be a valid lax or strict version. L<version::Internals> covers |
242
|
|
|
|
|
|
|
the details but basically: lax versions are everything you may do, and strict |
243
|
|
|
|
|
|
|
omit many of the usages best avoided. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head2 VersionObject |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
Just for good measure, this type is included to check if a value is a version |
248
|
|
|
|
|
|
|
object. Coercions from LaxVersionStr (and thus StrictVersionStr) are provided. |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head1 AUTHOR |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
Ricardo SIGNES <rjbs@cpan.org> |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Ricardo SIGNES. |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
259
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=cut |