line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Validator::LIVR::Rules::Special; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
13
|
use strict; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
81
|
|
4
|
4
|
|
|
4
|
|
11
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
65
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
1770
|
use Email::Valid; |
|
4
|
|
|
|
|
321902
|
|
|
4
|
|
|
|
|
131
|
|
7
|
4
|
|
|
4
|
|
1716
|
use Regexp::Common qw/URI/; |
|
4
|
|
|
|
|
11820
|
|
|
4
|
|
|
|
|
12
|
|
8
|
4
|
|
|
4
|
|
73126
|
use Time::Piece; |
|
4
|
|
|
|
|
26611
|
|
|
4
|
|
|
|
|
15
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '2.0'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub email { |
13
|
|
|
|
|
|
|
return sub { |
14
|
22
|
|
|
22
|
|
20
|
my $value = shift; |
15
|
22
|
100
|
66
|
|
|
74
|
return if !defined($value) || $value eq ''; |
16
|
20
|
100
|
|
|
|
32
|
return 'FORMAT_ERROR' if ref($value); |
17
|
|
|
|
|
|
|
|
18
|
16
|
100
|
|
|
|
52
|
return 'WRONG_EMAIL' unless Email::Valid->address($value); |
19
|
6
|
|
|
|
|
2369
|
return; |
20
|
23
|
|
|
23
|
0
|
127
|
}; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub equal_to_field { |
25
|
12
|
|
|
12
|
0
|
9
|
my $field = shift; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
return sub { |
28
|
12
|
|
|
12
|
|
10
|
my ( $value, $params ) = @_; |
29
|
12
|
100
|
66
|
|
|
40
|
return if !defined($value) || $value eq ''; |
30
|
10
|
100
|
|
|
|
19
|
return 'FORMAT_ERROR' if ref($value); |
31
|
|
|
|
|
|
|
|
32
|
6
|
100
|
|
|
|
11
|
return 'FIELDS_NOT_EQUAL' unless $value eq $params->{$field}; |
33
|
3
|
|
|
|
|
5
|
return; |
34
|
12
|
|
|
|
|
66
|
}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub url { |
39
|
|
|
|
|
|
|
return sub { |
40
|
12
|
|
|
12
|
|
11
|
my $value = shift; |
41
|
12
|
100
|
66
|
|
|
43
|
return if !defined($value) || $value eq ''; |
42
|
10
|
100
|
|
|
|
21
|
return 'FORMAT_ERROR' if ref($value); |
43
|
|
|
|
|
|
|
|
44
|
6
|
|
|
|
|
11
|
$value =~ s/#[^#]*$//; |
45
|
|
|
|
|
|
|
|
46
|
6
|
100
|
|
|
|
31
|
return 'WRONG_URL' unless lc($value) =~ /^$RE{URI}{HTTP}{-scheme => 'https?'}$/; |
47
|
3
|
|
|
|
|
499
|
return; |
48
|
12
|
|
|
12
|
0
|
64
|
}; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub iso_date { |
53
|
|
|
|
|
|
|
return sub { |
54
|
14
|
|
|
14
|
|
11
|
my $value = shift; |
55
|
14
|
100
|
66
|
|
|
57
|
return if !defined($value) || $value eq ''; |
56
|
12
|
100
|
|
|
|
22
|
return 'FORMAT_ERROR' if ref($value); |
57
|
|
|
|
|
|
|
|
58
|
8
|
|
|
|
|
19
|
my $iso_date_re = qr#^ |
59
|
|
|
|
|
|
|
(?\d{4})- |
60
|
|
|
|
|
|
|
(?[0-1][0-9])- |
61
|
|
|
|
|
|
|
(?[0-3][0-9]) |
62
|
|
|
|
|
|
|
$#x; |
63
|
|
|
|
|
|
|
|
64
|
8
|
100
|
|
|
|
46
|
if ( $value =~ $iso_date_re ) { |
65
|
7
|
|
|
|
|
6
|
my $date = eval { Time::Piece->strptime($value, "%Y-%m-%d") }; |
|
7
|
|
|
|
|
30
|
|
66
|
7
|
100
|
66
|
|
|
190
|
return "WRONG_DATE" if !$date || $@; |
67
|
|
|
|
|
|
|
|
68
|
4
|
100
|
66
|
4
|
|
2940
|
if ( $date->year == $+{year} && $date->mon == $+{month} && $date->mday == $+{day} ) { |
|
4
|
|
66
|
|
|
1215
|
|
|
4
|
|
|
|
|
283
|
|
|
6
|
|
|
|
|
259
|
|
69
|
5
|
|
|
|
|
108
|
return; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
2
|
|
|
|
|
29
|
return "WRONG_DATE"; |
74
|
14
|
|
|
14
|
0
|
97
|
}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |