line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
#* |
3
|
|
|
|
|
|
|
#* Name: Params::Dry::Types |
4
|
|
|
|
|
|
|
#* Info: Types definitions module |
5
|
|
|
|
|
|
|
#* Author: Pawel Guspiel (neo77) |
6
|
|
|
|
|
|
|
#* |
7
|
|
|
|
|
|
|
#* This module keeps validation functions. You can of course add your modules which uses this and will add additional checks |
8
|
|
|
|
|
|
|
#* Build in types for Params::Dry |
9
|
|
|
|
|
|
|
#* |
10
|
|
|
|
|
|
|
package Params::Dry::Types; |
11
|
|
|
|
|
|
|
{ |
12
|
3
|
|
|
3
|
|
1008
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
99
|
|
13
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
89
|
|
14
|
3
|
|
|
3
|
|
1300
|
use utf8; |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
22
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# --- version --- |
17
|
|
|
|
|
|
|
our $VERSION = 1.20_01; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#=------------------------------------------------------------------------ { use, constants } |
20
|
|
|
|
|
|
|
|
21
|
3
|
|
|
3
|
|
152
|
use Scalar::Util 'blessed'; |
|
3
|
|
|
|
|
39
|
|
|
3
|
|
|
|
|
279
|
|
22
|
|
|
|
|
|
|
|
23
|
3
|
|
|
3
|
|
18
|
use constant PASS => 1; # pass test |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
202
|
|
24
|
3
|
|
|
3
|
|
16
|
use constant FAIL => 0; # test fail |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
138
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
#=------------------------------------------------------------------------ { export } |
27
|
|
|
|
|
|
|
|
28
|
3
|
|
|
3
|
|
17
|
use Exporter; # to export _ rq and opt |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1264
|
|
29
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our @EXPORT_OK = qw(PASS FAIL); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( const => [qw(PASS FAIL)], ); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#=------------------------------------------------------------------------ { module public functions } |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#=--------- |
38
|
|
|
|
|
|
|
# String |
39
|
|
|
|
|
|
|
#=--------- |
40
|
|
|
|
|
|
|
#* string type check (parameter sets max length) |
41
|
|
|
|
|
|
|
#* RETURN: PASS if test pass otherwise FAIL |
42
|
|
|
|
|
|
|
sub String { |
43
|
17
|
100
|
|
17
|
1
|
2591
|
ref( $_[0] ) and return FAIL; |
44
|
16
|
100
|
100
|
|
|
104
|
$_[1] and length $_[0] > $_[1] and return FAIL; |
45
|
12
|
|
|
|
|
48
|
PASS; |
46
|
|
|
|
|
|
|
} #+ end of: sub String |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
#=--------- |
49
|
|
|
|
|
|
|
# Object |
50
|
|
|
|
|
|
|
#=--------- |
51
|
|
|
|
|
|
|
#* Object type check, Object - just object, or Object(Params::Dry::Types) check if is Params::Dry::Types type |
52
|
|
|
|
|
|
|
#* RETURN: PASS if test pass otherwise FAIL |
53
|
|
|
|
|
|
|
sub Object { |
54
|
4
|
|
|
4
|
1
|
1539
|
my $class = blessed( $_[0] ); |
55
|
4
|
100
|
|
|
|
13
|
return FAIL if !$class; # not an object |
56
|
1
|
50
|
33
|
|
|
6
|
return FAIL if $_[1] and ( $_[1] ne $class ); |
57
|
1
|
|
|
|
|
4
|
PASS; |
58
|
|
|
|
|
|
|
} #+ end of: sub Object |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
#=------ |
61
|
|
|
|
|
|
|
# Ref |
62
|
|
|
|
|
|
|
#=------ |
63
|
|
|
|
|
|
|
#* ref type check |
64
|
|
|
|
|
|
|
#* RETURN: PASS if test pass otherwise FAIL |
65
|
|
|
|
|
|
|
sub Ref { |
66
|
24
|
100
|
|
24
|
1
|
1515
|
my $ref = ref( $_[0] ) or return FAIL; |
67
|
|
|
|
|
|
|
|
68
|
20
|
100
|
100
|
|
|
102
|
return FAIL if $_[1] and $ref ne $_[1]; |
69
|
18
|
|
|
|
|
48
|
PASS; |
70
|
|
|
|
|
|
|
} #+ end of: sub Ref |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#=---------- |
73
|
|
|
|
|
|
|
# Defined |
74
|
|
|
|
|
|
|
#=---------- |
75
|
|
|
|
|
|
|
#* Allows anything what is defined |
76
|
|
|
|
|
|
|
#* RETURN: PASS if defined |
77
|
|
|
|
|
|
|
sub Defined { |
78
|
3
|
100
|
|
3
|
1
|
1186
|
defined $_[0] ? PASS : FAIL; |
79
|
|
|
|
|
|
|
} #+ end of: sub Defined |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#=-------- |
82
|
|
|
|
|
|
|
# Value |
83
|
|
|
|
|
|
|
#=-------- |
84
|
|
|
|
|
|
|
#* Allows anything what is not a reference |
85
|
|
|
|
|
|
|
#* RETURN: PASS if defined |
86
|
|
|
|
|
|
|
sub Value { |
87
|
2
|
100
|
|
2
|
1
|
748
|
$_[0] and ref $_[0] ? FAIL : PASS; |
|
|
50
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} #+ end of: sub Value |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
{ |
91
|
3
|
|
|
3
|
|
17
|
no warnings 'once'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
583
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#+ Number - mapped types |
94
|
|
|
|
|
|
|
*Params::Dry::Types::Int = *Params::Dry::Types::Number::Int; |
95
|
|
|
|
|
|
|
*Params::Dry::Types::Float = *Params::Dry::Types::Number::Float; |
96
|
|
|
|
|
|
|
*Params::Dry::Types::Bool = *Params::Dry::Types::Number::Bool; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
#+ Ref - mapped types |
99
|
|
|
|
|
|
|
*Params::Dry::Types::Scalar = *Params::Dry::Types::Ref::Scalar; |
100
|
|
|
|
|
|
|
*Params::Dry::Types::Array = *Params::Dry::Types::Ref::Array; |
101
|
|
|
|
|
|
|
*Params::Dry::Types::Hash = *Params::Dry::Types::Ref::Hash; |
102
|
|
|
|
|
|
|
*Params::Dry::Types::Code = *Params::Dry::Types::Ref::Code; |
103
|
|
|
|
|
|
|
*Params::Dry::Types::Regexp = *Params::Dry::Types::Ref::Regexp; |
104
|
|
|
|
|
|
|
}; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
}; |
107
|
|
|
|
|
|
|
0115 && 0x4d; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
#+ End of Params::Dry::Types |
110
|
|
|
|
|
|
|
__END__ |