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