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
|
|
1837
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
105
|
|
12
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
143
|
|
13
|
3
|
|
|
3
|
|
15
|
use utf8; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
15
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# --- version --- |
16
|
|
|
|
|
|
|
our $VERSION = 1.20_03; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#=------------------------------------------------------------------------ { use, constants } |
19
|
|
|
|
|
|
|
|
20
|
3
|
|
|
3
|
|
247
|
use Params::Dry::Types qw(:const); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1485
|
|
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
|
4518
|
( ref( $_[0] ) or $_[0] !~ /^[+\-]?(\d+)$/ ) and return FAIL; |
31
|
9
|
100
|
66
|
|
|
57
|
$_[1] and $1 and length $1 > $_[1] and return FAIL; |
|
|
|
66
|
|
|
|
|
32
|
7
|
|
|
|
|
22
|
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
|
7264
|
( ref( $_[0] ) or $_[0] !~ /^[+\-]?(\d+(\.\d+)?)$/ ) and return FAIL; |
42
|
11
|
100
|
66
|
|
|
554
|
$_[1] and $1 and length $1 > $_[1] and return FAIL; |
|
|
|
66
|
|
|
|
|
43
|
9
|
100
|
66
|
|
|
54
|
$_[2] and $2 and length $2 > $_[2] + 1 and return FAIL; |
|
|
|
66
|
|
|
|
|
44
|
8
|
|
|
|
|
31
|
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
|
4321
|
return PASS if !ref( $_[0] ) and ( "$_[0]" eq '0' or "$_[0]" eq 1 ); |
|
|
|
66
|
|
|
|
|
54
|
2
|
|
|
|
|
8
|
FAIL; |
55
|
|
|
|
|
|
|
} #+ end of: sub Bool |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
}; |
58
|
|
|
|
|
|
|
0115 && 0x4d; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
#+ End of Params::Dry::Types::Number |
61
|
|
|
|
|
|
|
__END__ |