| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Validator::LIVR::Rules::String; |
|
2
|
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
14
|
use strict; |
|
|
4
|
|
|
|
|
3
|
|
|
|
4
|
|
|
|
|
81
|
|
|
4
|
4
|
|
|
4
|
|
23
|
use warnings; |
|
|
4
|
|
|
|
|
3
|
|
|
|
4
|
|
|
|
|
1931
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '2.0'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub one_of { |
|
9
|
22
|
|
|
22
|
0
|
17
|
my $allowed_values; |
|
10
|
22
|
100
|
|
|
|
34
|
if (ref $_[0] eq 'ARRAY') { |
|
11
|
12
|
|
|
|
|
13
|
$allowed_values = $_[0]; |
|
12
|
|
|
|
|
|
|
} else { |
|
13
|
10
|
|
|
|
|
17
|
$allowed_values = [@_]; |
|
14
|
10
|
|
|
|
|
10
|
pop @$allowed_values; # pop rule_builders |
|
15
|
|
|
|
|
|
|
} |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
return sub { |
|
19
|
22
|
|
|
22
|
|
24
|
my ($value, undef, $output_ref) = @_; |
|
20
|
22
|
100
|
100
|
|
|
70
|
return if !defined($value) || $value eq ''; |
|
21
|
20
|
100
|
100
|
|
|
55
|
return 'FORMAT_ERROR' if ref($value) && ref($value) !~ 'Boolean'; |
|
22
|
|
|
|
|
|
|
|
|
23
|
16
|
|
|
|
|
17
|
for my $allowed_value (@$allowed_values) { |
|
24
|
29
|
100
|
|
|
|
45
|
if ($value eq $allowed_value) { |
|
25
|
9
|
|
|
|
|
11
|
$$output_ref = $allowed_value; |
|
26
|
9
|
|
|
|
|
15
|
return; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
7
|
|
|
|
|
56
|
return 'NOT_ALLOWED_VALUE'; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
22
|
|
|
|
|
121
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub max_length { |
|
36
|
26
|
|
|
26
|
0
|
20
|
my $max_length = shift; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
return sub { |
|
39
|
19
|
|
|
19
|
|
15
|
my $value = shift; |
|
40
|
19
|
100
|
100
|
|
|
62
|
return if !defined($value) || $value eq ''; |
|
41
|
16
|
100
|
|
|
|
27
|
return 'FORMAT_ERROR' if ref($value); |
|
42
|
|
|
|
|
|
|
|
|
43
|
12
|
100
|
|
|
|
23
|
return 'TOO_LONG' if length($value) > $max_length; |
|
44
|
7
|
|
|
|
|
8
|
return; |
|
45
|
26
|
|
|
|
|
135
|
}; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub min_length { |
|
50
|
21
|
|
|
21
|
0
|
16
|
my $min_length = shift; |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
return sub { |
|
53
|
21
|
|
|
21
|
|
19
|
my $value = shift; |
|
54
|
21
|
100
|
100
|
|
|
68
|
return if !defined($value) || $value eq ''; |
|
55
|
18
|
100
|
|
|
|
30
|
return 'FORMAT_ERROR' if ref($value); |
|
56
|
|
|
|
|
|
|
|
|
57
|
14
|
100
|
|
|
|
31
|
return 'TOO_SHORT' if length($value) < $min_length; |
|
58
|
7
|
|
|
|
|
7
|
return; |
|
59
|
21
|
|
|
|
|
120
|
}; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub length_equal { |
|
64
|
14
|
|
|
14
|
0
|
11
|
my $length = shift; |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
return sub { |
|
67
|
14
|
|
|
14
|
|
9
|
my $value = shift; |
|
68
|
14
|
100
|
100
|
|
|
44
|
return if !defined($value) || $value eq ''; |
|
69
|
11
|
100
|
|
|
|
19
|
return 'FORMAT_ERROR' if ref($value); |
|
70
|
|
|
|
|
|
|
|
|
71
|
7
|
100
|
|
|
|
11
|
return 'TOO_SHORT' if length($value) < $length; |
|
72
|
6
|
100
|
|
|
|
12
|
return 'TOO_LONG' if length($value) > $length; |
|
73
|
4
|
|
|
|
|
6
|
return; |
|
74
|
14
|
|
|
|
|
78
|
}; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub length_between { |
|
79
|
14
|
|
|
14
|
0
|
7
|
my ($min_length, $max_length) = @_; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
return sub { |
|
82
|
14
|
|
|
14
|
|
10
|
my $value = shift; |
|
83
|
14
|
100
|
100
|
|
|
44
|
return if !defined($value) || $value eq ''; |
|
84
|
11
|
100
|
|
|
|
38
|
return 'FORMAT_ERROR' if ref($value); |
|
85
|
|
|
|
|
|
|
|
|
86
|
7
|
100
|
|
|
|
11
|
return 'TOO_SHORT' if length($value) < $min_length; |
|
87
|
6
|
100
|
|
|
|
11
|
return 'TOO_LONG' if length($value) > $max_length; |
|
88
|
4
|
|
|
|
|
4
|
return; |
|
89
|
14
|
|
|
|
|
80
|
}; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub like { |
|
94
|
15
|
|
|
15
|
0
|
13
|
my ($re, $flags) = @_; |
|
95
|
|
|
|
|
|
|
|
|
96
|
15
|
|
66
|
|
|
32
|
my $is_ignore_case = @_ == 3 && index( $flags, 'i') >= 0; |
|
97
|
15
|
100
|
|
|
|
179
|
$re = $is_ignore_case ? qr/$re/i : qr/$re/; |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
return sub { |
|
100
|
15
|
|
|
15
|
|
14
|
my $value = shift; |
|
101
|
15
|
100
|
100
|
|
|
45
|
return if !defined($value) || $value eq ''; |
|
102
|
12
|
100
|
|
|
|
18
|
return 'FORMAT_ERROR' if ref($value); |
|
103
|
|
|
|
|
|
|
|
|
104
|
8
|
100
|
|
|
|
35
|
return 'WRONG_FORMAT' unless $value =~ m/$re/; |
|
105
|
4
|
|
|
|
|
7
|
return; |
|
106
|
15
|
|
|
|
|
93
|
}; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub string { |
|
111
|
|
|
|
|
|
|
return sub { |
|
112
|
9
|
|
|
9
|
|
7
|
my $value = shift; |
|
113
|
|
|
|
|
|
|
|
|
114
|
9
|
100
|
66
|
|
|
28
|
return if !defined($value) || $value eq ''; |
|
115
|
8
|
100
|
|
|
|
17
|
return 'FORMAT_ERROR' if ref($value); |
|
116
|
4
|
|
|
|
|
4
|
return; |
|
117
|
9
|
|
|
9
|
0
|
56
|
}; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub equal { |
|
122
|
18
|
|
|
18
|
0
|
19
|
my $allowed_value = shift; |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
return sub { |
|
125
|
21
|
|
|
21
|
|
22
|
my ($value, undef, $output_ref) = @_; |
|
126
|
21
|
100
|
66
|
|
|
70
|
return if !defined($value) || $value eq ''; |
|
127
|
20
|
100
|
|
|
|
35
|
return 'FORMAT_ERROR' if ref($value); |
|
128
|
|
|
|
|
|
|
|
|
129
|
16
|
100
|
|
|
|
30
|
return if $value eq $allowed_value; |
|
130
|
|
|
|
|
|
|
|
|
131
|
7
|
|
|
|
|
13
|
return 'NOT_ALLOWED_VALUE'; |
|
132
|
18
|
|
|
|
|
118
|
}; |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
1; |