line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FormValidator::Lite::Constraint::HTML; |
2
|
1
|
|
|
1
|
|
908
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
7
|
use Carp qw(croak); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
71
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use Scalar::Util::Numeric (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
7
|
1
|
|
|
1
|
|
6
|
use FormValidator::Lite; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
8
|
1
|
|
|
1
|
|
23
|
use FormValidator::Lite::Constraint; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
FormValidator::Lite->load_constraints(qw(URL Email)); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub rule_of ($) { |
15
|
10
|
|
|
10
|
0
|
47
|
$FormValidator::Lite::Rules->{$_[0]}; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
rule HTML_URL => rule_of('HTTP_URL'); |
19
|
|
|
|
|
|
|
rule HTML_EMAIL => rule_of('EMAIL'); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
rule HTML_NUMBER => sub { |
22
|
|
|
|
|
|
|
Scalar::Util::Numeric::isnum($_) ? 1 : 0; |
23
|
|
|
|
|
|
|
}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
rule HTML_RANGE => rule_of('HTML_NUMBER'); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
rule HTML_MAXLENGTH => sub { |
28
|
|
|
|
|
|
|
rule_of('LENGTH')->(0, shift); |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
rule HTML_MAX => sub { |
32
|
|
|
|
|
|
|
my ($max) = @_; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
return if !Scalar::Util::Numeric::isnum($_); |
35
|
|
|
|
|
|
|
croak 'Validation HTML_MAX requires numeric value' |
36
|
|
|
|
|
|
|
if !defined $max || !Scalar::Util::Numeric::isnum($max); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$_ <= $max ? 1 : 0; |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
rule HTML_MIN => sub { |
42
|
|
|
|
|
|
|
my ($min) = @_; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
return if !Scalar::Util::Numeric::isnum($_); |
45
|
|
|
|
|
|
|
croak 'Validation HTML_MIN requires numeric value' |
46
|
|
|
|
|
|
|
if !defined $min || !Scalar::Util::Numeric::isnum($min); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$_ >= $min ? 1 : 0; |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
rule HTML_PATTERN => sub { |
52
|
|
|
|
|
|
|
rule_of('REGEX')->('^(?:' . shift() . ')$'); |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
!!1; |