blib/lib/Salvation/TC/Type/ArrayRef.pm

filter: Statementstmt 97.8% 46 / 47 Branchbran 78.5% 11 / 14 Conditioncond 81.8% 9 / 11 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 12 / 12 Podpod 33.3% 1 / 3 totaltotal 88.1% 82 / 93 SCAR 26.5
CC
14
Cov
92%
__ANON__
5.4
__ANON__
5.0
create_validator_from_sig
4.1
CRAP 14.1
« blib/lib/Salvation/TC/Parser.pm ↑ Summary blib/lib/Salvation/TC/Type/Bool.pm »
1 package Salvation::TC::Type::ArrayRef;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use base 'Salvation::TC::Type::Ref';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Salvation::TC::Exception::WrongType ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Salvation::TC::Exception::WrongType::TC ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 sub Check {
14  
15 56 ▶ my ( $class, $value ) = @_;
Subroutine Check: called CC=2 SCAR=6.9
Pod documented
16  
17 56 ▶ ( ref( $value ) eq 'ARRAY' ) || Salvation::TC::Exception::WrongType -> throw( 'type' => 'ArrayRef', 'value' => $value );
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq "ARRAY" or "Salvation::TC::Exception::WrongType"->throw("type", "ArrayRef", "value", $value) 14 42 56
18 }
19  
20 sub create_validator_from_sig {
21  
22 5 ▶ my ( $class, $signature ) = @_;
Subroutine create_validator_from_sig: called CC=4 SCAR=14.1
Pod undocumented
23  
24 5 my @checks = ();
25 5 my $i = 0;
26  
27 5 foreach my $el ( @$signature ) {
28  
29 6 my ( $param, $type ) = @$el{ 'param', 'type' };
30  
31 6 ▶ die( 'Only positional parameters are supported' ) if( $param -> { 'named' } );
Branch: 1 branch
BranchTrueFalseTotal
if $param->{"named"} 0 6 6
32  
33 6 ▶ die( 'Optional parameters are not supported' ) if( $param -> { 'optional' } );
Branch: 1 branch
BranchTrueFalseTotal
if $param->{"optional"} 0 6 6
34  
35 6 my $local_i = $i++;
36  
37 push( @checks, sub {
38  
39 13 ▶ my ( @input ) = @_;
Subroutine __ANON__: called CC=5 SCAR=16.8
40  
41 13 eval { $type -> check( $input[ 0 ] -> [ $local_i ] ) };
42  
43 13 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 4 9 13
44  
45 4 ▶ if( blessed( $@ ) && $@ -> isa( 'Salvation::TC::Exception::WrongType' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($@) and $@->isa('Salvation::TC::Exception::WrongType')) { } 4 0 4
Condition33%1/3
builtin::blessed($@) and $@->isa("Salvation::TC::Exception::WrongType")
!ll&&!rl&&r
004
MC/DC0%0/2
builtin::blessed($@) and $@->isa("Salvation::TC::Exception::WrongType")
builtin::blessed($@) $@->isa("Salvation::TC::Exception::WrongType")
Truth table33%1/3
A and B
A= builtin::blessed($@)B= $@->isa("Salvation::TC::Exception::WrongType")
ABresult
0X0
100
111
46  
47 4 ▶ Salvation::TC::Exception::WrongType::TC -> throw(
Branch: 1 branch
BranchTrueFalseTotal
$@->isa('Salvation::TC::Exception::WrongType::TC') ? : 2 2 4
48 type => $@ -> getType(),
49 value => $@ -> getValue(),
50 param_name => $local_i,
51 ( $@ -> isa( 'Salvation::TC::Exception::WrongType::TC' ) ? (
52 prev => $@ -> getPrev(),
53 ) : () ),
54 );
55  
56 } else {
57  
58 0 die( $@ );
59 }
60 };
61 6 } );
62 }
63  
64 return sub {
65  
66 11 ▶ $_ -> ( $_[ 0 ] ) for @checks;
Subroutine __ANON__: called CC=2 SCAR=6.9
67  
68 7 1;
69 5 };
70 }
71  
72 sub create_length_validator {
73  
74 10 ▶ my ( $class, $min, $max ) = @_;
Subroutine create_length_validator: called CC=1 SCAR=0.0
Pod undocumented
75  
76 return sub {
77  
78 17 ▶ my $len = scalar( @{ $_[ 0 ] } );
Subroutine __ANON__: called CC=5 SCAR=16.1
79  
80 17 ▶ if( ( $len < $min ) || ( defined $max && ( $len > $max ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len < $min or defined $max and $len > $max) 4 13 17
Condition100%6/6
$len < $min or defined $max and $len > $max
l!l&&r!l&&!r
3113
defined $max and $len > $max
!ll&&!rl&&r
1121
MC/DC66%2/3
$len < $min or defined $max and $len > $max
$len < $min defined $max $len > $max
Truth table75%3/4
A or B and C
A= $len < $minB= defined $maxC= $len > $max
ABCresult
1XX1
0111
00X0
0100
81  
82 4 ▶ Salvation::TC::Exception::WrongType -> throw(
Condition100%2/2
$max // ""
l!l
31
MC/DC100%1/1
$max // ""
$max
Truth table100%2/2
A
A= $max
Aresult
11
00
83 'type' => sprintf( 'ArrayRef{%s,%s}', $min, ( $max // '' ) ),
84 'value' => $_[ 0 ]
85 );
86 }
87  
88 13 1;
89 10 };
90 }
91  
92 4 1;
93  
94 __END__
« blib/lib/Salvation/TC/Parser.pm ↑ Summary blib/lib/Salvation/TC/Type/Bool.pm »