| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
|
2
|
|
|
|
|
|
|
#* |
|
3
|
|
|
|
|
|
|
#* Info: Number types definitions module |
|
4
|
|
|
|
|
|
|
#* Author: Pawel Guspiel (neo77) |
|
5
|
|
|
|
|
|
|
#* |
|
6
|
|
|
|
|
|
|
#* This module keeps validation functions. You can of course add your modules which uses this and will add additional checks |
|
7
|
|
|
|
|
|
|
#* Build in types for Params::Dry |
|
8
|
|
|
|
|
|
|
#* |
|
9
|
|
|
|
|
|
|
package Params::Dry::Types::Number; |
|
10
|
|
|
|
|
|
|
{ |
|
11
|
3
|
|
|
3
|
|
1474
|
use strict; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
97
|
|
|
12
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
78
|
|
|
13
|
3
|
|
|
3
|
|
14
|
use utf8; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
14
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# --- version --- |
|
16
|
|
|
|
|
|
|
our $VERSION = 1.20_01; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#=------------------------------------------------------------------------ { use, constants } |
|
19
|
|
|
|
|
|
|
|
|
20
|
3
|
|
|
3
|
|
130
|
use Params::Dry::Types qw(:const); |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
1420
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
#=------------------------------------------------------------------------ { module public functions } |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
#=------ |
|
25
|
|
|
|
|
|
|
# Int |
|
26
|
|
|
|
|
|
|
#=------ |
|
27
|
|
|
|
|
|
|
#* int type check Int[3] - no more than 999 |
|
28
|
|
|
|
|
|
|
#* RETURN: PASS if test pass otherwise FAIL |
|
29
|
|
|
|
|
|
|
sub Int { |
|
30
|
15
|
100
|
100
|
15
|
1
|
3935
|
( ref( $_[0] ) or $_[0] !~ /^[+\-]?(\d+)$/ ) and return FAIL; |
|
31
|
9
|
100
|
66
|
|
|
68
|
$_[1] and $1 and length $1 > $_[1] and return FAIL; |
|
|
|
|
66
|
|
|
|
|
|
32
|
7
|
|
|
|
|
24
|
PASS; |
|
33
|
|
|
|
|
|
|
} #+ end of: sub Int |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#=-------- |
|
36
|
|
|
|
|
|
|
# Float |
|
37
|
|
|
|
|
|
|
#=-------- |
|
38
|
|
|
|
|
|
|
#* float type check |
|
39
|
|
|
|
|
|
|
#* RETURN: PASS if test pass otherwise FAIL |
|
40
|
|
|
|
|
|
|
sub Float { |
|
41
|
13
|
100
|
100
|
13
|
1
|
5413
|
( ref( $_[0] ) or $_[0] !~ /^[+\-]?(\d+(\.\d+)?)$/ ) and return FAIL; |
|
42
|
11
|
100
|
66
|
|
|
56
|
$_[1] and $1 and length $1 > $_[1] and return FAIL; |
|
|
|
|
66
|
|
|
|
|
|
43
|
9
|
100
|
66
|
|
|
34
|
$_[2] and $2 and length $2 > $_[2] + 1 and return FAIL; |
|
|
|
|
66
|
|
|
|
|
|
44
|
8
|
|
|
|
|
23
|
PASS; |
|
45
|
|
|
|
|
|
|
} #+ end of: sub Float |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
#=------- |
|
48
|
|
|
|
|
|
|
# Bool |
|
49
|
|
|
|
|
|
|
#=------- |
|
50
|
|
|
|
|
|
|
#* Bool type check |
|
51
|
|
|
|
|
|
|
#* RETURN: PASS if test pass otherwise FAIL |
|
52
|
|
|
|
|
|
|
sub Bool { |
|
53
|
5
|
100
|
100
|
5
|
1
|
2055
|
return PASS if !ref( $_[0] ) and ( "$_[0]" eq '0' or "$_[0]" eq 1 ); |
|
|
|
|
66
|
|
|
|
|
|
54
|
2
|
|
|
|
|
5
|
FAIL; |
|
55
|
|
|
|
|
|
|
} #+ end of: sub Bool |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
}; |
|
58
|
|
|
|
|
|
|
0115 && 0x4d; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
#+ End of Params::Dry::Types::Number |
|
61
|
|
|
|
|
|
|
__END__ |