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