line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FormValidator::Simple::Struct::Regex; |
2
|
11
|
|
|
11
|
|
15209
|
use 5.008_001; |
|
11
|
|
|
|
|
31
|
|
|
11
|
|
|
|
|
374
|
|
3
|
11
|
|
|
11
|
|
46
|
use strict; |
|
11
|
|
|
|
|
13
|
|
|
11
|
|
|
|
|
285
|
|
4
|
11
|
|
|
11
|
|
97
|
use warnings; |
|
11
|
|
|
|
|
14
|
|
|
11
|
|
|
|
|
254
|
|
5
|
11
|
|
|
11
|
|
5804
|
use Email::Valid; |
|
11
|
|
|
|
|
1027122
|
|
|
11
|
|
|
|
|
401
|
|
6
|
11
|
|
|
11
|
|
7196
|
use Time::Piece; |
|
11
|
|
|
|
|
110549
|
|
|
11
|
|
|
|
|
53
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.15'; |
9
|
|
|
|
|
|
|
|
10
|
11
|
|
|
11
|
|
874
|
use base 'Exporter'; |
|
11
|
|
|
|
|
18
|
|
|
11
|
|
|
|
|
8117
|
|
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
|
105
|
my $s = shift; |
15
|
80
|
100
|
100
|
|
|
354
|
if (defined $s and length($s) > 0 ){ |
16
|
73
|
|
|
|
|
256
|
return 1; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
7
|
|
|
|
|
22
|
!!$s; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub INT{ |
23
|
112
|
|
|
112
|
1
|
117
|
my $s = shift; |
24
|
112
|
100
|
|
|
|
195
|
return 1 unless $s; |
25
|
109
|
|
|
|
|
678
|
$s =~ m/^\d+$|^-\d+$/; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub ASCII{ |
29
|
57
|
|
|
57
|
1
|
64
|
my $s = shift; |
30
|
57
|
100
|
|
|
|
127
|
return 1 unless $s; |
31
|
48
|
|
|
|
|
369
|
$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
|
42
|
my $s = shift; |
42
|
14
|
50
|
|
|
|
25
|
return 1 unless $s; |
43
|
14
|
100
|
|
|
|
112
|
$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
|
7
|
|
|
7
|
1
|
10
|
my $s = shift; |
54
|
7
|
50
|
|
|
|
14
|
return 1 unless $s; |
55
|
7
|
|
|
|
|
7
|
eval{ |
56
|
7
|
|
|
|
|
27
|
Time::Piece->strptime($s , "%Y-%m-%d %H:%M:%S"); |
57
|
|
|
|
|
|
|
}; |
58
|
7
|
100
|
|
|
|
113
|
if($@){ |
59
|
6
|
|
|
|
|
13
|
eval{ |
60
|
6
|
|
|
|
|
13
|
Time::Piece->strptime($s , "%Y/%m/%d %H:%M:%S"); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
7
|
100
|
|
|
|
53
|
if($@){ |
64
|
5
|
|
|
|
|
5
|
eval{ |
65
|
5
|
|
|
|
|
11
|
Time::Piece->strptime($s , "%Y-%m-%d %H-%M-%S"); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
7
|
100
|
|
|
|
50
|
if($@){ |
69
|
4
|
|
|
|
|
3
|
eval{ |
70
|
4
|
|
|
|
|
7
|
Time::Piece->strptime($s , "%Y/%m/%d %H-%M-%S"); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
7
|
|
|
|
|
52
|
!$@ |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub DATE{ |
77
|
5
|
|
|
5
|
1
|
9
|
my $s = shift; |
78
|
5
|
50
|
|
|
|
11
|
return 1 unless $s; |
79
|
5
|
|
|
|
|
6
|
eval{ |
80
|
5
|
|
|
|
|
15
|
Time::Piece->strptime($s , "%Y-%m-%d"); |
81
|
|
|
|
|
|
|
}; |
82
|
5
|
100
|
|
|
|
80
|
if($@){ |
83
|
3
|
|
|
|
|
4
|
eval{ |
84
|
3
|
|
|
|
|
7
|
Time::Piece->strptime($s , "%Y/%m/%d"); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
5
|
100
|
|
|
|
51
|
if($@){ |
88
|
1
|
|
|
|
|
2
|
eval{ |
89
|
1
|
|
|
|
|
3
|
Time::Piece->strptime($s , "%Y-%m-%d"); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
5
|
100
|
|
|
|
14
|
if($@){ |
93
|
1
|
|
|
|
|
2
|
eval{ |
94
|
1
|
|
|
|
|
2
|
Time::Piece->strptime($s , "%Y/%m/%d"); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
5
|
|
|
|
|
18
|
!$@ |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub TIME{ |
101
|
5
|
|
|
5
|
1
|
11
|
my $s = shift; |
102
|
5
|
50
|
|
|
|
10
|
return 1 unless $s; |
103
|
5
|
|
|
|
|
32
|
$s =~ m/\d{2}-\d{2}-\d{2}|\d{2}:\d{2}:\d{2}/; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub TINYINT{ |
107
|
11
|
|
|
11
|
0
|
16
|
my $s = shift; |
108
|
11
|
100
|
|
|
|
25
|
return 1 unless $s; |
109
|
9
|
|
66
|
|
|
58
|
return ($s eq "0" or $s eq "1"); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub LENGTH{ |
113
|
9
|
|
|
9
|
1
|
12
|
my ($s , $min , $max) = @_; |
114
|
9
|
|
|
|
|
12
|
my $len = length($s); |
115
|
9
|
100
|
100
|
|
|
43
|
if($len == 0 or $len >= $min and $len <= $max){ |
|
|
|
66
|
|
|
|
|
116
|
5
|
|
|
|
|
25
|
return 1; |
117
|
|
|
|
|
|
|
}else{ |
118
|
4
|
|
|
|
|
13
|
return 0; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub DIGIT_LENGTH{ |
123
|
3
|
|
|
3
|
0
|
5
|
my ($s , $integer , $decimal) = @_; |
124
|
3
|
|
|
|
|
12
|
my ($integer_value , $decimal_value) = $s =~ m/(\d+)\.(\d+)/; |
125
|
|
|
|
|
|
|
|
126
|
3
|
100
|
100
|
|
|
13
|
if(length($integer_value) <= $integer && length($decimal_value) <= $decimal){ |
127
|
1
|
|
|
|
|
8
|
return 1; |
128
|
|
|
|
|
|
|
}else{ |
129
|
2
|
|
|
|
|
6
|
return 0; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub BETWEEN{ |
134
|
17
|
|
|
17
|
1
|
19
|
my ($s , $min , $max) = @_; |
135
|
17
|
100
|
100
|
|
|
49
|
if($s >= $min and $s <= $max){ |
136
|
10
|
|
|
|
|
57
|
return 1; |
137
|
|
|
|
|
|
|
}else{ |
138
|
7
|
|
|
|
|
22
|
return 0; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub URL{ |
143
|
7
|
|
|
7
|
1
|
14
|
my ($s) = @_; |
144
|
7
|
50
|
|
|
|
13
|
return 1 unless $s; |
145
|
7
|
|
|
|
|
43
|
$s =~ m/^http:\/\/|^https:\/\//; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
1; |
149
|
|
|
|
|
|
|
__END__ |