line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Vparam::Numbers; |
2
|
73
|
|
|
73
|
|
4979448
|
use Mojo::Base -strict; |
|
73
|
|
|
|
|
108141
|
|
|
73
|
|
|
|
|
406
|
|
3
|
73
|
|
|
73
|
|
7578
|
use Mojolicious::Plugin::Vparam::Common; |
|
73
|
|
|
|
|
142
|
|
|
73
|
|
|
|
|
73347
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub check_int($) { |
6
|
246
|
100
|
|
246
|
0
|
653
|
return 'Value is not defined' unless defined $_[0]; |
7
|
142
|
50
|
|
|
|
383
|
return 'Value is not set' unless length $_[0]; |
8
|
142
|
|
|
|
|
401
|
return 0; |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub check_numeric($) { |
12
|
73
|
100
|
|
73
|
0
|
149
|
return 'Value is not defined' unless defined $_[0]; |
13
|
64
|
50
|
|
|
|
209
|
return 'Value is not set' unless length $_[0]; |
14
|
64
|
|
|
|
|
113
|
return 0; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub check_money($) { |
18
|
9
|
50
|
|
9
|
0
|
18
|
return 'Value is not defined' unless defined $_[0]; |
19
|
9
|
50
|
|
|
|
22
|
return 'Value is not set' unless length $_[0]; |
20
|
|
|
|
|
|
|
|
21
|
9
|
|
|
|
|
13
|
my $numeric = check_numeric $_[0]; |
22
|
9
|
50
|
|
|
|
16
|
return $numeric if $numeric; |
23
|
|
|
|
|
|
|
|
24
|
9
|
100
|
100
|
|
|
60
|
return 'Invalid fractional part' |
25
|
|
|
|
|
|
|
if $_[0] =~ m{\.} && $_[0] !~ m{\.\d{0,2}$}; |
26
|
8
|
|
|
|
|
23
|
return 0; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub check_percent($) { |
30
|
5
|
50
|
|
5
|
0
|
8
|
return 'Value is not defined' unless defined $_[0]; |
31
|
5
|
50
|
|
|
|
12
|
return 'Value is not set' unless length $_[0]; |
32
|
|
|
|
|
|
|
|
33
|
5
|
|
|
|
|
10
|
my $numeric = check_numeric $_[0]; |
34
|
5
|
50
|
|
|
|
9
|
return $numeric if $numeric; |
35
|
|
|
|
|
|
|
|
36
|
5
|
100
|
|
|
|
14
|
return 'Value must be greater than 0' unless $_[0] >= 0; |
37
|
4
|
100
|
|
|
|
9
|
return 'Value must be less than 100' unless $_[0] <= 100; |
38
|
3
|
|
|
|
|
7
|
return 0; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub check_lon($) { |
42
|
12
|
50
|
|
12
|
0
|
29
|
return 'Value not defined' unless defined $_[0]; |
43
|
|
|
|
|
|
|
|
44
|
12
|
|
|
|
|
34
|
my $numeric = check_numeric $_[0]; |
45
|
12
|
50
|
|
|
|
27
|
return $numeric if $numeric; |
46
|
|
|
|
|
|
|
|
47
|
12
|
100
|
|
|
|
53
|
return 'Value should not be less than -180°' unless $_[0] >= -180; |
48
|
11
|
100
|
|
|
|
26
|
return 'Value should not be greater than 180°' unless $_[0] <= 180; |
49
|
10
|
|
|
|
|
26
|
return 0; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub check_lat($) { |
53
|
12
|
50
|
|
12
|
0
|
26
|
return 'Value not defined' unless defined $_[0]; |
54
|
|
|
|
|
|
|
|
55
|
12
|
|
|
|
|
25
|
my $numeric = check_numeric $_[0]; |
56
|
12
|
50
|
|
|
|
22
|
return $numeric if $numeric; |
57
|
|
|
|
|
|
|
|
58
|
12
|
100
|
|
|
|
31
|
return 'Value should not be less than -90°' unless $_[0] >= -90; |
59
|
11
|
100
|
|
|
|
34
|
return 'Value should not be greater than 90°' unless $_[0] <= 90; |
60
|
10
|
|
|
|
|
21
|
return 0; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub parse_int($) { |
64
|
246
|
|
|
246
|
0
|
422
|
my ($str) = @_; |
65
|
246
|
100
|
|
|
|
494
|
return undef unless defined $str; |
66
|
210
|
|
|
|
|
763
|
my ($int) = $str =~ m{([-+]?\d+)}; |
67
|
210
|
|
|
|
|
487
|
return $int; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub parse_number($) { |
71
|
33
|
|
|
33
|
0
|
70
|
my ($str) = @_; |
72
|
33
|
50
|
|
|
|
105
|
return undef unless defined $str; |
73
|
33
|
|
|
|
|
179
|
my ($number) = $str =~ m{ |
74
|
|
|
|
|
|
|
( |
75
|
|
|
|
|
|
|
[-+]? |
76
|
|
|
|
|
|
|
(?: |
77
|
|
|
|
|
|
|
\d+(?:[\.,]\d*)? |
78
|
|
|
|
|
|
|
| |
79
|
|
|
|
|
|
|
[\.,]\d+ |
80
|
|
|
|
|
|
|
) |
81
|
|
|
|
|
|
|
) |
82
|
|
|
|
|
|
|
}x; |
83
|
33
|
100
|
|
|
|
125
|
return undef unless defined $number; |
84
|
31
|
|
|
|
|
109
|
tr{,}{.} for $number; |
85
|
31
|
|
|
|
|
85
|
return $number; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub register { |
89
|
75
|
|
|
75
|
0
|
240
|
my ($class, $self, $app, $conf) = @_; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$app->vtype( |
92
|
|
|
|
|
|
|
int => |
93
|
246
|
|
|
246
|
|
532
|
pre => sub{ parse_int $_[1] }, |
94
|
246
|
|
|
246
|
|
475
|
valid => sub{ check_int $_[1] }, |
95
|
236
|
100
|
|
236
|
|
671
|
post => sub{ defined $_[1] ? 0 + $_[1] : undef }, |
96
|
75
|
|
|
|
|
751
|
); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my %numeric = ( |
99
|
11
|
|
|
11
|
|
25
|
pre => sub{ parse_number $_[1] }, |
100
|
11
|
|
|
11
|
|
24
|
valid => sub{ check_numeric $_[1] }, |
101
|
11
|
100
|
|
11
|
|
45
|
post => sub{ defined $_[1] ? 0.0 + $_[1] : undef }, |
102
|
75
|
|
|
|
|
564
|
); |
103
|
75
|
|
|
|
|
511
|
$app->vtype(numeric => %numeric); |
104
|
75
|
|
|
|
|
529
|
$app->vtype(number => %numeric); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
$app->vtype( |
107
|
|
|
|
|
|
|
money => |
108
|
9
|
|
|
9
|
|
17
|
pre => sub{ parse_number $_[1] }, |
109
|
9
|
|
|
9
|
|
16
|
valid => sub{ check_money $_[1] }, |
110
|
9
|
100
|
|
9
|
|
45
|
post => sub{ defined $_[1] ? 0.0 + $_[1] : undef }, |
111
|
75
|
|
|
|
|
648
|
); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
$app->vtype( |
114
|
|
|
|
|
|
|
percent => |
115
|
5
|
|
|
5
|
|
8
|
pre => sub{ parse_number $_[1] }, |
116
|
5
|
|
|
5
|
|
10
|
valid => sub{ check_percent $_[1] }, |
117
|
5
|
100
|
|
5
|
|
18
|
post => sub{ defined $_[1] ? 0.0 + $_[1] : undef }, |
118
|
75
|
|
|
|
|
641
|
); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
$app->vtype( |
121
|
|
|
|
|
|
|
lon => |
122
|
4
|
|
|
4
|
|
10
|
pre => sub{ parse_number $_[1] }, |
123
|
4
|
|
|
4
|
|
12
|
valid => sub{ check_lon $_[1] }, |
124
|
4
|
100
|
|
4
|
|
23
|
post => sub{ defined $_[1] ? 0.0 + $_[1] : undef }, |
125
|
75
|
|
|
|
|
603
|
); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
$app->vtype( |
128
|
|
|
|
|
|
|
lat => |
129
|
4
|
|
|
4
|
|
8
|
pre => sub{ parse_number $_[1] }, |
130
|
4
|
|
|
4
|
|
11
|
valid => sub{ check_lat $_[1] }, |
131
|
4
|
100
|
|
4
|
|
16
|
post => sub{ defined $_[1] ? 0.0 + $_[1] : undef }, |
132
|
75
|
|
|
|
|
641
|
); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
75
|
|
|
|
|
297
|
return; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; |