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

filter: Statementstmt 98.1% 52 / 53 Branchbran 83.3% 15 / 18 Conditioncond 63.6% 7 / 11 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 15 / 15 Podpod 33.3% 1 / 3 totaltotal 86.7% 92 / 106 SCAR 27.9
CC
16
Cov
90%
__ANON__
5.8
__ANON__
5.1
create_validator_from_sig
4.0
CRAP 16.2
« blib/lib/Salvation/TC/Meta/Type/Parameterized.pm ↑ Summary blib/lib/Salvation/TC/Parser.pm »
1 package Salvation::TC::Type::HashRef;
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 60 ▶ my ( $class, $value ) = @_;
Subroutine Check: called CC=2 SCAR=6.9
Pod documented
16  
17 60 ▶ ( ref( $value ) eq 'HASH' ) || Salvation::TC::Exception::WrongType -> throw( 'type' => 'HashRef', 'value' => $value );
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq "HASH" or "Salvation::TC::Exception::WrongType"->throw("type", "HashRef", "value", $value) 10 50 60
18 }
19  
20 sub create_validator_from_sig {
21  
22 7 ▶ my ( $class, $signature ) = @_;
Subroutine create_validator_from_sig: called CC=4 SCAR=14.0
Pod undocumented
23  
24 7 my @checks = ();
25  
26 7 foreach my $el ( @$signature ) {
27  
28 9 my ( $param, $type ) = @$el{ 'param', 'type' };
29  
30 9 ▶ die( 'Only named parameters are supported' ) if( $param -> { 'positional' } );
Branch: 1 branch
BranchTrueFalseTotal
if $param->{"positional"} 0 9 9
31  
32 my $wrap = sub {
33  
34 9 ▶ my ( $code ) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.2
35  
36 return sub {
37  
38 18 ▶ my ( @input ) = @_;
Subroutine __ANON__: called CC=5 SCAR=17.5
39  
40 18 eval { $code -> ( @input ) };
41  
42 18 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 3 15 18
43  
44 3 ▶ if( blessed( $@ ) && $@ -> isa( 'Salvation::TC::Exception::WrongType' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($@) and $@->isa('Salvation::TC::Exception::WrongType')) { } 3 0 3
Condition33%1/3
builtin::blessed($@) and $@->isa("Salvation::TC::Exception::WrongType")
!ll&&!rl&&r
003
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
45  
46 Salvation::TC::Exception::WrongType::TC -> throw(
47 type => $@ -> getType(),
48 value => $@ -> getValue(),
49 3 ▶ param_name => $param -> { 'name' },
Branch: 1 branch
BranchTrueFalseTotal
$@->isa('Salvation::TC::Exception::WrongType::TC') ? : 0 3 3
50 ( $@ -> isa( 'Salvation::TC::Exception::WrongType::TC' ) ? (
51 prev => $@ -> getPrev(),
52 ) : () ),
53 );
54  
55 } else {
56  
57 0 die( $@ );
58 }
59 };
60 9 };
61 9 };
62  
63 9 ▶ if( $param -> { 'optional' } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param->{'optional'}) { } 2 7 9
64  
65 push( @checks, $wrap -> ( sub {
66  
67 3 ▶ if( exists $_[ 0 ] -> { $param -> { 'name' } } ) {
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_[0]{$param->{"name"}}) 1 2 3
68  
69 1 $type -> check( $_[ 0 ] -> { $param -> { 'name' } } )
70 }
71  
72 2 } ) );
73  
74 } else {
75  
76 push( @checks, $wrap -> ( sub {
77  
78 15 ▶ exists $_[ 0 ] -> { $param -> { 'name' } } || Salvation::TC::Exception::WrongType
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
exists $_[0]{$param->{"name"}} or "Salvation::TC::Exception::WrongType"->throw("type", $type->name, "value", "(not exists)") 1 14 15
79 -> throw( 'type' => $type -> name(), 'value' => '(not exists)' );
80  
81 14 $type -> check( $_[ 0 ] -> { $param -> { 'name' } } );
82  
83 7 } ) );
84 }
85 }
86  
87 return sub {
88  
89 15 ▶ $_ -> ( $_[ 0 ] ) for @checks;
Subroutine __ANON__: called CC=2 SCAR=6.9
90  
91 12 1;
92 7 };
93 }
94  
95 sub create_length_validator {
96  
97 5 ▶ my ( $class, $min, $max ) = @_;
Subroutine create_length_validator: called CC=1 SCAR=0.0
Pod undocumented
98  
99 return sub {
100  
101 5 ▶ my $len = scalar( keys( %{ $_[ 0 ] } ) );
Subroutine __ANON__: called CC=5 SCAR=16.2
102  
103 5 ▶ if( ( $len < $min ) || ( defined $max && ( $len > $max ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len < $min or defined $max and $len > $max) 2 3 5
Condition66%4/6
$len < $min or defined $max and $len > $max
l!l&&r!l&&!r
203
defined $max and $len > $max
!ll&&!rl&&r
120
MC/DC33%1/3
$len < $min or defined $max and $len > $max
$len < $min defined $max $len > $max
Truth table50%2/4
A or B and C
A= $len < $minB= defined $maxC= $len > $max
ABCresult
1XX1
0111
00X0
0100
104  
105 2 ▶ Salvation::TC::Exception::WrongType -> throw(
Condition100%2/2
$max // ""
l!l
11
MC/DC100%1/1
$max // ""
$max
Truth table100%2/2
A
A= $max
Aresult
11
00
106 'type' => sprintf( 'HashRef{%s,%s}', $min, ( $max // '' ) ),
107 'value' => $_[ 0 ]
108 );
109 }
110  
111 3 1;
112 5 };
113 }
114  
115 4 1;
116  
117 __END__
« blib/lib/Salvation/TC/Meta/Type/Parameterized.pm ↑ Summary blib/lib/Salvation/TC/Parser.pm »