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