lib/Types/Standard/Tuple.pm

filter: Statementstmt 100% 184 / 185 (1 uncoverable) Branchbran 85.0% 119 / 140 Conditioncond 70.8% 51 / 72 MC/DCmcdc 55.8% 24 / 43 Subroutinesub 100% 21 / 21 Podpod n/a totaltotal 86.7% 399 / 461 (1 uncoverable) CC 101 SCAR 25.2
CC
101
Cov
89%
__deep_explanation
21.3
__ANON__
16.0
__inline_generator
14.0
CRAP 12.4
« blib/lib/Types/TypeTiny.pm ↑ Summary blib/lib/Type/Tiny.pm »
1 # INTERNAL MODULE: guts for Tuple type from Types::Standard.
2  
3 package Types::Standard::Tuple;
4  
5 15 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 15 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 $Types::Standard::Tuple::AUTHORITY = 'cpan:TOBYINK';
11 15 $Types::Standard::Tuple::VERSION = '2.010001';
12 }
13  
14 15 $Types::Standard::Tuple::VERSION =~ tr/_//d;
15  
16 15 ▶use Type::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 15 ▶use Types::Standard ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 15 ▶use Types::TypeTiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 ▶sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak }
Subroutine _croak: called CC=1 SCAR=0.0
21  
22 15 my $_Optional = Types::Standard::Optional;
23 15 my $_Slurpy = Types::Standard::Slurpy;
24  
25 15 ▶use Exporter::Tiny 1.004001 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
26 15 our @ISA = qw( Exporter::Tiny );
27  
28 2 ▶sub _exporter_fail {
Subroutine _exporter_fail: called CC=8 SCAR=21.7
29 2 my ( $class, $type_name, $values, $globals ) = @_;
30 2 my $caller = $globals->{into};
31
32 2 my @final;
33 {
34 2 ▶ my $to_type = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
35 4 ▶ return $_[0] if Types::TypeTiny::is_TypeTiny($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if Types::TypeTiny::is_TypeTiny($_[0]) 2 2 4
36 2 require Type::Utils;
37 2 Type::Utils::dwim_type( $_[0], for => 'caller' );
38 2 };
39 2 my $of = $values->{of};
40 2 ▶ Types::TypeTiny::is_ArrayLike($of)
Branch: 1 branch
BranchTrueFalseTotal
Types::TypeTiny::is_ArrayLike($of) or &_croak(qq[Expected arrayref option "of" for type "$type_name"]) 2 0 2
41 or _croak( qq{Expected arrayref option "of" for type "$type_name"} );
42 2 @final = map { $to_type->($_) } @$of;
43 }
44
45 2 my $type = Types::Standard::Tuple->of( @final );
46 $type = $type->create_child_type(
47 name => $type_name,
48 $type->has_coercion ? ( coercion => 1 ) : (),
49 2 ▶ exists( $values->{where} ) ? ( constraint => $values->{where} ) : (),
Branch: 2 branches
BranchTrueFalseTotal
$type->has_coercion ? : 0 2 2
exists $values->{'where'} ? : 0 2 2
50 );
51
52 $INC{'Type/Registry.pm'}
53 ? 'Type::Registry'->for_class( $caller )->add_type( $type, $type_name )
54 : ( $Type::Registry::DELAYED{$caller}{$type_name} = $type )
55 2 ▶ unless( ref($caller) or $caller eq '-lexical' or $globals->{'lexical'} );
Branch: 2 branches
BranchTrueFalseTotal
unless ref $caller or $caller eq "-lexical" or $globals->{"lexical"} 2 0 2
$INC{'Type/Registry.pm'} ? : 1 1 2
Condition33%2/6
ref $caller or $caller eq "-lexical" or $globals->{"lexical"}
l!l&&r!l&&!r
002
ref $caller or $caller eq "-lexical"
l!l&&r!l&&!r
002
MC/DC0%0/3
ref $caller or $caller eq "-lexical" or $globals->{"lexical"}
ref $caller $caller eq "-lexical" $globals->{"lexical"}
Truth table25%1/4
A or B or C
A= ref $callerB= $caller eq "-lexical"C= $globals->{"lexical"}
ABCresult
1XX1
01X1
0011
0000
56 2 return map +( $_->{name} => $_->{code} ), @{ $type->exportables };
57 }
58  
59 15 ▶no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
60  
61 57 ▶sub __constraint_generator {
Subroutine __constraint_generator: called CC=14 SCAR=26.4
62 57 ▶ my $slurpy =
Branch: 1 branch
BranchTrueFalseTotal
@_ && Types::TypeTiny::is_TypeTiny($_[-1]) && $_[-1]->is_strictly_a_type_of($_Slurpy) ? : 18 39 57
Condition100%6/6
@_ and Types::TypeTiny::is_TypeTiny($_[-1]) and $_[-1]->is_strictly_a_type_of($_Slurpy)
!ll&&!rl&&r
33618
@_ and Types::TypeTiny::is_TypeTiny($_[-1])
!ll&&!rl&&r
2154
MC/DC100%3/3
@_ and Types::TypeTiny::is_TypeTiny($_[-1]) and $_[-1]->is_strictly_a_type_of($_Slurpy)
@_ Types::TypeTiny::is_TypeTiny($_[-1]) $_[-1]->is_strictly_a_type_of($_Slurpy)
Truth table100%4/4
A and B and C
A= @_B= Types::TypeTiny::is_TypeTiny($_[-1])C= $_[-1]->is_strictly_a_type_of($_Slurpy)
ABCresult
0XX0
10X0
1100
1111
63 @_
64 && Types::TypeTiny::is_TypeTiny( $_[-1] )
65 && $_[-1]->is_strictly_a_type_of( $_Slurpy )
66 ? pop
67 : undef;
68
69 57 my @constraints = @_;
70 57 for ( @constraints ) {
71 99 ▶ Types::TypeTiny::is_TypeTiny( $_ )
Branch: 1 branch
BranchTrueFalseTotal
Types::TypeTiny::is_TypeTiny($_) or &_croak("Parameters to Tuple[...] expected to be type constraints; got $_") 98 1 99
72 or
73 _croak( "Parameters to Tuple[...] expected to be type constraints; got $_" );
74 }
75
76 # By god, the Type::Tiny::XS API is currently horrible
77 56 my @xsub;
78 56 ▶ if ( Type::Tiny::_USE_XS and !$slurpy ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($slurpy) 38 18 56
79 my @known = map {
80 38 my $known;
81 69 ▶ $known = Type::Tiny::XS::is_known( $_->compiled_check )
Branch: 1 branch
BranchTrueFalseTotal
unless $_->is_strictly_a_type_of($_Optional) 62 7 69
82 unless $_->is_strictly_a_type_of( $_Optional );
83 69 ▶ defined( $known ) ? $known : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $known ? : 53 16 69
84 } @constraints;
85
86 38 ▶ if ( @known == @constraints ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@known == @constraints) 25 13 38
87 25 my $xsub = Type::Tiny::XS::get_coderef_for(
88 sprintf( "Tuple[%s]", join( ',', @known ) ) );
89 25 ▶ push @xsub, $xsub if $xsub;
Branch: 1 branch
BranchTrueFalseTotal
if $xsub 23 2 25
90 }
91 } #/ if ( Type::Tiny::_USE_XS...)
92
93 56 my @is_optional = map !!$_->is_strictly_a_type_of( $_Optional ), @constraints;
94 56 ▶ my $slurp_hash = $slurpy && $slurpy->my_slurp_into eq 'HASH';
Condition100%3/3
$slurpy && $slurpy->my_slurp_into eq 'HASH'
!ll&&!rl&&r
38117
MC/DC100%2/2
$slurpy && $slurpy->my_slurp_into eq 'HASH'
$slurpy $slurpy->my_slurp_into eq 'HASH'
Truth table100%3/3
A && B
A= $slurpyB= $slurpy->my_slurp_into eq 'HASH'
ABresult
0X0
100
111
95 56 ▶ my $slurp_any = $slurpy && $slurpy->my_unslurpy->equals( Types::Standard::Any );
Condition66%2/3
$slurpy && $slurpy->my_unslurpy->equals(&Types::Standard::Any())
!ll&&!rl&&r
38180
MC/DC0%0/2
$slurpy && $slurpy->my_unslurpy->equals(&Types::Standard::Any())
$slurpy $slurpy->my_unslurpy->equals(&Types::Standard::Any())
Truth table66%2/3
A && B
A= $slurpyB= $slurpy->my_unslurpy->equals(&Types::Standard::Any())
ABresult
0X0
100
111
96
97 56 my @sorted_is_optional = sort @is_optional;
98 56 ▶ join( "|", @sorted_is_optional ) eq join( "|", @is_optional )
Branch: 1 branch
BranchTrueFalseTotal
join("|", @sorted_is_optional) eq join("|", @is_optional) or &_croak("Optional parameters to Tuple[...] cannot precede required parameters") 55 1 56
99 or _croak(
100 "Optional parameters to Tuple[...] cannot precede required parameters" );
101
102 123 ▶ sub {
Subroutine __ANON__: called CC=11 SCAR=24.0
103 123 my $value = $_[0];
104 123 ▶ if ( $#constraints < $#$value ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#constraints < $value->$#*) 45 78 123
105 45 ▶ return !!0 unless $slurpy;
Branch: 1 branch
BranchTrueFalseTotal
unless $slurpy 8 37 45
106 37 my $tmp;
107 37 ▶ if ( $slurp_hash ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($slurp_hash) { } 11 26 37
elsif (not $slurp_any) { } 26 0 26
108 11 ▶ ( $#$value - $#constraints + 1 ) % 2 or return;
Branch: 1 branch
BranchTrueFalseTotal
($value->$#* - $#constraints + 1) % 2 or return 6 5 11
109 6 $tmp = +{ @$value[ $#constraints + 1 .. $#$value ] };
110 6 ▶ $slurpy->check( $tmp ) or return;
Branch: 1 branch
BranchTrueFalseTotal
$slurpy->check($tmp) or return 4 2 6
111 }
112 elsif ( not $slurp_any ) {
113 26 $tmp = +[ @$value[ $#constraints + 1 .. $#$value ] ];
114 26 ▶ $slurpy->check( $tmp ) or return;
Branch: 1 branch
BranchTrueFalseTotal
$slurpy->check($tmp) or return 11 15 26
115 }
116 } #/ if ( $#constraints < $#$value)
117 93 for my $i ( 0 .. $#constraints ) {
118 198 ▶ ( $i > $#$value )
Branch: 1 branch
BranchTrueFalseTotal
$i > $value->$#* and return !!$is_optional[$i] 18 180 198
119 and return !!$is_optional[$i];
120
121 180 ▶ $constraints[$i]->check( $value->[$i] )
Branch: 1 branch
BranchTrueFalseTotal
$constraints[$i]->check($value->[$i]) or 163 17 180
122 or return !!0;
123 }
124 58 return !!1;
125 55 }, @xsub;
126 } #/ sub __constraint_generator
127  
128 55 ▶sub __inline_generator {
Subroutine __inline_generator: called CC=14 SCAR=26.4
129 55 ▶ my $slurpy =
Branch: 1 branch
BranchTrueFalseTotal
@_ && Types::TypeTiny::is_TypeTiny($_[-1]) && $_[-1]->is_strictly_a_type_of($_Slurpy) ? : 18 37 55
Condition83%5/6
@_ and Types::TypeTiny::is_TypeTiny($_[-1]) and $_[-1]->is_strictly_a_type_of($_Slurpy)
!ll&&!rl&&r
23518
@_ and Types::TypeTiny::is_TypeTiny($_[-1])
!ll&&!rl&&r
2053
MC/DC66%2/3
@_ and Types::TypeTiny::is_TypeTiny($_[-1]) and $_[-1]->is_strictly_a_type_of($_Slurpy)
@_ Types::TypeTiny::is_TypeTiny($_[-1]) $_[-1]->is_strictly_a_type_of($_Slurpy)
Truth table75%3/4
A and B and C
A= @_B= Types::TypeTiny::is_TypeTiny($_[-1])C= $_[-1]->is_strictly_a_type_of($_Slurpy)
ABCresult
0XX0
10X0
1100
1111
130 @_
131 && Types::TypeTiny::is_TypeTiny( $_[-1] )
132 && $_[-1]->is_strictly_a_type_of( $_Slurpy )
133 ? pop
134 : undef;
135 55 my @constraints = @_;
136
137 55 ▶ return if grep { not $_->can_be_inlined } @constraints;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not $_->can_be_inlined;} @constraints 3 52 55
138 52 ▶ return if defined $slurpy && !$slurpy->can_be_inlined;
Branch: 1 branch
BranchTrueFalseTotal
if defined $slurpy and not $slurpy->can_be_inlined 1 51 52
Condition100%3/3
defined $slurpy and not $slurpy->can_be_inlined
!ll&&!rl&&r
34171
MC/DC100%2/2
defined $slurpy and not $slurpy->can_be_inlined
defined $slurpy not $slurpy->can_be_inlined
Truth table100%3/3
A and not(B)
A= defined $slurpyB= not $slurpy->can_be_inlined
ABresult
0X0
100
111
139
140 51 my $xsubname;
141 51 ▶ if ( Type::Tiny::_USE_XS and !$slurpy ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($slurpy) 34 17 51
142 my @known = map {
143 34 my $known;
144 60 ▶ $known = Type::Tiny::XS::is_known( $_->compiled_check )
Branch: 1 branch
BranchTrueFalseTotal
unless $_->is_strictly_a_type_of($_Optional) 54 6 60
145 unless $_->is_strictly_a_type_of( $_Optional );
146 60 ▶ defined( $known ) ? $known : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $known ? : 48 12 60
147 } @constraints;
148
149 34 ▶ if ( @known == @constraints ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@known == @constraints) 25 9 34
150 25 $xsubname = Type::Tiny::XS::get_subname_for(
151 sprintf( "Tuple[%s]", join( ',', @known ) ) );
152 }
153 } #/ if ( Type::Tiny::_USE_XS...)
154
155 51 my $tmpl = "do { my \$tmp = +[\@{%s}[%d..\$#{%s}]]; %s }";
156 51 my $slurpy_any;
157 51 ▶ if ( defined $slurpy ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $slurpy) 17 34 51
158 17 ▶ $tmpl =
Branch: 1 branch
BranchTrueFalseTotal
if $slurpy->my_slurp_into eq "HASH" 7 10 17
159 'do { my ($orig, $from, $to) = (%s, %d, $#{%s});'
160 . '(($to-$from) %% 2) and do { my $tmp = +{@{$orig}[$from..$to]}; %s }'
161 . '}'
162 if $slurpy->my_slurp_into eq 'HASH';
163 17 ▶ $slurpy_any = 1
Branch: 1 branch
BranchTrueFalseTotal
if $slurpy->my_unslurpy->equals(&Types::Standard::Any()) 0 17 17
164 if $slurpy->my_unslurpy->equals( Types::Standard::Any );
165 }
166
167 51 my @is_optional = map !!$_->is_strictly_a_type_of( $_Optional ), @constraints;
168 51 my $min = 0+ grep !$_, @is_optional;
169
170 428 ▶ return sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
171 428 my $v = $_[1];
172 428 ▶ return "$xsubname\($v\)" if $xsubname && !$Type::Tiny::AvoidCallbacks;
Branch: 1 branch
BranchTrueFalseTotal
if $xsubname and not $Type::Tiny::AvoidCallbacks 160 268 428
Condition100%3/3
$xsubname and not $Type::Tiny::AvoidCallbacks
!ll&&!rl&&r
21058160
MC/DC100%2/2
$xsubname and not $Type::Tiny::AvoidCallbacks
$xsubname not $Type::Tiny::AvoidCallbacks
Truth table100%3/3
A and not(B)
A= $xsubnameB= not $Type::Tiny::AvoidCallbacks
ABresult
0X0
100
111
173 join " and ",
174 Types::Standard::ArrayRef->inline_check( $v ),
175 (
176 ( scalar @constraints == $min and not $slurpy )
177 ? "\@{$v} == $min"
178 : sprintf(
179 165 ▶ "(\@{$v} == $min or (\@{$v} > $min and \@{$v} <= ${\(1+$#constraints)}) or (\@{$v} > ${\(1+$#constraints)} and %s))",
Branch: 2 branches
BranchTrueFalseTotal
$slurpy_any ? : 0 165 165
$slurpy ? : 125 40 165
180 (
181 $slurpy_any ? '!!1'
182 : (
183 $slurpy
184 ? sprintf( $tmpl, $v, $#constraints + 1, $v, $slurpy->inline_check( '$tmp' ) )
185 : sprintf( "\@{$v} <= %d", scalar @constraints )
186 )
187 ),
188 )
189 ),
190 map {
191 268 ▶ my $inline = $constraints[$_]->inline_check( "$v\->[$_]" );
Branch: 1 branch
BranchTrueFalseTotal
scalar @constraints == $min && !$slurpy ? : 103 165 268
Condition100%3/3
scalar @constraints == $min and not $slurpy
!ll&&!rl&&r
10857103
MC/DC100%2/2
scalar @constraints == $min and not $slurpy
scalar @constraints == $min not $slurpy
Truth table100%3/3
A and not(B)
A= scalar @constraints == $minB= not $slurpy
ABresult
0X0
100
111
192 613 ▶ $inline eq '(!!1)' ? ()
Branch: 2 branches
BranchTrueFalseTotal
$inline eq '(!!1)' ? : 16 597 613
$is_optional[$_] ? : 121 476 597
193 : (
194 $is_optional[$_] ? sprintf( '(@{%s} <= %d or %s)', $v, $_, $inline )
195 : $inline
196 );
197 } 0 .. $#constraints;
198 51 };
199 } #/ sub __inline_generator
200  
201 4 ▶sub __deep_explanation {
Subroutine __deep_explanation: called CC=16 SCAR=30.6
202 4 my ( $type, $value, $varname ) = @_;
203
204 4 my @constraints = @{ $type->parameters };
205 4 ▶ my $slurpy =
Branch: 1 branch
BranchTrueFalseTotal
@constraints && Types::TypeTiny::is_TypeTiny($constraints[-1]) && $constraints[-1]->is_strictly_a_type_of($_Slurpy) ? : 2 2 4
Condition50%3/6
@constraints and Types::TypeTiny::is_TypeTiny($constraints[-1]) and $constraints[-1]->is_strictly_a_type_of($_Slurpy)
!ll&&!rl&&r
022
@constraints and Types::TypeTiny::is_TypeTiny($constraints[-1])
!ll&&!rl&&r
004
MC/DC33%1/3
@constraints and Types::TypeTiny::is_TypeTiny($constraints[-1]) and $constraints[-1]->is_strictly_a_type_of($_Slurpy)
@constraints Types::TypeTiny::is_TypeTiny($constraints[-1]) $constraints[-1]->is_strictly_a_type_of($_Slurpy)
Truth table50%2/4
A and B and C
A= @constraintsB= Types::TypeTiny::is_TypeTiny($constraints[-1])C= $constraints[-1]->is_strictly_a_type_of($_Slurpy)
ABCresult
0XX0
10X0
1100
1111
206 @constraints
207 && Types::TypeTiny::is_TypeTiny( $constraints[-1] )
208 && $constraints[-1]->is_strictly_a_type_of( $_Slurpy )
209 ? pop( @constraints )
210 : undef;
211 4 @constraints = map Types::TypeTiny::to_TypeTiny( $_ ), @constraints;
212
213 4 ▶ if ( @constraints < @$value and not $slurpy ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@constraints < @$value and not $slurpy) 2 2 4
Condition100%3/3
@constraints < @$value and not $slurpy
!ll&&!rl&&r
112
MC/DC100%2/2
@constraints < @$value and not $slurpy
@constraints < @$value not $slurpy
Truth table100%3/3
A and not(B)
A= @constraints < @$valueB= not $slurpy
ABresult
0X0
100
111
214 return [
215 2 sprintf(
216 '"%s" expects at most %d values in the array', $type, scalar( @constraints )
217 ),
218 sprintf( '%d values found; too many', scalar( @$value ) ),
219 ];
220 }
221
222 2 for my $i ( 0 .. $#constraints ) {
223 next
224 2 ▶ if $constraints[$i]
Branch: 1 branch
BranchTrueFalseTotal
if $constraints[$i]->is_strictly_a_type_of(&Types::Standard::Optional()) and $i > $value->$#* 0 2 2
Condition33%1/3
$constraints[$i]->is_strictly_a_type_of(&Types::Standard::Optional()) and $i > $value->$#*
!ll&&!rl&&r
200
MC/DC0%0/2
$constraints[$i]->is_strictly_a_type_of(&Types::Standard::Optional()) and $i > $value->$#*
$constraints[$i]->is_strictly_a_type_of(&Types::Standard::Optional()) $i > $value->$#*
Truth table33%1/3
A and B
A= $constraints[$i]->is_strictly_a_type_of(&Types::Standard::Optional())B= $i > $value->$#*
ABresult
0X0
100
111
225 ->is_strictly_a_type_of( Types::Standard::Optional )
226 && $i > $#$value;
227 2 ▶ next if $constraints[$i]->check( $value->[$i] );
Branch: 1 branch
BranchTrueFalseTotal
if $constraints[$i]->check($value->[$i]) 1 1 2
228
229 return [
230 sprintf(
231 '"%s" constrains value at index %d of array with "%s"', $type, $i,
232 $constraints[$i]
233 ),
234 @{
235 1 $constraints[$i]
236 ->validate_explain( $value->[$i], sprintf( '%s->[%s]', $varname, $i ) )
237 },
238 ];
239 } #/ for my $i ( 0 .. $#constraints)
240
241 1 ▶ if ( defined( $slurpy ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $slurpy) 1 0 1
242 1 ▶ my $tmp =
Branch: 1 branch
BranchTrueFalseTotal
$slurpy->my_slurp_into eq 'HASH' ? : 1 0 1
243 $slurpy->my_slurp_into eq 'HASH'
244 ? +{ @$value[ $#constraints + 1 .. $#$value ] }
245 : +[ @$value[ $#constraints + 1 .. $#$value ] ];
246 $slurpy->check( $tmp )
247 or return [
248 sprintf(
249 'Array elements from index %d are slurped into a %s which is constrained with "%s"',
250 $#constraints + 1,
251 ( $slurpy->my_slurp_into eq 'HASH' ) ? 'hashref' : 'arrayref',
252 ( $slurpy->my_unslurpy || $slurpy ),
253 ),
254 1 ▶ @{ ( $slurpy->my_unslurpy || $slurpy )->validate_explain( $tmp, '$SLURPY' ) },
Branch: 2 branches
BranchTrueFalseTotal
$slurpy->check($tmp) or return [sprintf("Array elements from index %d are slurped into a %s which is constrained with \"%s\"", $#constraints + 1, $slurpy->my_slurp_into eq "HASH" ? "hashref" : "arrayref", $slurpy->my_unslurpy || $slurpy), @{($slurpy->my_unslurpy || $slurpy)->validate_explain($tmp, "\$SLURPY");}] 0 1 1
$slurpy->my_slurp_into eq 'HASH' ? : 1 0 1
Condition33%2/6
$slurpy->my_unslurpy || $slurpy
l!l&&r!l&&!r
100
$slurpy->my_unslurpy || $slurpy
l!l&&r!l&&!r
100
MC/DC0%0/2
$slurpy->my_unslurpy || $slurpy
$slurpy->my_unslurpy $slurpy
MC/DC0%0/2
$slurpy->my_unslurpy || $slurpy
$slurpy->my_unslurpy $slurpy
Truth table33%1/3
A || B
A= $slurpy->my_unslurpyB= $slurpy
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $slurpy->my_unslurpyB= $slurpy
ABresult
1X1
011
000
255 ];
256 } #/ if ( defined( $slurpy ...))
257
258 # This should never happen...
259 0 return; # uncoverable statement
260 } #/ sub __deep_explanation
261  
262 15 my $label_counter = 0;
263  
264 15 ▶sub __coercion_generator {
Subroutine __coercion_generator: called CC=13 SCAR=25.9
265 15 my ( $parent, $child, @tuple ) = @_;
266
267 15 ▶ my $slurpy =
Branch: 1 branch
BranchTrueFalseTotal
@tuple && Types::TypeTiny::is_TypeTiny($tuple[-1]) && $tuple[-1]->is_strictly_a_type_of($_Slurpy) ? : 4 11 15
Condition50%3/6
@tuple and Types::TypeTiny::is_TypeTiny($tuple[-1]) and $tuple[-1]->is_strictly_a_type_of($_Slurpy)
!ll&&!rl&&r
0114
@tuple and Types::TypeTiny::is_TypeTiny($tuple[-1])
!ll&&!rl&&r
0015
MC/DC33%1/3
@tuple and Types::TypeTiny::is_TypeTiny($tuple[-1]) and $tuple[-1]->is_strictly_a_type_of($_Slurpy)
@tuple Types::TypeTiny::is_TypeTiny($tuple[-1]) $tuple[-1]->is_strictly_a_type_of($_Slurpy)
Truth table50%2/4
A and B and C
A= @tupleB= Types::TypeTiny::is_TypeTiny($tuple[-1])C= $tuple[-1]->is_strictly_a_type_of($_Slurpy)
ABCresult
0XX0
10X0
1100
1111
268 @tuple
269 && Types::TypeTiny::is_TypeTiny( $tuple[-1] )
270 && $tuple[-1]->is_strictly_a_type_of( $_Slurpy )
271 ? pop( @tuple )
272 : undef;
273
274 15 my $child_coercions_exist = 0;
275 15 my $all_inlinable = 1;
276 15 ▶ for my $tc ( @tuple, ( $slurpy ? $slurpy : () ) ) {
Branch: 1 branch
BranchTrueFalseTotal
$slurpy ? : 4 11 15
277 29 ▶ $all_inlinable = 0 if !$tc->can_be_inlined;
Branch: 1 branch
BranchTrueFalseTotal
unless $tc->can_be_inlined 1 28 29
278 29 ▶ $all_inlinable = 0 if $tc->has_coercion && !$tc->coercion->can_be_inlined;
Branch: 1 branch
BranchTrueFalseTotal
if $tc->has_coercion and not $tc->coercion->can_be_inlined 12 17 29
Condition100%3/3
$tc->has_coercion and not $tc->coercion->can_be_inlined
!ll&&!rl&&r
11612
MC/DC100%2/2
$tc->has_coercion and not $tc->coercion->can_be_inlined
$tc->has_coercion not $tc->coercion->can_be_inlined
Truth table100%3/3
A and not(B)
A= $tc->has_coercionB= not $tc->coercion->can_be_inlined
ABresult
0X0
100
111
279 29 ▶ $child_coercions_exist++ if $tc->has_coercion;
Branch: 1 branch
BranchTrueFalseTotal
if $tc->has_coercion 18 11 29
280 }
281
282 15 ▶ return unless $child_coercions_exist;
Branch: 1 branch
BranchTrueFalseTotal
unless $child_coercions_exist 5 10 15
283 10 my $C = "Type::Coercion"->new( type_constraint => $child );
284
285 10 ▶ my $slurpy_is_hashref = $slurpy && $slurpy->my_slurp_into eq 'HASH';
Condition100%3/3
$slurpy && $slurpy->my_slurp_into eq 'HASH'
!ll&&!rl&&r
622
MC/DC100%2/2
$slurpy && $slurpy->my_slurp_into eq 'HASH'
$slurpy $slurpy->my_slurp_into eq 'HASH'
Truth table100%3/3
A && B
A= $slurpyB= $slurpy->my_slurp_into eq 'HASH'
ABresult
0X0
100
111
286
287 10 ▶ if ( $all_inlinable ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($all_inlinable) { } 4 6 10
288 $C->add_type_coercions(
289 3 ▶ $parent => Types::Standard::Stringable {
Subroutine __ANON__: called CC=8 SCAR=20.9
290 3 my $label = sprintf( "TUPLELABEL%d", ++$label_counter );
291 3 my @code;
292 3 push @code, 'do { my ($orig, $return_orig, $tmp, @new) = ($_, 0);';
293 3 push @code, "$label: {";
294 3 ▶ push @code,
Branch: 1 branch
BranchTrueFalseTotal
unless $slurpy 2 1 3
295 sprintf(
296 '(($return_orig = 1), last %s) if @$orig > %d;', $label,
297 scalar @tuple
298 ) unless $slurpy;
299 3 for my $i ( 0 .. $#tuple ) {
300 4 my $ct = $tuple[$i];
301 4 my $ct_coerce = $ct->has_coercion;
302 4 my $ct_optional = $ct->is_a_type_of( Types::Standard::Optional );
303
304 4 ▶ push @code, sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$ct_coerce ? : 4 0 4
305 'if (@$orig > %d) { $tmp = %s; (%s) ? ($new[%d]=$tmp) : (($return_orig=1), last %s) }',
306 $i,
307 $ct_coerce
308 ? $ct->coercion->inline_coercion( "\$orig->[$i]" )
309 : "\$orig->[$i]",
310 $ct->inline_check( '$tmp' ),
311 $i,
312 $label,
313 );
314 } #/ for my $i ( 0 .. $#tuple)
315 3 ▶ if ( $slurpy ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($slurpy) 1 2 3
316 1 my $size = @tuple;
317 1 push @code, sprintf( 'if (@$orig > %d) {', $size );
318 1 ▶ push @code, sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$slurpy_is_hashref ? : 0 1 1
319 (
320 $slurpy_is_hashref
321 ? 'my $tail = do { no warnings; +{ @{$orig}[%d .. $#$orig]} };'
322 : 'my $tail = [ @{$orig}[%d .. $#$orig] ];'
323 ),
324 $size,
325 );
326 1 ▶ push @code,
Branch: 1 branch
BranchTrueFalseTotal
$slurpy->has_coercion ? : 1 0 1
327 $slurpy->has_coercion
328 ? sprintf(
329 '$tail = %s;',
330 $slurpy->coercion->inline_coercion( '$tail' )
331 )
332 : q();
333 1 ▶ push @code, sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$slurpy_is_hashref ? : 0 1 1
334 '(%s) ? push(@new, %s$tail) : ($return_orig++);',
335 $slurpy->inline_check( '$tail' ),
336 ( $slurpy_is_hashref ? '%' : '@' ),
337 );
338 1 push @code, '}';
339 } #/ if ( $slurpy )
340 3 push @code, '}';
341 3 push @code, '$return_orig ? $orig : \\@new';
342 3 push @code, '}';
343 3 "@code";
344 }
345 4 );
346 } #/ if ( $all_inlinable )
347
348 else {
349 6 my @is_optional = map !!$_->is_strictly_a_type_of( $_Optional ), @tuple;
350
351 $C->add_type_coercions(
352 6 ▶ $parent => sub {
Subroutine __ANON__: called CC=15 SCAR=27.7
353 6 ▶ my $value = @_ ? $_[0] : $_;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 6 0 6
354
355 6 ▶ if ( !$slurpy and @$value > @tuple ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $slurpy and @$value > @tuple) 2 4 6
Condition100%3/3
not $slurpy and @$value > @tuple
!ll&&!rl&&r
312
MC/DC100%2/2
not $slurpy and @$value > @tuple
not $slurpy @$value > @tuple
Truth table100%3/3
not(A) and B
A= not $slurpyB= @$value > @tuple
ABresult
0X0
100
111
356 2 return $value;
357 }
358
359 4 my @new;
360 4 for my $i ( 0 .. $#tuple ) {
361 8 ▶ return \@new if $i > $#$value and $is_optional[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $i > $value->$#* and $is_optional[$i] 0 8 8
Condition33%1/3
$i > $value->$#* and $is_optional[$i]
!ll&&!rl&&r
800
MC/DC0%0/2
$i > $value->$#* and $is_optional[$i]
$i > $value->$#* $is_optional[$i]
Truth table33%1/3
A and B
A= $i > $value->$#*B= $is_optional[$i]
ABresult
0X0
100
111
362
363 8 my $ct = $tuple[$i];
364 8 ▶ my $x = $ct->has_coercion ? $ct->coerce( $value->[$i] ) : $value->[$i];
Branch: 1 branch
BranchTrueFalseTotal
$ct->has_coercion ? : 7 1 8
365
366 8 ▶ return $value unless $ct->check( $x );
Branch: 1 branch
BranchTrueFalseTotal
unless $ct->check($x) 0 8 8
367
368 8 $new[$i] = $x;
369 } #/ for my $i ( 0 .. $#tuple)
370
371 4 ▶ if ( $slurpy and @$value > @tuple ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($slurpy and @$value > @tuple) 3 1 4
Condition66%2/3
$slurpy and @$value > @tuple
!ll&&!rl&&r
103
MC/DC50%1/2
$slurpy and @$value > @tuple
$slurpy @$value > @tuple
Truth table66%2/3
A and B
A= $slurpyB= @$value > @tuple
ABresult
0X0
100
111
372 15 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
373 my $tmp =
374 $slurpy_is_hashref
375 2 ? { @{$value}[ @tuple .. $#$value ] }
376 3 ▶ : [ @{$value}[ @tuple .. $#$value ] ];
Branch: 1 branch
BranchTrueFalseTotal
$slurpy_is_hashref ? : 2 1 3
377 3 ▶ $tmp = $slurpy->coerce( $tmp ) if $slurpy->has_coercion;
Branch: 1 branch
BranchTrueFalseTotal
if $slurpy->has_coercion 3 0 3
378 3 ▶ $slurpy->check( $tmp )
Branch: 2 branches
BranchTrueFalseTotal
$slurpy->check($tmp) ? : 3 0 3
$slurpy_is_hashref ? : 2 1 3
379 ? push( @new, $slurpy_is_hashref ? %$tmp : @$tmp )
380 : return ( $value );
381 } #/ if ( $slurpy and @$value...)
382
383 4 return \@new;
384 },
385 6 );
386 } #/ else [ if ( $all_inlinable ) ]
387
388 10 return $C;
389 } #/ sub __coercion_generator
390  
391 15 1;
392  
393 __END__
« blib/lib/Types/TypeTiny.pm ↑ Summary blib/lib/Type/Tiny.pm »