line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Vparam::Numbers; |
2
|
72
|
|
|
72
|
|
3196971
|
use Mojo::Base -strict; |
|
72
|
|
|
|
|
9528
|
|
|
72
|
|
|
|
|
503
|
|
3
|
72
|
|
|
72
|
|
7623
|
use Mojolicious::Plugin::Vparam::Common; |
|
72
|
|
|
|
|
171
|
|
|
72
|
|
|
|
|
80845
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub check_int($) { |
6
|
227
|
100
|
|
227
|
0
|
825
|
return 'Value is not defined' unless defined $_[0]; |
7
|
136
|
50
|
|
|
|
469
|
return 'Value is not set' unless length $_[0]; |
8
|
136
|
|
|
|
|
483
|
return 0; |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub check_numeric($) { |
12
|
73
|
100
|
|
73
|
0
|
194
|
return 'Value is not defined' unless defined $_[0]; |
13
|
64
|
50
|
|
|
|
196
|
return 'Value is not set' unless length $_[0]; |
14
|
64
|
|
|
|
|
142
|
return 0; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub check_money($) { |
18
|
9
|
50
|
|
9
|
0
|
21
|
return 'Value is not defined' unless defined $_[0]; |
19
|
9
|
50
|
|
|
|
25
|
return 'Value is not set' unless length $_[0]; |
20
|
|
|
|
|
|
|
|
21
|
9
|
|
|
|
|
21
|
my $numeric = check_numeric $_[0]; |
22
|
9
|
50
|
|
|
|
21
|
return $numeric if $numeric; |
23
|
|
|
|
|
|
|
|
24
|
9
|
100
|
100
|
|
|
61
|
return 'Invalid fractional part' |
25
|
|
|
|
|
|
|
if $_[0] =~ m{\.} && $_[0] !~ m{\.\d{0,2}$}; |
26
|
8
|
|
|
|
|
28
|
return 0; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub check_percent($) { |
30
|
5
|
50
|
|
5
|
0
|
10
|
return 'Value is not defined' unless defined $_[0]; |
31
|
5
|
50
|
|
|
|
16
|
return 'Value is not set' unless length $_[0]; |
32
|
|
|
|
|
|
|
|
33
|
5
|
|
|
|
|
30
|
my $numeric = check_numeric $_[0]; |
34
|
5
|
50
|
|
|
|
11
|
return $numeric if $numeric; |
35
|
|
|
|
|
|
|
|
36
|
5
|
100
|
|
|
|
17
|
return 'Value must be greater than 0' unless $_[0] >= 0; |
37
|
4
|
100
|
|
|
|
11
|
return 'Value must be less than 100' unless $_[0] <= 100; |
38
|
3
|
|
|
|
|
9
|
return 0; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub check_lon($) { |
42
|
12
|
50
|
|
12
|
0
|
34
|
return 'Value not defined' unless defined $_[0]; |
43
|
|
|
|
|
|
|
|
44
|
12
|
|
|
|
|
38
|
my $numeric = check_numeric $_[0]; |
45
|
12
|
50
|
|
|
|
34
|
return $numeric if $numeric; |
46
|
|
|
|
|
|
|
|
47
|
12
|
100
|
|
|
|
75
|
return 'Value should not be less than -180°' unless $_[0] >= -180; |
48
|
11
|
100
|
|
|
|
47
|
return 'Value should not be greater than 180°' unless $_[0] <= 180; |
49
|
10
|
|
|
|
|
30
|
return 0; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub check_lat($) { |
53
|
12
|
50
|
|
12
|
0
|
30
|
return 'Value not defined' unless defined $_[0]; |
54
|
|
|
|
|
|
|
|
55
|
12
|
|
|
|
|
27
|
my $numeric = check_numeric $_[0]; |
56
|
12
|
50
|
|
|
|
34
|
return $numeric if $numeric; |
57
|
|
|
|
|
|
|
|
58
|
12
|
100
|
|
|
|
38
|
return 'Value should not be less than -90°' unless $_[0] >= -90; |
59
|
11
|
100
|
|
|
|
31
|
return 'Value should not be greater than 90°' unless $_[0] <= 90; |
60
|
10
|
|
|
|
|
24
|
return 0; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub parse_int($) { |
64
|
227
|
|
|
227
|
0
|
523
|
my ($str) = @_; |
65
|
227
|
100
|
|
|
|
661
|
return undef unless defined $str; |
66
|
196
|
|
|
|
|
887
|
my ($int) = $str =~ m{([-+]?\d+)}; |
67
|
196
|
|
|
|
|
611
|
return $int; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub parse_number($) { |
71
|
33
|
|
|
33
|
0
|
62
|
my ($str) = @_; |
72
|
33
|
50
|
|
|
|
76
|
return undef unless defined $str; |
73
|
33
|
|
|
|
|
157
|
my ($number) = $str =~ m{ |
74
|
|
|
|
|
|
|
( |
75
|
|
|
|
|
|
|
[-+]? |
76
|
|
|
|
|
|
|
(?: |
77
|
|
|
|
|
|
|
\d+(?:[\.,]\d*)? |
78
|
|
|
|
|
|
|
| |
79
|
|
|
|
|
|
|
[\.,]\d+ |
80
|
|
|
|
|
|
|
) |
81
|
|
|
|
|
|
|
) |
82
|
|
|
|
|
|
|
}x; |
83
|
33
|
100
|
|
|
|
85
|
return undef unless defined $number; |
84
|
31
|
|
|
|
|
104
|
tr{,}{.} for $number; |
85
|
31
|
|
|
|
|
79
|
return $number; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub register { |
89
|
74
|
|
|
74
|
0
|
1106
|
my ($class, $self, $app, $conf) = @_; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$app->vtype( |
92
|
|
|
|
|
|
|
int => |
93
|
227
|
|
|
227
|
|
732
|
pre => sub{ parse_int $_[1] }, |
94
|
227
|
|
|
227
|
|
583
|
valid => sub{ check_int $_[1] }, |
95
|
217
|
100
|
|
217
|
|
908
|
post => sub{ defined $_[1] ? 0 + $_[1] : undef }, |
96
|
74
|
|
|
|
|
846
|
); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my %numeric = ( |
99
|
11
|
|
|
11
|
|
26
|
pre => sub{ parse_number $_[1] }, |
100
|
11
|
|
|
11
|
|
26
|
valid => sub{ check_numeric $_[1] }, |
101
|
11
|
100
|
|
11
|
|
44
|
post => sub{ defined $_[1] ? 0.0 + $_[1] : undef }, |
102
|
74
|
|
|
|
|
683
|
); |
103
|
74
|
|
|
|
|
602
|
$app->vtype(numeric => %numeric); |
104
|
74
|
|
|
|
|
606
|
$app->vtype(number => %numeric); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
$app->vtype( |
107
|
|
|
|
|
|
|
money => |
108
|
9
|
|
|
9
|
|
21
|
pre => sub{ parse_number $_[1] }, |
109
|
9
|
|
|
9
|
|
22
|
valid => sub{ check_money $_[1] }, |
110
|
9
|
100
|
|
9
|
|
40
|
post => sub{ defined $_[1] ? 0.0 + $_[1] : undef }, |
111
|
74
|
|
|
|
|
815
|
); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
$app->vtype( |
114
|
|
|
|
|
|
|
percent => |
115
|
5
|
|
|
5
|
|
12
|
pre => sub{ parse_number $_[1] }, |
116
|
5
|
|
|
5
|
|
11
|
valid => sub{ check_percent $_[1] }, |
117
|
5
|
100
|
|
5
|
|
17
|
post => sub{ defined $_[1] ? 0.0 + $_[1] : undef }, |
118
|
74
|
|
|
|
|
877
|
); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
$app->vtype( |
121
|
|
|
|
|
|
|
lon => |
122
|
4
|
|
|
4
|
|
9
|
pre => sub{ parse_number $_[1] }, |
123
|
4
|
|
|
4
|
|
11
|
valid => sub{ check_lon $_[1] }, |
124
|
4
|
100
|
|
4
|
|
15
|
post => sub{ defined $_[1] ? 0.0 + $_[1] : undef }, |
125
|
74
|
|
|
|
|
796
|
); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
$app->vtype( |
128
|
|
|
|
|
|
|
lat => |
129
|
4
|
|
|
4
|
|
10
|
pre => sub{ parse_number $_[1] }, |
130
|
4
|
|
|
4
|
|
9
|
valid => sub{ check_lat $_[1] }, |
131
|
4
|
100
|
|
4
|
|
57
|
post => sub{ defined $_[1] ? 0.0 + $_[1] : undef }, |
132
|
74
|
|
|
|
|
814
|
); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
74
|
|
|
|
|
369
|
return; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; |