| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
ref $caller or $caller eq "-lexical" or $globals->{"lexical"}
ref $caller or $caller eq "-lexical"
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
@_ and Types::TypeTiny::is_TypeTiny($_[-1]) and $_[-1]->is_strictly_a_type_of($_Slurpy)
@_ and Types::TypeTiny::is_TypeTiny($_[-1])
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | my @known = map { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 38 | my $known; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 69 | ▶ | $known = Type::Tiny::XS::is_known( $_->compiled_check ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | unless $_->is_strictly_a_type_of( $_Optional ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 69 | ▶ | defined( $known ) ? $known : (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } @constraints; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 38 | ▶ | if ( @known == @constraints ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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'
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'
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 56 | ▶ | my $slurp_any = $slurpy && $slurpy->my_unslurpy->equals( Types::Standard::Any ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$slurpy && $slurpy->my_unslurpy->equals(&Types::Standard::Any())
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())
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 56 | my @sorted_is_optional = sort @is_optional; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 56 | ▶ | join( "|", @sorted_is_optional ) eq join( "|", @is_optional ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 45 | ▶ | return !!0 unless $slurpy; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 37 | my $tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 37 | ▶ | if ( $slurp_hash ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 11 | ▶ | ( $#$value - $#constraints + 1 ) % 2 or return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 6 | $tmp = +{ @$value[ $#constraints + 1 .. $#$value ] }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 6 | ▶ | $slurpy->check( $tmp ) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | elsif ( not $slurp_any ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 26 | $tmp = +[ @$value[ $#constraints + 1 .. $#$value ] ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 26 | ▶ | $slurpy->check( $tmp ) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } #/ if ( $#constraints < $#$value) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 93 | for my $i ( 0 .. $#constraints ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 198 | ▶ | ( $i > $#$value ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | and return !!$is_optional[$i]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 180 | ▶ | $constraints[$i]->check( $value->[$i] ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition83%5/6
@_ and Types::TypeTiny::is_TypeTiny($_[-1]) and $_[-1]->is_strictly_a_type_of($_Slurpy)
@_ and Types::TypeTiny::is_TypeTiny($_[-1])
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 52 | ▶ | return if defined $slurpy && !$slurpy->can_be_inlined; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $slurpy and not $slurpy->can_be_inlined
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 51 | my $xsubname; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 51 | ▶ | if ( Type::Tiny::_USE_XS and !$slurpy ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | my @known = map { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 34 | my $known; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 60 | ▶ | $known = Type::Tiny::XS::is_known( $_->compiled_check ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | unless $_->is_strictly_a_type_of( $_Optional ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 60 | ▶ | defined( $known ) ? $known : (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } @constraints; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 34 | ▶ | if ( @known == @constraints ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 17 | ▶ | $tmpl = | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$xsubname and not $Type::Tiny::AvoidCallbacks
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
scalar @constraints == $min and not $slurpy
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 613 | ▶ | $inline eq '(!!1)' ? () | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%3/6
@constraints and Types::TypeTiny::is_TypeTiny($constraints[-1]) and $constraints[-1]->is_strictly_a_type_of($_Slurpy)
@constraints and Types::TypeTiny::is_TypeTiny($constraints[-1])
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
@constraints < @$value and not $slurpy
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$constraints[$i]->is_strictly_a_type_of(&Types::Standard::Optional()) and $i > $value->$#*
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->$#*
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | ->is_strictly_a_type_of( Types::Standard::Optional ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | && $i > $#$value; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 2 | ▶ | next if $constraints[$i]->check( $value->[$i] ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 1 | ▶ | my $tmp = | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
$slurpy->my_unslurpy || $slurpy
$slurpy->my_unslurpy || $slurpy
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
Truth table33%1/3
A || B
A= $slurpy->my_unslurpyB= $slurpy
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%3/6
@tuple and Types::TypeTiny::is_TypeTiny($tuple[-1]) and $tuple[-1]->is_strictly_a_type_of($_Slurpy)
@tuple and Types::TypeTiny::is_TypeTiny($tuple[-1])
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 29 | ▶ | $all_inlinable = 0 if !$tc->can_be_inlined; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 29 | ▶ | $all_inlinable = 0 if $tc->has_coercion && !$tc->coercion->can_be_inlined; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$tc->has_coercion and not $tc->coercion->can_be_inlined
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 29 | ▶ | $child_coercions_exist++ if $tc->has_coercion; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 15 | ▶ | return unless $child_coercions_exist; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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'
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'
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 10 | ▶ | if ( $all_inlinable ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 1 | my $size = @tuple; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 1 | push @code, sprintf( 'if (@$orig > %d) {', $size ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 1 | ▶ | push @code, sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 6 | ▶ | if ( !$slurpy and @$value > @tuple ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $slurpy and @$value > @tuple
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$i > $value->$#* and $is_optional[$i]
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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 8 | my $ct = $tuple[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 8 | ▶ | my $x = $ct->has_coercion ? $ct->coerce( $value->[$i] ) : $value->[$i]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 8 | ▶ | return $value unless $ct->check( $x ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 8 | $new[$i] = $x; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } #/ for my $i ( 0 .. $#tuple) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 4 | ▶ | if ( $slurpy and @$value > @tuple ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$slurpy and @$value > @tuple
MC/DC50%1/2
$slurpy and @$value > @tuple
$slurpy
@$value > @tuple
Truth table66%2/3
A and B
A= $slurpyB= @$value > @tuple
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 3 | ▶ | $tmp = $slurpy->coerce( $tmp ) if $slurpy->has_coercion; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 3 | ▶ | $slurpy->check( $tmp ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||||||