line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Validator::Checker::MostWanted; |
2
|
2
|
|
|
2
|
|
1331
|
use 5.006; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
73
|
|
3
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
57
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
77
|
|
5
|
2
|
|
|
2
|
|
11
|
use Scalar::Util qw(blessed); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1405
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Validator::Checker::MostWanted - "most wanted" checkers for Validator::Var. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 0.03 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
require Exporter; |
22
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
23
|
|
|
|
|
|
|
our @EXPORT_OK = qw(Ref Type Can Base Min Max Between Regexp Length); |
24
|
|
|
|
|
|
|
|
25
|
3
|
|
|
3
|
1
|
19
|
sub Ref { [\&_ref, 'Ref', 'is reference' ] } |
26
|
0
|
|
|
0
|
1
|
0
|
sub Type { [\&_ref, 'Type', 'is reference'] } |
27
|
5
|
|
|
5
|
1
|
25
|
sub Can { [\&_can, 'Can', 'has method'] } |
28
|
0
|
|
|
0
|
1
|
0
|
sub Base { [\&_base, 'Base', 'inherit class'] } |
29
|
1
|
|
|
1
|
1
|
5
|
sub Min { [\&_min, 'Min', 'is grater than'] } |
30
|
0
|
|
|
0
|
1
|
0
|
sub Max { [\&_max, 'Max', 'is less than'] } |
31
|
1
|
|
|
1
|
1
|
7
|
sub Between { [\&_between, 'Between', 'is between'] } |
32
|
1
|
|
|
1
|
1
|
4
|
sub Regexp { [\&_regexp, 'Regexp', 'match regexp'] } |
33
|
2
|
|
|
2
|
1
|
14
|
sub Length { [\&_length, 'Length', 'has length equal to' ] } |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 SYNOPSIS |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
see Validator::Var |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 EXPORT |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
This package exports "most wanted" checkers for Validator::Var. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 Ref @refs |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
variable is a reference to one of listed in @refs |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 Type @types |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
equivalent to C[ checker ] |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 Can @methods |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
variable is blessed and has methods listed in @methods |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 Base @base_classes |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
variable is an object and inherited from all classes listed in @base_classes |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 Min $min_val |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
variable is a scalar and it's value is grater or equal to $min_val |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 Max $max_val |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
variable is a scalar and it's value is less or equal to $max_val |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 Between $min_val $max_val |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
variable is a scalar and it's value is bitween $min_val and $max_val (inclusive) |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 Regexp $re |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
variable is a scalar and matches regexp $re |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 Length $len_val |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
variable is a scalar and it's length is equal to $len_val |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# |
83
|
|
|
|
|
|
|
# returns true if $var is the reference to one from @refnames |
84
|
|
|
|
|
|
|
# |
85
|
|
|
|
|
|
|
sub _ref |
86
|
|
|
|
|
|
|
{ |
87
|
7
|
|
|
7
|
|
11
|
my ($var, @refnames) = @_; |
88
|
7
|
100
|
|
|
|
22
|
return 0 unless ref $var; |
89
|
6
|
50
|
|
|
|
10
|
return 0 unless scalar @refnames; |
90
|
6
|
|
|
|
|
11
|
my $refvar = ref $var; |
91
|
|
|
|
|
|
|
|
92
|
6
|
|
|
|
|
11
|
foreach( @refnames ) { |
93
|
14
|
100
|
|
|
|
39
|
return 1 if $refvar eq $_; |
94
|
|
|
|
|
|
|
} |
95
|
3
|
|
|
|
|
12
|
return 0; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# |
99
|
|
|
|
|
|
|
# returns true if $var is reference and it has methods listed in @methods |
100
|
|
|
|
|
|
|
# |
101
|
|
|
|
|
|
|
sub _can { |
102
|
5
|
|
|
5
|
|
11
|
my ($var, @methods) = @_; |
103
|
5
|
100
|
|
|
|
25
|
return 0 unless blessed $var; |
104
|
4
|
50
|
|
|
|
10
|
return 0 unless scalar @methods; |
105
|
|
|
|
|
|
|
|
106
|
4
|
|
|
|
|
9
|
foreach( @methods ) { |
107
|
5
|
50
|
|
|
|
33
|
return 0 unless $var->can($_); |
108
|
|
|
|
|
|
|
} |
109
|
4
|
|
|
|
|
16
|
return 1; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub _base { |
113
|
0
|
|
|
0
|
|
0
|
my ($var, @base_classes) = @_; |
114
|
0
|
0
|
|
|
|
0
|
return 0 unless ref $var; |
115
|
0
|
0
|
|
|
|
0
|
return 0 unless scalar @base_classes; |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
0
|
foreach( @base_classes ) { |
118
|
0
|
0
|
|
|
|
0
|
return 0 unless $var->isa($_); |
119
|
|
|
|
|
|
|
} |
120
|
0
|
|
|
|
|
0
|
return 1; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub _min($$) { |
124
|
1
|
50
|
|
1
|
|
4
|
return 0 if ref $_[0]; |
125
|
1
|
|
|
|
|
12
|
return $_[0] >= $_[1]; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub _max($$) { |
129
|
0
|
0
|
|
0
|
|
0
|
return 0 if ref $_[0]; |
130
|
0
|
|
|
|
|
0
|
return $_[0] <= $_[1]; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub _between($$$) |
134
|
|
|
|
|
|
|
{ |
135
|
5
|
50
|
|
5
|
|
14
|
return 0 if ref $_[0]; |
136
|
5
|
|
100
|
|
|
22
|
my $rc = $_[0] >= $_[1] && $_[0] <= $_[2]; |
137
|
5
|
|
|
|
|
22
|
return $rc; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub _regexp($$) |
141
|
|
|
|
|
|
|
{ |
142
|
2
|
50
|
|
2
|
|
5
|
return 0 if ref $_[0]; |
143
|
2
|
100
|
|
|
|
33
|
return $_[0] =~ $_[1] ? 1 : 0; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub _length($$) { |
147
|
1
|
50
|
|
1
|
|
5
|
return 0 if ref $_[0]; |
148
|
1
|
|
|
|
|
5
|
return length $_[0] == $_[1]; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 AUTHOR |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Fedor Semenov, C<< >> |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 BUGS |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
158
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
159
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 SUPPORT |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
perldoc Validator::Checker::MostWanted |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
You can also look for information at: |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=over 4 |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
L |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
L |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item * CPAN Ratings |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
L |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item * Search CPAN |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
L |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=back |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Copyright 2011 Fedor Semenov. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
199
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
200
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=cut |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
1; # End of Validator::Checker::MostWanted |