line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FormValidator::Simple::Validator; |
2
|
25
|
|
|
25
|
|
139
|
use strict; |
|
25
|
|
|
|
|
44
|
|
|
25
|
|
|
|
|
883
|
|
3
|
25
|
|
|
25
|
|
125
|
use base qw/Class::Data::Inheritable/; |
|
25
|
|
|
|
|
49
|
|
|
25
|
|
|
|
|
4804
|
|
4
|
|
|
|
|
|
|
|
5
|
25
|
|
|
25
|
|
1837
|
use FormValidator::Simple::Constants; |
|
25
|
|
|
|
|
42
|
|
|
25
|
|
|
|
|
1840
|
|
6
|
25
|
|
|
25
|
|
133
|
use FormValidator::Simple::Exception; |
|
25
|
|
|
|
|
58
|
|
|
25
|
|
|
|
|
237
|
|
7
|
25
|
|
|
25
|
|
28479
|
use Email::Valid; |
|
25
|
|
|
|
|
6937300
|
|
|
25
|
|
|
|
|
543
|
|
8
|
25
|
|
|
25
|
|
29144
|
use Email::Valid::Loose; |
|
25
|
|
|
|
|
32803
|
|
|
25
|
|
|
|
|
298
|
|
9
|
25
|
|
|
25
|
|
25255
|
use Date::Calc; |
|
25
|
|
|
|
|
13654618
|
|
|
25
|
|
|
|
|
1398
|
|
10
|
25
|
|
|
25
|
|
3290
|
use UNIVERSAL::require; |
|
25
|
|
|
|
|
4815
|
|
|
25
|
|
|
|
|
374
|
|
11
|
25
|
|
|
25
|
|
3326
|
use List::MoreUtils; |
|
25
|
|
|
|
|
3812
|
|
|
25
|
|
|
|
|
987
|
|
12
|
25
|
|
|
25
|
|
39790
|
use DateTime::Format::Strptime; |
|
25
|
|
|
|
|
5720712
|
|
|
25
|
|
|
|
|
114649
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
__PACKAGE__->mk_classdata( options => { } ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub SP { |
17
|
4
|
|
|
4
|
0
|
27
|
my ($self, $params, $args) = @_; |
18
|
4
|
|
|
|
|
6
|
my $data = $params->[0]; |
19
|
4
|
100
|
|
|
|
23
|
return $data =~ /\s/ ? TRUE : FALSE; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
*SPACE = \&SP; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub INT { |
25
|
22
|
|
|
22
|
0
|
139
|
my ($self, $params, $args) = @_; |
26
|
22
|
|
|
|
|
43
|
my $data = $params->[0]; |
27
|
22
|
100
|
|
|
|
162
|
return $data =~ /^\-?[\d]+$/ ? TRUE : FALSE; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub UINT { |
31
|
0
|
|
|
0
|
0
|
0
|
my ($self, $params, $args) = @_; |
32
|
0
|
|
|
|
|
0
|
my $data = $params->[0]; |
33
|
0
|
0
|
|
|
|
0
|
return $data =~ /^\d+$/ ? TRUE : FALSE; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub ASCII { |
37
|
11
|
|
|
11
|
0
|
95
|
my ($self, $params, $args) = @_; |
38
|
11
|
|
|
|
|
29
|
my $data = $params->[0]; |
39
|
11
|
100
|
|
|
|
102
|
return $data =~ /^[\x21-\x7E]+$/ ? TRUE : FALSE; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub DUPLICATION { |
43
|
4
|
|
|
4
|
0
|
25
|
my ($self, $params, $args) = @_; |
44
|
4
|
|
|
|
|
6
|
my $data1 = $params->[0]; |
45
|
4
|
|
|
|
|
6
|
my $data2 = $params->[1]; |
46
|
4
|
50
|
33
|
|
|
35
|
unless (defined $data1 && defined $data2) { |
47
|
0
|
|
|
|
|
0
|
FormValidator::Simple::Exception->throw( |
48
|
|
|
|
|
|
|
qq/validation "DUPLICATION" needs two keys of data./ |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
} |
51
|
4
|
100
|
|
|
|
17
|
return $data1 eq $data2 ? TRUE : FALSE; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub LENGTH { |
55
|
17
|
|
|
17
|
0
|
105
|
my ($self, $params, $args) = @_; |
56
|
17
|
50
|
|
|
|
48
|
unless ( scalar(@$args) > 0 ) { |
57
|
0
|
|
|
|
|
0
|
FormValidator::Simple::Exception->throw( |
58
|
|
|
|
|
|
|
qq/validation "LENGTH" needs one or two arguments./ |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
} |
61
|
17
|
|
|
|
|
34
|
my $data = $params->[0]; |
62
|
17
|
|
|
|
|
28
|
my $length = length $data; |
63
|
17
|
|
|
|
|
28
|
my $min = $args->[0]; |
64
|
17
|
|
66
|
|
|
68
|
my $max = $args->[1] || $min; |
65
|
17
|
|
|
|
|
41
|
$min += 0; |
66
|
17
|
|
|
|
|
24
|
$max += 0; |
67
|
17
|
100
|
100
|
|
|
130
|
return $min <= $length && $length <= $max ? TRUE : FALSE; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub REGEX { |
71
|
3
|
|
|
3
|
0
|
17
|
my ($self, $params, $args) = @_; |
72
|
3
|
|
|
|
|
4
|
my $data = $params->[0]; |
73
|
3
|
|
|
|
|
5
|
my $regex = $args->[0]; |
74
|
3
|
100
|
|
|
|
24
|
return $data =~ /$regex/ ? TRUE : FALSE; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub EMAIL { |
78
|
0
|
|
|
0
|
0
|
0
|
my ($self, $params, $args) = @_; |
79
|
0
|
|
|
|
|
0
|
my $data = $params->[0]; |
80
|
0
|
0
|
|
|
|
0
|
return FALSE unless $data; |
81
|
0
|
0
|
|
|
|
0
|
return Email::Valid->address(-address => $data) ? TRUE : FALSE; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub EMAIL_MX { |
85
|
0
|
|
|
0
|
0
|
0
|
my ($self, $params, $args) = @_; |
86
|
0
|
|
|
|
|
0
|
my $data = $params->[0]; |
87
|
0
|
0
|
|
|
|
0
|
return FALSE unless $data; |
88
|
0
|
0
|
|
|
|
0
|
return Email::Valid->address(-address => $data, -mxcheck => 1) ? TRUE : FALSE; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub EMAIL_LOOSE { |
92
|
3
|
|
|
3
|
0
|
24
|
my ($self, $params, $args) = @_; |
93
|
3
|
|
|
|
|
6
|
my $data = $params->[0]; |
94
|
3
|
50
|
|
|
|
9
|
return FALSE unless $data; |
95
|
3
|
50
|
|
|
|
42
|
return Email::Valid::Loose->address($data) ? TRUE : FALSE; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub EMAIL_LOOSE_MX { |
99
|
0
|
|
|
0
|
0
|
0
|
my ($self, $params, $args) = @_; |
100
|
0
|
|
|
|
|
0
|
my $data = $params->[0]; |
101
|
0
|
0
|
|
|
|
0
|
return FALSE unless $data; |
102
|
0
|
0
|
|
|
|
0
|
return Email::Valid::Loose->address(-address => $data, -mxcheck => 1) ? TRUE : FALSE; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub DATE { |
106
|
4
|
|
|
4
|
0
|
29
|
my ($self, $params, $args) = @_; |
107
|
4
|
|
|
|
|
8
|
my ($year, $month, $day ) = @$params; |
108
|
4
|
100
|
|
|
|
20
|
my $result = Date::Calc::check_date($year, $month, $day) ? TRUE : FALSE; |
109
|
4
|
|
|
|
|
6
|
my $data; |
110
|
4
|
100
|
|
|
|
12
|
if ($result) { |
111
|
2
|
|
50
|
|
|
10
|
my $class = $self->options->{datetime_class} || ''; |
112
|
2
|
50
|
|
|
|
32
|
if ($class eq 'DateTime') { |
|
|
50
|
|
|
|
|
|
113
|
0
|
|
|
|
|
0
|
$class->require; |
114
|
0
|
0
|
|
|
|
0
|
if ($@) { |
115
|
0
|
|
|
|
|
0
|
FormValidator::Simple::Exception->throw( |
116
|
|
|
|
|
|
|
qq/Validation DATE: failed to require $class. "$@"./ |
117
|
|
|
|
|
|
|
); |
118
|
|
|
|
|
|
|
} |
119
|
0
|
|
|
|
|
0
|
my %date = ( |
120
|
|
|
|
|
|
|
year => $year, |
121
|
|
|
|
|
|
|
month => $month, |
122
|
|
|
|
|
|
|
day => $day, |
123
|
|
|
|
|
|
|
); |
124
|
0
|
0
|
|
|
|
0
|
if ($self->options->{time_zone}) { |
125
|
0
|
|
|
|
|
0
|
$date{time_zone} = $self->options->{time_zone}; |
126
|
|
|
|
|
|
|
} |
127
|
0
|
|
|
|
|
0
|
$data = $class->new(%date); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
elsif ($class eq 'Time::Piece') { |
130
|
0
|
|
|
|
|
0
|
$data = sprintf "%04d-%02d-%02d 00:00:00", $year, $month, $day; |
131
|
0
|
|
|
|
|
0
|
$class->require; |
132
|
0
|
0
|
|
|
|
0
|
if ($@) { |
133
|
0
|
|
|
|
|
0
|
FormValidator::Simple::Exception->throw( |
134
|
|
|
|
|
|
|
qq/Validation DATE: failed to require $class. "$@"./ |
135
|
|
|
|
|
|
|
); |
136
|
|
|
|
|
|
|
} |
137
|
0
|
|
|
|
|
0
|
$data = $class->strptime($data, "%Y-%m-%d %H:%M:%S"); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
else { |
140
|
2
|
|
|
|
|
11
|
$data = sprintf "%04d-%02d-%02d 00:00:00", $year, $month, $day; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
} |
143
|
4
|
|
|
|
|
16
|
return ($result, $data); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub TIME { |
147
|
4
|
|
|
4
|
0
|
30
|
my ($self, $params, $args) = @_; |
148
|
4
|
|
|
|
|
89
|
my ($hour, $min, $sec ) = @$params; |
149
|
4
|
|
50
|
|
|
16
|
$hour ||= 0; |
150
|
4
|
|
50
|
|
|
9
|
$min ||= 0; |
151
|
4
|
|
50
|
|
|
11
|
$sec ||= 0; |
152
|
4
|
100
|
|
|
|
21
|
my $result = Date::Calc::check_time($hour, $min, $sec) ? TRUE : FALSE; |
153
|
4
|
100
|
|
|
|
22
|
my $time = $result ? sprintf("%02d:%02d:%02d", $hour, $min, $sec) : undef; |
154
|
4
|
|
|
|
|
18
|
return ($result, $time); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub DATETIME { |
158
|
4
|
|
|
4
|
0
|
31
|
my ($self, $params, $args) = @_; |
159
|
4
|
|
|
|
|
10
|
my ($year, $month, $day, $hour, $min, $sec) = @$params; |
160
|
4
|
|
50
|
|
|
10
|
$hour ||= 0; |
161
|
4
|
|
50
|
|
|
11
|
$min ||= 0; |
162
|
4
|
|
50
|
|
|
9
|
$sec ||= 0; |
163
|
4
|
100
|
66
|
|
|
20
|
my $result = Date::Calc::check_date($year, $month, $day) |
164
|
|
|
|
|
|
|
&& Date::Calc::check_time($hour, $min, $sec) ? TRUE : FALSE; |
165
|
4
|
|
|
|
|
9
|
my $data; |
166
|
4
|
100
|
|
|
|
10
|
if ($result) { |
167
|
2
|
|
50
|
|
|
28
|
my $class = $self->options->{datetime_class} || ''; |
168
|
2
|
50
|
|
|
|
35
|
if ($class eq 'DateTime') { |
|
|
50
|
|
|
|
|
|
169
|
0
|
|
|
|
|
0
|
$class->require; |
170
|
0
|
0
|
|
|
|
0
|
if ($@) { |
171
|
0
|
|
|
|
|
0
|
FormValidator::Simple::Exception->throw( |
172
|
|
|
|
|
|
|
qq/Validation DATETIME: failed to require $class. "$@"./ |
173
|
|
|
|
|
|
|
); |
174
|
|
|
|
|
|
|
} |
175
|
0
|
|
|
|
|
0
|
my %date = ( |
176
|
|
|
|
|
|
|
year => $year, |
177
|
|
|
|
|
|
|
month => $month, |
178
|
|
|
|
|
|
|
day => $day, |
179
|
|
|
|
|
|
|
hour => $hour, |
180
|
|
|
|
|
|
|
minute => $min, |
181
|
|
|
|
|
|
|
second => $sec, |
182
|
|
|
|
|
|
|
); |
183
|
0
|
0
|
|
|
|
0
|
if ($self->options->{time_zone}) { |
184
|
0
|
|
|
|
|
0
|
$date{time_zone} = $self->options->{time_zone}; |
185
|
|
|
|
|
|
|
} |
186
|
0
|
|
|
|
|
0
|
$data = $class->new(%date); |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
elsif ($class eq 'Time::Piece') { |
189
|
0
|
|
|
|
|
0
|
$data = sprintf "%04d-%02d-%02d %02d:%02d:%02d", |
190
|
|
|
|
|
|
|
$year, $month, $day, $hour, $min, $sec; |
191
|
0
|
|
|
|
|
0
|
$class->require; |
192
|
0
|
0
|
|
|
|
0
|
if ($@) { |
193
|
0
|
|
|
|
|
0
|
FormValidator::Simple::Exception->throw( |
194
|
|
|
|
|
|
|
qq/Validation DATETIME: failed to require $class. "$@"./ |
195
|
|
|
|
|
|
|
); |
196
|
|
|
|
|
|
|
} |
197
|
0
|
|
|
|
|
0
|
$data = $class->strptime($data, "%Y-%m-%d %H:%M:%S"); |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
else { |
200
|
2
|
|
|
|
|
20
|
$data = sprintf "%04d-%02d-%02d %02d:%02d:%02d", |
201
|
|
|
|
|
|
|
$year, $month, $day, $hour, $min, $sec; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
} |
204
|
4
|
|
|
|
|
16
|
return ($result, $data); |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub ANY { |
208
|
4
|
|
|
4
|
0
|
24
|
my ($self, $params, $args) = @_; |
209
|
4
|
|
|
|
|
8
|
foreach my $param ( @$params ) { |
210
|
8
|
100
|
66
|
|
|
44
|
return TRUE if ( defined $param && $param ne '' ); |
211
|
|
|
|
|
|
|
} |
212
|
2
|
|
|
|
|
9
|
return FALSE; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub HTTP_URL { |
216
|
2
|
|
|
2
|
0
|
13
|
my ($self, $params, $args) = @_; |
217
|
2
|
|
|
|
|
3
|
my $data = $params->[0]; |
218
|
2
|
100
|
|
|
|
16
|
return $data =~ /^s?https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#]+$/ ? TRUE : FALSE; |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub SELECTED_AT_LEAST { |
222
|
0
|
|
|
0
|
0
|
0
|
my ($self, $params, $args) = @_; |
223
|
0
|
|
|
|
|
0
|
my $data = $params->[0]; |
224
|
0
|
0
|
|
|
|
0
|
my $selected = ref $data ? $data : [$data]; |
225
|
0
|
|
|
|
|
0
|
my $num = $args->[0] + 0; |
226
|
0
|
0
|
|
|
|
0
|
return scalar(@$selected) >= $num ? TRUE : FALSE; |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
sub GREATER_THAN { |
230
|
3
|
|
|
3
|
0
|
19
|
my ($self, $params, $args) = @_; |
231
|
3
|
|
|
|
|
6
|
my $data = $params->[0]; |
232
|
3
|
|
|
|
|
4
|
my $target = $args->[0]; |
233
|
3
|
|
|
|
|
13
|
my $regex = qr/^[-+]?[0-9]+(:?\.[0-9]+)?$/; |
234
|
3
|
50
|
33
|
|
|
31
|
unless ( defined $target && $target =~ /$regex/ ) { |
235
|
0
|
|
|
|
|
0
|
FormValidator::Simple::Exception->throw( |
236
|
|
|
|
|
|
|
qq/Validation GREATER_THAN needs a numeric argument./ |
237
|
|
|
|
|
|
|
); |
238
|
|
|
|
|
|
|
} |
239
|
3
|
50
|
|
|
|
18
|
return FALSE unless $data =~ /$regex/; |
240
|
3
|
100
|
|
|
|
15
|
return ( $data > $target ) ? TRUE : FALSE; |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub LESS_THAN { |
244
|
3
|
|
|
3
|
0
|
19
|
my ($self, $params, $args) = @_; |
245
|
3
|
|
|
|
|
7
|
my $data = $params->[0]; |
246
|
3
|
|
|
|
|
6
|
my $target = $args->[0]; |
247
|
3
|
|
|
|
|
12
|
my $regex = qr/^[-+]?[0-9]+(:?\.[0-9]+)?$/; |
248
|
3
|
50
|
33
|
|
|
38
|
unless ( defined $target && $target =~ /$regex/ ) { |
249
|
0
|
|
|
|
|
0
|
FormValidator::Simple::Exception->throw( |
250
|
|
|
|
|
|
|
qq/Validation LESS_THAN needs a numeric argument./ |
251
|
|
|
|
|
|
|
); |
252
|
|
|
|
|
|
|
} |
253
|
3
|
50
|
|
|
|
17
|
return FALSE unless $data =~ /$regex/; |
254
|
3
|
100
|
|
|
|
37
|
return ( $data < $target ) ? TRUE : FALSE; |
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
sub EQUAL_TO { |
258
|
3
|
|
|
3
|
0
|
16
|
my ($self, $params, $args) = @_; |
259
|
3
|
|
|
|
|
6
|
my $data = $params->[0]; |
260
|
3
|
|
|
|
|
6
|
my $target = $args->[0]; |
261
|
3
|
|
|
|
|
11
|
my $regex = qr/^[-+]?[0-9]+(:?\.[0-9]+)?$/; |
262
|
3
|
50
|
33
|
|
|
27
|
unless ( defined $target && $target =~ /$regex/ ) { |
263
|
0
|
|
|
|
|
0
|
FormValidator::Simple::Exception->throw( |
264
|
|
|
|
|
|
|
qq/Validation EQUAL_TO needs a numeric argument./ |
265
|
|
|
|
|
|
|
); |
266
|
|
|
|
|
|
|
} |
267
|
3
|
50
|
|
|
|
15
|
return FALSE unless $data =~ /$regex/; |
268
|
3
|
100
|
|
|
|
20
|
return ( $data == $target ) ? TRUE : FALSE; |
269
|
|
|
|
|
|
|
} |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
sub BETWEEN { |
272
|
5
|
|
|
5
|
0
|
29
|
my ($self, $params, $args) = @_; |
273
|
5
|
|
|
|
|
10
|
my $data = $params->[0]; |
274
|
5
|
|
|
|
|
7
|
my $start = $args->[0]; |
275
|
5
|
|
|
|
|
9
|
my $end = $args->[1]; |
276
|
5
|
|
|
|
|
16
|
my $regex = qr/^[-+]?[0-9]+(:?\.[0-9]+)?$/; |
277
|
5
|
50
|
33
|
|
|
96
|
unless ( defined($start) && $start =~ /$regex/ && defined($end) && $end =~ /$regex/ ) { |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
278
|
0
|
|
|
|
|
0
|
FormValidator::Simple::Exception->throw( |
279
|
|
|
|
|
|
|
qq/Validation BETWEEN needs two numeric arguments./ |
280
|
|
|
|
|
|
|
); |
281
|
|
|
|
|
|
|
} |
282
|
5
|
50
|
|
|
|
34
|
return FALSE unless $data =~ /$regex/; |
283
|
5
|
100
|
66
|
|
|
33
|
return ( $data >= $start && $data <= $end ) ? TRUE : FALSE; |
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
sub DECIMAL { |
287
|
4
|
|
|
4
|
0
|
24
|
my ($self, $params, $args) = @_; |
288
|
4
|
|
|
|
|
8
|
my $data = $params->[0]; |
289
|
4
|
50
|
|
|
|
10
|
unless ( scalar(@$args) > 0 ) { |
290
|
0
|
|
|
|
|
0
|
FormValidator::Simple::Exception->throw( |
291
|
|
|
|
|
|
|
qq/Validation DECIMAL needs one or two numeric arguments./ |
292
|
|
|
|
|
|
|
); |
293
|
|
|
|
|
|
|
} |
294
|
4
|
|
|
|
|
7
|
my $digit1 = $args->[0]; |
295
|
4
|
|
50
|
|
|
11
|
my $digit2 = $args->[1] || 0; |
296
|
4
|
50
|
33
|
|
|
35
|
unless ( $digit1 =~ /^\d+$/ && $digit2 =~ /^\d+$/ ) { |
297
|
0
|
|
|
|
|
0
|
FormValidator::Simple::Exception->throw( |
298
|
|
|
|
|
|
|
qq/Validation DECIMAL needs one or two numeric arguments./ |
299
|
|
|
|
|
|
|
); |
300
|
|
|
|
|
|
|
} |
301
|
4
|
50
|
|
|
|
21
|
return FALSE unless $data =~ /^\d+(\.\d+)?$/; |
302
|
4
|
|
|
|
|
47
|
my $reg = qr/^\d{1,$digit1}(\.\d{0,$digit2})?$/; |
303
|
4
|
100
|
|
|
|
40
|
return $data =~ /$reg/ ? TRUE : FALSE; |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
sub ALL { |
307
|
2
|
|
|
2
|
0
|
12
|
my ($self, $params, $args) = @_; |
308
|
2
|
|
|
|
|
5
|
foreach my $param ( @$params ) { |
309
|
4
|
100
|
66
|
|
|
23
|
unless ( defined $param && $param ne '' ) { |
310
|
1
|
|
|
|
|
6
|
return FALSE; |
311
|
|
|
|
|
|
|
} |
312
|
|
|
|
|
|
|
} |
313
|
1
|
|
|
|
|
4
|
return TRUE; |
314
|
|
|
|
|
|
|
} |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
sub IN_ARRAY { |
317
|
3
|
|
|
3
|
0
|
19
|
my ($class, $params, $args) = @_; |
318
|
3
|
50
|
|
|
|
12
|
my $data = defined $params->[0] ? $params->[0] : ''; |
319
|
3
|
100
|
|
4
|
|
34
|
return (List::MoreUtils::any { $_ eq $data } @$args) ? TRUE : FALSE; |
|
4
|
|
|
|
|
15
|
|
320
|
|
|
|
|
|
|
} |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
sub DATETIME_FORMAT { |
323
|
0
|
|
|
0
|
0
|
|
my ( $self, $params, $args ) = @_; |
324
|
0
|
|
|
|
|
|
my $date = $params->[0]; |
325
|
0
|
|
|
|
|
|
my $format = $args->[0]; |
326
|
0
|
0
|
|
|
|
|
FormValidator::Simple::Exception->throw( |
327
|
|
|
|
|
|
|
qq/Validation DATETIME_FORMAT needs a format argument./) |
328
|
|
|
|
|
|
|
unless $format; |
329
|
|
|
|
|
|
|
|
330
|
0
|
|
|
|
|
|
my $module; |
331
|
0
|
0
|
|
|
|
|
if ( ref $format ) { |
332
|
0
|
|
|
|
|
|
$module = $format; |
333
|
|
|
|
|
|
|
} |
334
|
|
|
|
|
|
|
else { |
335
|
0
|
|
|
|
|
|
$module = "DateTime::Format::$format"; |
336
|
0
|
0
|
|
|
|
|
$module->require |
337
|
|
|
|
|
|
|
or FormValidator::Simple::Exception->throw( |
338
|
|
|
|
|
|
|
qq/Validation DATETIME_FORMAT: failed to require $module. "$@"/ ); |
339
|
|
|
|
|
|
|
} |
340
|
0
|
|
|
|
|
|
my $dt; |
341
|
0
|
|
|
|
|
|
eval { |
342
|
0
|
|
|
|
|
|
$dt = $module->parse_datetime($date); |
343
|
|
|
|
|
|
|
}; |
344
|
0
|
0
|
|
|
|
|
my $result = $dt ? TRUE : FALSE; |
345
|
|
|
|
|
|
|
|
346
|
0
|
0
|
0
|
|
|
|
if ( $dt && $self->options->{time_zone} ) { |
347
|
0
|
|
|
|
|
|
$dt->set_time_zone( $self->options->{time_zone} ); |
348
|
|
|
|
|
|
|
} |
349
|
0
|
|
|
|
|
|
return ($result, $dt); |
350
|
|
|
|
|
|
|
} |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
sub DATETIME_STRPTIME { |
353
|
0
|
|
|
0
|
0
|
|
my ( $self, $params, $args ) = @_; |
354
|
0
|
|
|
|
|
|
my $date = $params->[0]; |
355
|
0
|
|
|
|
|
|
my $format = $args->[0]; |
356
|
0
|
0
|
|
|
|
|
FormValidator::Simple::Exception->throw( |
357
|
|
|
|
|
|
|
qq/Validation DATETIME_STRPTIME needs a format argument./) |
358
|
|
|
|
|
|
|
unless $format; |
359
|
|
|
|
|
|
|
|
360
|
0
|
|
|
|
|
|
my $dt; |
361
|
0
|
|
|
|
|
|
eval{ |
362
|
0
|
|
|
|
|
|
my $strp = DateTime::Format::Strptime->new( |
363
|
|
|
|
|
|
|
pattern => $format, |
364
|
|
|
|
|
|
|
on_error => 'croak' |
365
|
|
|
|
|
|
|
); |
366
|
0
|
|
|
|
|
|
$dt = $strp->parse_datetime($date); |
367
|
|
|
|
|
|
|
}; |
368
|
|
|
|
|
|
|
|
369
|
0
|
0
|
|
|
|
|
my $result = $dt ? TRUE : FALSE; |
370
|
|
|
|
|
|
|
|
371
|
0
|
0
|
0
|
|
|
|
if ( $dt && $self->options->{time_zone} ) { |
372
|
0
|
|
|
|
|
|
$dt->set_time_zone( $self->options->{time_zone} ); |
373
|
|
|
|
|
|
|
} |
374
|
0
|
|
|
|
|
|
return ($result, $dt); |
375
|
|
|
|
|
|
|
} |
376
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
1; |
378
|
|
|
|
|
|
|
__END__ |