line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FormValidator::Simple::Struct::Regex; |
2
|
11
|
|
|
11
|
|
21677
|
use 5.008_001; |
|
11
|
|
|
|
|
35
|
|
3
|
11
|
|
|
11
|
|
56
|
use strict; |
|
11
|
|
|
|
|
21
|
|
|
11
|
|
|
|
|
276
|
|
4
|
11
|
|
|
11
|
|
54
|
use warnings; |
|
11
|
|
|
|
|
19
|
|
|
11
|
|
|
|
|
295
|
|
5
|
11
|
|
|
11
|
|
9582
|
use Email::Valid; |
|
11
|
|
|
|
|
1569201
|
|
|
11
|
|
|
|
|
424
|
|
6
|
11
|
|
|
11
|
|
11635
|
use Time::Piece; |
|
11
|
|
|
|
|
145178
|
|
|
11
|
|
|
|
|
61
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.16'; |
9
|
|
|
|
|
|
|
|
10
|
11
|
|
|
11
|
|
1035
|
use base 'Exporter'; |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
11225
|
|
11
|
|
|
|
|
|
|
our @EXPORT= qw/NOT_BLANK INT ASCII STRING DECIMAL EMAIL DATETIME DATE TIME TINYINT URL LENGTH BETWEEN DIGIT_LENGTH/; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub NOT_BLANK{ |
14
|
80
|
|
|
80
|
0
|
127
|
my $s = shift; |
15
|
80
|
100
|
100
|
|
|
401
|
if (defined $s and length($s) > 0 ){ |
16
|
73
|
|
|
|
|
305
|
return 1; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
7
|
|
|
|
|
30
|
!!$s; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub INT{ |
23
|
112
|
|
|
112
|
1
|
178
|
my $s = shift; |
24
|
112
|
100
|
|
|
|
263
|
return 1 unless $s; |
25
|
109
|
|
|
|
|
859
|
$s =~ m/^\d+$|^-\d+$/; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub ASCII{ |
29
|
57
|
|
|
57
|
1
|
99
|
my $s = shift; |
30
|
57
|
100
|
|
|
|
171
|
return 1 unless $s; |
31
|
48
|
|
|
|
|
435
|
$s =~ /^[\x21-\x7E]+$/; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub STRING{ |
35
|
0
|
|
|
0
|
1
|
0
|
my $s = shift; |
36
|
0
|
0
|
|
|
|
0
|
return 1 unless $s; |
37
|
0
|
|
|
|
|
0
|
1; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub DECIMAL{ |
41
|
14
|
|
|
14
|
1
|
78
|
my $s = shift; |
42
|
14
|
50
|
|
|
|
62
|
return 1 unless $s; |
43
|
14
|
100
|
|
|
|
212
|
$s =~ m/^\d+\.\d+$|^-\d+\.\d+$/ or INT($s); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub EMAIL{ |
47
|
0
|
|
|
0
|
1
|
0
|
my $s = shift; |
48
|
0
|
0
|
|
|
|
0
|
return 1 unless $s; |
49
|
0
|
|
|
|
|
0
|
Email::Valid->address(-address => $s); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub DATETIME{ |
53
|
9
|
|
|
9
|
1
|
26
|
my $s = shift; |
54
|
9
|
50
|
|
|
|
29
|
return 1 unless $s; |
55
|
9
|
100
|
|
|
|
69
|
return 0 unless $s =~ m!^\d{4}(?:-|/)\d{2}(?:-|/)\d{2} \d{2}(?::|-)\d{2}(?::|-)\d{2}$!; |
56
|
6
|
|
|
|
|
28
|
eval{ |
57
|
6
|
|
|
|
|
38
|
Time::Piece->strptime($s , "%Y-%m-%d %H:%M:%S"); |
58
|
|
|
|
|
|
|
}; |
59
|
6
|
100
|
|
|
|
195
|
if($@){ |
60
|
5
|
|
|
|
|
10
|
eval{ |
61
|
5
|
|
|
|
|
29
|
Time::Piece->strptime($s , "%Y/%m/%d %H:%M:%S"); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
6
|
100
|
|
|
|
137
|
if($@){ |
65
|
4
|
|
|
|
|
8
|
eval{ |
66
|
4
|
|
|
|
|
15
|
Time::Piece->strptime($s , "%Y-%m-%d %H-%M-%S"); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
6
|
100
|
|
|
|
84
|
if($@){ |
70
|
3
|
|
|
|
|
6
|
eval{ |
71
|
3
|
|
|
|
|
9
|
Time::Piece->strptime($s , "%Y/%m/%d %H-%M-%S"); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
6
|
|
|
|
|
81
|
!$@ |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub DATE{ |
78
|
5
|
|
|
5
|
1
|
13
|
my $s = shift; |
79
|
5
|
50
|
|
|
|
15
|
return 1 unless $s; |
80
|
5
|
|
|
|
|
10
|
eval{ |
81
|
5
|
|
|
|
|
24
|
Time::Piece->strptime($s , "%Y-%m-%d"); |
82
|
|
|
|
|
|
|
}; |
83
|
5
|
100
|
|
|
|
114
|
if($@){ |
84
|
3
|
|
|
|
|
7
|
eval{ |
85
|
3
|
|
|
|
|
11
|
Time::Piece->strptime($s , "%Y/%m/%d"); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
5
|
100
|
|
|
|
66
|
if($@){ |
89
|
1
|
|
|
|
|
4
|
eval{ |
90
|
1
|
|
|
|
|
8
|
Time::Piece->strptime($s , "%Y-%m-%d"); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
5
|
100
|
|
|
|
27
|
if($@){ |
94
|
1
|
|
|
|
|
3
|
eval{ |
95
|
1
|
|
|
|
|
6
|
Time::Piece->strptime($s , "%Y/%m/%d"); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
5
|
|
|
|
|
34
|
!$@ |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub TIME{ |
102
|
5
|
|
|
5
|
1
|
17
|
my $s = shift; |
103
|
5
|
50
|
|
|
|
25
|
return 1 unless $s; |
104
|
5
|
|
|
|
|
71
|
$s =~ m/\d{2}-\d{2}-\d{2}|\d{2}:\d{2}:\d{2}/; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub TINYINT{ |
108
|
11
|
|
|
11
|
0
|
30
|
my $s = shift; |
109
|
11
|
100
|
|
|
|
40
|
return 1 unless $s; |
110
|
9
|
|
66
|
|
|
89
|
return ($s eq "0" or $s eq "1"); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub LENGTH{ |
114
|
9
|
|
|
9
|
1
|
18
|
my ($s , $min , $max) = @_; |
115
|
9
|
|
|
|
|
12
|
my $len = length($s); |
116
|
9
|
100
|
100
|
|
|
51
|
if($len == 0 or $len >= $min and $len <= $max){ |
|
|
|
66
|
|
|
|
|
117
|
5
|
|
|
|
|
34
|
return 1; |
118
|
|
|
|
|
|
|
}else{ |
119
|
4
|
|
|
|
|
16
|
return 0; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub DIGIT_LENGTH{ |
124
|
3
|
|
|
3
|
0
|
5
|
my ($s , $integer , $decimal) = @_; |
125
|
3
|
|
|
|
|
17
|
my ($integer_value , $decimal_value) = $s =~ m/(\d+)\.(\d+)/; |
126
|
3
|
|
50
|
|
|
8
|
$integer_value ||= ""; |
127
|
3
|
|
50
|
|
|
8
|
$decimal_value ||= ""; |
128
|
|
|
|
|
|
|
|
129
|
3
|
100
|
100
|
|
|
14
|
if(length($integer_value) <= $integer && length($decimal_value) <= $decimal){ |
130
|
1
|
|
|
|
|
9
|
return 1; |
131
|
|
|
|
|
|
|
}else{ |
132
|
2
|
|
|
|
|
9
|
return 0; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub BETWEEN{ |
137
|
17
|
|
|
17
|
1
|
30
|
my ($s , $min , $max) = @_; |
138
|
17
|
100
|
100
|
|
|
71
|
if($s >= $min and $s <= $max){ |
139
|
10
|
|
|
|
|
66
|
return 1; |
140
|
|
|
|
|
|
|
}else{ |
141
|
7
|
|
|
|
|
27
|
return 0; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub URL{ |
146
|
7
|
|
|
7
|
1
|
28
|
my ($s) = @_; |
147
|
7
|
50
|
|
|
|
36
|
return 1 unless $s; |
148
|
7
|
|
|
|
|
82
|
$s =~ m/^http:\/\/|^https:\/\//; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
1; |
152
|
|
|
|
|
|
|
__END__ |