line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Salvation::TC::Type::HashRef; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
1472
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
110
|
|
4
|
4
|
|
|
4
|
|
15
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
85
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
12
|
use base 'Salvation::TC::Type::Ref'; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
234
|
|
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
18
|
use Scalar::Util 'blessed'; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
189
|
|
9
|
4
|
|
|
4
|
|
15
|
use Salvation::TC::Exception::WrongType (); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
37
|
|
10
|
4
|
|
|
4
|
|
13
|
use Salvation::TC::Exception::WrongType::TC (); |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
1644
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub Check { |
14
|
|
|
|
|
|
|
|
15
|
60
|
|
|
60
|
1
|
60
|
my ( $class, $value ) = @_; |
16
|
|
|
|
|
|
|
|
17
|
60
|
100
|
|
|
|
229
|
( ref( $value ) eq 'HASH' ) || Salvation::TC::Exception::WrongType -> throw( 'type' => 'HashRef', 'value' => $value ); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub create_validator_from_sig { |
21
|
|
|
|
|
|
|
|
22
|
7
|
|
|
7
|
0
|
7
|
my ( $class, $signature ) = @_; |
23
|
|
|
|
|
|
|
|
24
|
7
|
|
|
|
|
7
|
my @checks = (); |
25
|
|
|
|
|
|
|
|
26
|
7
|
|
|
|
|
14
|
foreach my $el ( @$signature ) { |
27
|
|
|
|
|
|
|
|
28
|
9
|
|
|
|
|
13
|
my ( $param, $type ) = @$el{ 'param', 'type' }; |
29
|
|
|
|
|
|
|
|
30
|
9
|
50
|
|
|
|
18
|
die( 'Only named parameters are supported' ) if( $param -> { 'positional' } ); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $wrap = sub { |
33
|
|
|
|
|
|
|
|
34
|
9
|
|
|
9
|
|
9
|
my ( $code ) = @_; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
return sub { |
37
|
|
|
|
|
|
|
|
38
|
18
|
|
|
|
|
20
|
my ( @input ) = @_; |
39
|
|
|
|
|
|
|
|
40
|
18
|
|
|
|
|
18
|
eval { $code -> ( @input ) }; |
|
18
|
|
|
|
|
24
|
|
41
|
|
|
|
|
|
|
|
42
|
18
|
100
|
|
|
|
48
|
if( $@ ) { |
43
|
|
|
|
|
|
|
|
44
|
3
|
50
|
33
|
|
|
26
|
if( blessed( $@ ) && $@ -> isa( 'Salvation::TC::Exception::WrongType' ) ) { |
45
|
|
|
|
|
|
|
|
46
|
3
|
50
|
|
|
|
13
|
Salvation::TC::Exception::WrongType::TC -> throw( |
47
|
|
|
|
|
|
|
type => $@ -> getType(), |
48
|
|
|
|
|
|
|
value => $@ -> getValue(), |
49
|
|
|
|
|
|
|
param_name => $param -> { 'name' }, |
50
|
|
|
|
|
|
|
( $@ -> isa( 'Salvation::TC::Exception::WrongType::TC' ) ? ( |
51
|
|
|
|
|
|
|
prev => $@ -> getPrev(), |
52
|
|
|
|
|
|
|
) : () ), |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
} else { |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
0
|
die( $@ ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
}; |
60
|
9
|
|
|
|
|
29
|
}; |
61
|
9
|
|
|
|
|
32
|
}; |
62
|
|
|
|
|
|
|
|
63
|
9
|
100
|
|
|
|
17
|
if( $param -> { 'optional' } ) { |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
push( @checks, $wrap -> ( sub { |
66
|
|
|
|
|
|
|
|
67
|
3
|
100
|
|
3
|
|
7
|
if( exists $_[ 0 ] -> { $param -> { 'name' } } ) { |
68
|
|
|
|
|
|
|
|
69
|
1
|
|
|
|
|
3
|
$type -> check( $_[ 0 ] -> { $param -> { 'name' } } ) |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
2
|
|
|
|
|
12
|
} ) ); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
} else { |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
push( @checks, $wrap -> ( sub { |
77
|
|
|
|
|
|
|
|
78
|
15
|
100
|
|
15
|
|
31
|
exists $_[ 0 ] -> { $param -> { 'name' } } || Salvation::TC::Exception::WrongType |
79
|
|
|
|
|
|
|
-> throw( 'type' => $type -> name(), 'value' => '(not exists)' ); |
80
|
|
|
|
|
|
|
|
81
|
14
|
|
|
|
|
31
|
$type -> check( $_[ 0 ] -> { $param -> { 'name' } } ); |
82
|
|
|
|
|
|
|
|
83
|
7
|
|
|
|
|
18
|
} ) ); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
return sub { |
88
|
|
|
|
|
|
|
|
89
|
15
|
|
|
15
|
|
30
|
$_ -> ( $_[ 0 ] ) for @checks; |
90
|
|
|
|
|
|
|
|
91
|
12
|
|
|
|
|
24
|
1; |
92
|
7
|
|
|
|
|
26
|
}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub create_length_validator { |
96
|
|
|
|
|
|
|
|
97
|
5
|
|
|
5
|
0
|
9
|
my ( $class, $min, $max ) = @_; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
return sub { |
100
|
|
|
|
|
|
|
|
101
|
5
|
|
|
5
|
|
4
|
my $len = scalar( keys( %{ $_[ 0 ] } ) ); |
|
5
|
|
|
|
|
9
|
|
102
|
|
|
|
|
|
|
|
103
|
5
|
100
|
66
|
|
|
21
|
if( ( $len < $min ) || ( defined $max && ( $len > $max ) ) ) { |
|
|
|
66
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
2
|
|
100
|
|
|
13
|
Salvation::TC::Exception::WrongType -> throw( |
106
|
|
|
|
|
|
|
'type' => sprintf( 'HashRef{%s,%s}', $min, ( $max // '' ) ), |
107
|
|
|
|
|
|
|
'value' => $_[ 0 ] |
108
|
|
|
|
|
|
|
); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
3
|
|
|
|
|
5
|
1; |
112
|
5
|
|
|
|
|
18
|
}; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
__END__ |