line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Validator::LIVR::Rules::Numeric; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
11
|
use strict; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
84
|
|
4
|
4
|
|
|
4
|
|
12
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
76
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
12
|
use Scalar::Util qw/looks_like_number/; |
|
4
|
|
|
|
|
3
|
|
|
4
|
|
|
|
|
2151
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '2.0'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub integer { |
11
|
|
|
|
|
|
|
return sub { |
12
|
14
|
|
|
14
|
|
11
|
my $value = shift; |
13
|
14
|
100
|
100
|
|
|
49
|
return if !defined($value) || $value eq ''; |
14
|
11
|
100
|
|
|
|
20
|
return 'FORMAT_ERROR' if ref($value); |
15
|
7
|
100
|
|
|
|
20
|
return 'NOT_INTEGER' unless looks_like_number($value); |
16
|
|
|
|
|
|
|
|
17
|
5
|
100
|
66
|
|
|
29
|
return 'NOT_INTEGER' unless $value =~ /^\-?\d+$/ && looks_like_number($value); |
18
|
3
|
|
|
|
|
3
|
return; |
19
|
15
|
|
|
15
|
0
|
77
|
}; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub positive_integer { |
24
|
|
|
|
|
|
|
return sub { |
25
|
109
|
|
|
109
|
|
84
|
my $value = shift; |
26
|
109
|
100
|
100
|
|
|
306
|
return if !defined($value) || $value eq ''; |
27
|
99
|
100
|
|
|
|
132
|
return 'FORMAT_ERROR' if ref($value); |
28
|
95
|
100
|
|
|
|
195
|
return 'NOT_POSITIVE_INTEGER' unless looks_like_number($value); |
29
|
|
|
|
|
|
|
|
30
|
90
|
100
|
66
|
|
|
530
|
return 'NOT_POSITIVE_INTEGER' unless $value =~ /^\d+$/ |
|
|
|
100
|
|
|
|
|
31
|
|
|
|
|
|
|
&& looks_like_number($value) |
32
|
|
|
|
|
|
|
&& $value > 0; |
33
|
72
|
|
|
|
|
99
|
return; |
34
|
90
|
|
|
90
|
0
|
536
|
}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub decimal { |
39
|
|
|
|
|
|
|
return sub { |
40
|
13
|
|
|
13
|
|
16
|
my $value = shift; |
41
|
13
|
100
|
66
|
|
|
57
|
return if !defined($value) || $value eq ''; |
42
|
11
|
100
|
|
|
|
24
|
return 'FORMAT_ERROR' if ref($value); |
43
|
7
|
100
|
|
|
|
29
|
return 'NOT_DECIMAL' unless looks_like_number($value); |
44
|
|
|
|
|
|
|
|
45
|
3
|
50
|
33
|
|
|
20
|
return 'NOT_DECIMAL' unless $value =~ /^\-?[\d.]+$/ |
46
|
|
|
|
|
|
|
&& looks_like_number($value); |
47
|
|
|
|
|
|
|
|
48
|
3
|
|
|
|
|
4
|
return; |
49
|
13
|
|
|
13
|
0
|
131
|
}; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub positive_decimal { |
54
|
|
|
|
|
|
|
return sub { |
55
|
14
|
|
|
14
|
|
12
|
my $value = shift; |
56
|
14
|
100
|
66
|
|
|
48
|
return if !defined($value) || $value eq ''; |
57
|
12
|
100
|
|
|
|
22
|
return 'FORMAT_ERROR' if ref($value); |
58
|
8
|
100
|
|
|
|
20
|
return 'NOT_POSITIVE_DECIMAL' unless looks_like_number($value); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
6
|
100
|
33
|
|
|
51
|
return 'NOT_POSITIVE_DECIMAL' unless $value =~ /^\-?[\d.]+$/ |
|
|
|
66
|
|
|
|
|
62
|
|
|
|
|
|
|
&& looks_like_number($value) |
63
|
|
|
|
|
|
|
&& $value > 0; |
64
|
|
|
|
|
|
|
|
65
|
4
|
|
|
|
|
5
|
return; |
66
|
14
|
|
|
14
|
0
|
75
|
}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub max_number { |
71
|
16
|
|
|
16
|
0
|
13
|
my $max_number = shift; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
return sub { |
74
|
24
|
|
|
24
|
|
22
|
my $value = shift; |
75
|
24
|
100
|
66
|
|
|
68
|
return if !defined($value) || $value eq ''; |
76
|
22
|
100
|
|
|
|
32
|
return 'FORMAT_ERROR' if ref($value); |
77
|
18
|
100
|
|
|
|
39
|
return 'NOT_NUMBER' unless looks_like_number($value); |
78
|
|
|
|
|
|
|
|
79
|
17
|
100
|
|
|
|
25
|
return 'TOO_HIGH' if $value > $max_number; |
80
|
13
|
|
|
|
|
15
|
return; |
81
|
16
|
|
|
|
|
81
|
}; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub min_number { |
86
|
48
|
|
|
48
|
0
|
41
|
my $min_number = shift; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
return sub { |
89
|
42
|
|
|
42
|
|
34
|
my $value = shift; |
90
|
42
|
100
|
66
|
|
|
134
|
return if !defined($value) || $value eq ''; |
91
|
40
|
100
|
|
|
|
58
|
return 'FORMAT_ERROR' if ref($value); |
92
|
36
|
100
|
|
|
|
67
|
return 'NOT_NUMBER' unless looks_like_number($value); |
93
|
|
|
|
|
|
|
|
94
|
35
|
100
|
|
|
|
52
|
return 'TOO_LOW' if $value < $min_number; |
95
|
28
|
|
|
|
|
34
|
return; |
96
|
48
|
|
|
|
|
261
|
}; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub number_between { |
101
|
12
|
|
|
12
|
0
|
9
|
my ($min_number, $max_number) = @_; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
return sub { |
104
|
12
|
|
|
12
|
|
9
|
my $value = shift; |
105
|
12
|
100
|
66
|
|
|
38
|
return if !defined($value) || $value eq ''; |
106
|
10
|
100
|
|
|
|
19
|
return 'FORMAT_ERROR' if ref($value); |
107
|
6
|
100
|
|
|
|
14
|
return 'NOT_NUMBER' unless looks_like_number($value); |
108
|
|
|
|
|
|
|
|
109
|
5
|
100
|
|
|
|
13
|
return 'TOO_LOW' if $value < $min_number; |
110
|
4
|
100
|
|
|
|
6
|
return 'TOO_HIGH' if $value > $max_number; |
111
|
3
|
|
|
|
|
4
|
return; |
112
|
12
|
|
|
|
|
67
|
}; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |