line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Validator::LIVR::Rules::String; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
20
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
143
|
|
4
|
4
|
|
|
4
|
|
46
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
2299
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.09'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub one_of { |
9
|
13
|
|
|
13
|
0
|
13
|
my $allowed_values; |
10
|
13
|
100
|
|
|
|
26
|
if (ref $_[0] eq 'ARRAY') { |
11
|
7
|
|
|
|
|
9
|
$allowed_values = $_[0]; |
12
|
|
|
|
|
|
|
} else { |
13
|
6
|
|
|
|
|
10
|
$allowed_values = [@_]; |
14
|
6
|
|
|
|
|
10
|
pop @$allowed_values; # pop rule_builders |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
return sub { |
19
|
13
|
|
|
13
|
|
13
|
my $value = shift; |
20
|
13
|
100
|
66
|
|
|
56
|
return if !defined($value) || $value eq ''; |
21
|
|
|
|
|
|
|
|
22
|
12
|
100
|
|
|
|
15
|
return 'NOT_ALLOWED_VALUE' unless grep { $value eq $_ } @$allowed_values; |
|
24
|
|
|
|
|
47
|
|
23
|
6
|
|
|
|
|
10
|
return; |
24
|
|
|
|
|
|
|
} |
25
|
13
|
|
|
|
|
89
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub max_length { |
29
|
10
|
|
|
10
|
0
|
9
|
my $max_length = shift; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
return sub { |
32
|
10
|
|
|
10
|
|
11
|
my $value = shift; |
33
|
10
|
100
|
66
|
|
|
41
|
return if !defined($value) || $value eq ''; |
34
|
|
|
|
|
|
|
|
35
|
8
|
100
|
|
|
|
24
|
return 'TOO_LONG' if length($value) > $max_length; |
36
|
4
|
|
|
|
|
7
|
return; |
37
|
10
|
|
|
|
|
65
|
}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub min_length { |
42
|
12
|
|
|
12
|
0
|
11
|
my $min_length = shift; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
return sub { |
45
|
12
|
|
|
12
|
|
12
|
my $value = shift; |
46
|
12
|
100
|
66
|
|
|
45
|
return if !defined($value) || $value eq ''; |
47
|
|
|
|
|
|
|
|
48
|
10
|
100
|
|
|
|
31
|
return 'TOO_SHORT' if length($value) < $min_length; |
49
|
5
|
|
|
|
|
8
|
return; |
50
|
12
|
|
|
|
|
80
|
}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub length_equal { |
55
|
8
|
|
|
8
|
0
|
8
|
my $length = shift; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
return sub { |
58
|
8
|
|
|
8
|
|
5
|
my $value = shift; |
59
|
8
|
100
|
66
|
|
|
30
|
return if !defined($value) || $value eq ''; |
60
|
|
|
|
|
|
|
|
61
|
6
|
100
|
|
|
|
12
|
return 'TOO_SHORT' if length($value) < $length; |
62
|
5
|
100
|
|
|
|
11
|
return 'TOO_LONG' if length($value) > $length; |
63
|
3
|
|
|
|
|
4
|
return; |
64
|
8
|
|
|
|
|
48
|
}; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub length_between { |
69
|
8
|
|
|
8
|
0
|
9
|
my ($min_length, $max_length) = @_; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
return sub { |
72
|
8
|
|
|
8
|
|
11
|
my $value = shift; |
73
|
8
|
100
|
66
|
|
|
31
|
return if !defined($value) || $value eq ''; |
74
|
|
|
|
|
|
|
|
75
|
6
|
100
|
|
|
|
12
|
return 'TOO_SHORT' if length($value) < $min_length; |
76
|
5
|
100
|
|
|
|
13
|
return 'TOO_LONG' if length($value) > $max_length; |
77
|
3
|
|
|
|
|
4
|
return; |
78
|
8
|
|
|
|
|
48
|
}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub like { |
83
|
10
|
|
|
10
|
0
|
12
|
my ($re, $flags) = @_; |
84
|
|
|
|
|
|
|
|
85
|
10
|
|
66
|
|
|
30
|
my $is_ignore_case = @_ == 3 && index( $flags, 'i') >= 0; |
86
|
10
|
100
|
|
|
|
197
|
$re = $is_ignore_case ? qr/$re/i : qr/$re/; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
return sub { |
89
|
10
|
|
|
10
|
|
9
|
my $value = shift; |
90
|
10
|
100
|
66
|
|
|
36
|
return if !defined($value) || $value eq ''; |
91
|
|
|
|
|
|
|
|
92
|
8
|
100
|
|
|
|
36
|
return 'WRONG_FORMAT' unless $value =~ m/$re/; |
93
|
4
|
|
|
|
|
6
|
return; |
94
|
10
|
|
|
|
|
101
|
}; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |