| 1 | package Type::Params::Parameter; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 58 | ▶ | use 5.008001; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 58 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 58 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 58 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 0 | ▶ | if ( $] < 5.010 ) { require Devel::TypeTiny::Perl58Compat } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 58 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 58 | $Type::Params::Parameter::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 58 | $Type::Params::Parameter::VERSION = '2.010001'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 58 | $Type::Params::Parameter::VERSION =~ tr/_//d; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 58 | ▶ | use Types::Standard qw( -is -types ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 58 | my $RE_WORDLIKE = qr/\A[^\W0-9]\w*\z/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 58 | my $Attrs = Enum[ qw/ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | name type slurpy default alias strictness coerce clone in_list optional | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | getter predicate allow_dash vartail default_on_undef | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | quux | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | / ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | sub _croak { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_croak: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | require Carp; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | Carp::croak( pop ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 756 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 756 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | my %self = @_ == 1 ? %{$_[0]} : @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 756 | ▶ | $self{alias} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self{"alias"} ||= []
MC/DC100%1/1
$self{"alias"} ||= []
$self{"alias"}
Truth table100%2/2
A
A= $self{"alias"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 756 | ▶ | if ( defined $self{alias} and not ref $self{alias} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self{"alias"} and not ref $self{"alias"}
MC/DC50%1/2
defined $self{"alias"} and not ref $self{"alias"}
defined $self{"alias"}
not ref $self{"alias"}
Truth table66%2/3
A and not(B)
A= defined $self{"alias"}B= not ref $self{"alias"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 13 | $self{alias} = [ $self{alias} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 756 | my $self = bless \%self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 756 | ▶ | $Attrs->all( sort keys %$self ) or do { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | require Carp; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | require Type::Utils; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | my @bad = ( ~ $Attrs )->grep( sort keys %$self ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | Carp::carp( sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | "Warning: unrecognized parameter %s: %s, continuing anyway", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | @bad == 1 ? 'option' : 'options', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | Type::Utils::english_list( @bad ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 756 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 3 | ▶ | sub name { $_[0]{name} } sub has_name { exists $_[0]{name} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_name: called CC=1 SCAR=0.0
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 3 | ▶ | sub type { $_[0]{type} } sub has_type { exists $_[0]{type} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_type: called CC=1 SCAR=0.0
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 22 | ▶ | sub default { $_[0]{default} } sub has_default { exists $_[0]{default} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default: called CC=1 SCAR=0.0
Subroutine
has_default: called CC=1 SCAR=0.0
Pod
documented
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub alias { $_[0]{alias} } sub has_alias { @{ $_[0]{alias} } } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
alias: called CC=1 SCAR=2.6
Subroutine
has_alias: not called CC=1 SCAR=2.6
Pod
documented
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 740 | ▶ | sub strictness { $_[0]{strictness} } sub has_strictness { exists $_[0]{strictness} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_strictness: called CC=1 SCAR=0.0
Subroutine
strictness: called CC=1 SCAR=0.0
Pod
documented
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 907 | ▶ | sub should_clone { $_[0]{clone} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
should_clone: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 22 | ▶ | sub default_on_undef { $_[0]{default_on_undef} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_on_undef: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 20 | ▶ | sub in_list { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
in_list: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 20 | ▶ | return $_[0]{in_list} if exists $_[0]{in_list}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 9 | $_[0]{in_list} = !$_[0]->optional; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 152 | ▶ | sub coerce { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
coerce: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | exists( $_[0]{coerce} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | ? $_[0]{coerce} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 152 | ▶ | : ( $_[0]{coerce} = $_[0]->type->has_coercion ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 2195 | ▶ | sub optional { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
optional: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | exists( $_[0]{optional} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | ? $_[0]{optional} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 2195 | ▶ | : do { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | $_[0]{optional} = $_[0]->has_default || grep( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | $_->{uniq} == Optional->{uniq}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 729 | ▶ | $_[0]->type, $_[0]->type->parents, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_[0]->has_default || grep(($_->{'uniq'} == &Optional()->{'uniq'}), $_[0]->type, $_[0]->type->parents)
MC/DC100%2/2
$_[0]->has_default || grep(($_->{'uniq'} == &Optional()->{'uniq'}), $_[0]->type, $_[0]->type->parents)
$_[0]->has_default
grep(($_->{'uniq'} == &Optional()->{'uniq'}), $_[0]->type, $_[0]->type->parents)
Truth table100%3/3
A || B
A= $_[0]->has_defaultB= grep(($_->{'uniq'} == &Optional()->{'uniq'}), $_[0]->type, $_[0]->type->parents)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 172 | ▶ | sub getter { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getter: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | exists( $_[0]{getter} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | ? $_[0]{getter} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | : ( $_[0]{getter} = $_[0]{name} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 172 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 172 | ▶ | sub predicate { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
predicate: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | exists( $_[0]{predicate} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | ? $_[0]{predicate} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 172 | ▶ | : ( $_[0]{predicate} = ( $_[0]->optional ? 'has_' . $_[0]{name} : undef ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 165 | ▶ | sub might_supply_new_value { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
might_supply_new_value: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 165 | ▶ | $_[0]->has_default or $_[0]->coerce or $_[0]->should_clone; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$_[0]->has_default or $_[0]->coerce
MC/DC100%2/2
$_[0]->has_default or $_[0]->coerce
$_[0]->has_default
$_[0]->coerce
Truth table100%3/3
A or B
A= $_[0]->has_defaultB= $_[0]->coerce
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 557 | ▶ | sub _all_aliases { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_all_aliases: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 557 | my ( $self, $signature ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 557 | my $allow_dash = $self->{allow_dash}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 557 | ▶ | $allow_dash = $signature->allow_dash if !defined $allow_dash; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 557 | my @aliases; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 557 | ▶ | if ( $allow_dash and $self->name =~ $RE_WORDLIKE ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$allow_dash and $self->name =~ /$RE_WORDLIKE/
MC/DC50%1/2
$allow_dash and $self->name =~ /$RE_WORDLIKE/
$allow_dash
$self->name =~ /$RE_WORDLIKE/
Truth table66%2/3
A and B
A= $allow_dashB= $self->name =~ /$RE_WORDLIKE/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 23 | push @aliases, sprintf( '-%s', $self->name ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 557 | for my $name ( @{ $self->alias } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 32 | push @aliases, $name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 32 | ▶ | if ( $allow_dash and $name =~ $RE_WORDLIKE ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$allow_dash and $name =~ /$RE_WORDLIKE/
MC/DC50%1/2
$allow_dash and $name =~ /$RE_WORDLIKE/
$allow_dash
$name =~ /$RE_WORDLIKE/
Truth table66%2/3
A and B
A= $allow_dashB= $name =~ /$RE_WORDLIKE/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 3 | push @aliases, sprintf( '-%s', $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 557 | return @aliases; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 22 | ▶ | sub _code_for_default { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_code_for_default: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 22 | my ( $self, $signature, $coderef ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 22 | my $default = $self->default; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 22 | ▶ | if ( is_CodeRef $default ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | my $default_varname = $coderef->add_variable( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | '$default_for_' . $self->{vartail}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 5 | \$default, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 5 | return sprintf( '%s->( %s )', $default_varname, $signature->method_invocant ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 17 | ▶ | if ( is_Undef $default ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | return 'undef'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 15 | ▶ | if ( is_Str $default ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 9 | return B::perlstring( $default ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 6 | ▶ | if ( is_HashRef $default ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 2 | return '{}'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 4 | ▶ | if ( is_ArrayRef $default ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 2 | return '[]'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 2 | ▶ | if ( is_ScalarRef $default ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | return $$default; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | $self->_croak( 'Default expected to be undef, string, coderef, or empty arrayref/hashref' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 24 | ▶ | sub _maybe_clone { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_maybe_clone: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 24 | my ( $self, $varname ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 24 | ▶ | if ( $self->should_clone ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | return sprintf( 'Storable::dclone( %s )', $varname ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 22 | return $varname; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 740 | ▶ | sub _make_code { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_make_code: called CC=54 SCAR=39.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 740 | my ( $self, %args ) = ( shift, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 740 | ▶ | my $type = $args{type} || 'arg'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'type'} || 'arg'
MC/DC100%1/1
$args{'type'} || 'arg'
$args{'type'}
Truth table100%2/2
A
A= $args{'type'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 740 | my $signature = $args{signature}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 740 | my $coderef = $args{coderef}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 740 | my $varname = $args{input_slot}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 740 | my $index = $args{index}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 740 | my $constraint = $self->type; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 740 | my $is_optional = $self->optional; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | my $really_optional = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | $is_optional | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | && $constraint->parent | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | && $constraint->parent->{uniq} eq Optional->{uniq} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 740 | ▶ | && $constraint->type_parameter; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition88%8/9
$is_optional && $constraint->parent && $constraint->parent->{'uniq'} eq &Optional()->{'uniq'} && $constraint->type_parameter
$is_optional and $constraint->parent and $constraint->parent->{"uniq"} eq &Optional()->{"uniq"}
$is_optional and $constraint->parent
MC/DC75%3/4
$is_optional && $constraint->parent && $constraint->parent->{'uniq'} eq &Optional()->{'uniq'} && $constraint->type_parameter
$is_optional
$constraint->parent
$constraint->parent->{"uniq"} eq &Optional()->{"uniq"}
$constraint->type_parameter
Truth table80%4/5
A and B and C && D
A= $is_optionalB= $constraint->parentC= $constraint->parent->{"uniq"} eq &Optional()->{"uniq"}D= $constraint->type_parameter
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # Allow Optional itself, without any parameter. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | $really_optional = Types::Standard::Any | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 740 | ▶ | if $constraint && $constraint->{uniq} eq Optional->{uniq}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$constraint and $constraint->{"uniq"} eq &Optional()->{"uniq"}
MC/DC50%1/2
$constraint and $constraint->{"uniq"} eq &Optional()->{"uniq"}
$constraint
$constraint->{"uniq"} eq &Optional()->{"uniq"}
Truth table66%2/3
A and B
A= $constraintB= $constraint->{"uniq"} eq &Optional()->{"uniq"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 740 | my $strictness; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 740 | ▶ | if ( $self->has_strictness ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 1 | $strictness = \ $self->strictness; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | elsif ( $signature->has_strictness ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 9 | $strictness = \ $signature->strictness; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 740 | my ( $vartail, $exists_check ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 740 | ▶ | if ( $args{is_named} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 379 | my $bit = $args{key}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 379 | ▶ | $bit =~ s/([_\W])/$1 eq '_' ? '__' : sprintf('_%x', ord($1))/ge; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 379 | $vartail = $type . '_' . $bit; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 379 | $exists_check = sprintf 'exists( %s )', $args{input_slot}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 361 | ▶ | ( my $input_count_varname = $args{input_var} || '' ) =~ s/\@/\$\#/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'input_var'} || ''
MC/DC100%1/1
$args{'input_var'} || ''
$args{'input_var'}
Truth table100%2/2
A
A= $args{'input_var'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 361 | $vartail = $type . '_' . $index; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 361 | $exists_check = sprintf '%s >= %d', $input_count_varname, $index; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 740 | my $block_needs_ending = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 740 | my $needs_clone = $self->should_clone; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 740 | my $in_big_optional_block = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 740 | ▶ | if ( $needs_clone and not $signature->{loaded_Storable} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$needs_clone and not $signature->{"loaded_Storable"}
MC/DC50%1/2
$needs_clone and not $signature->{"loaded_Storable"}
$needs_clone
not $signature->{"loaded_Storable"}
Truth table66%2/3
A and not(B)
A= $needs_cloneB= not $signature->{"loaded_Storable"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 2 | $coderef->add_line( 'use Storable ();' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 2 | $coderef->add_gap; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 2 | $signature->{loaded_Storable} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | $coderef->add_line( sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | '# Parameter %s (type: %s)', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | $self->name || $args{input_slot}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 740 | ▶ | $constraint->display_name, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->name || $args{'input_slot'}
MC/DC0%0/2
$self->name || $args{'input_slot'}
$self->name
$args{'input_slot'}
Truth table66%2/3
A || B
A= $self->nameB= $args{'input_slot'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 740 | ▶ | if ( $args{is_named} and my @aliases = $self->_all_aliases($signature) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$args{"is_named"} and my(@aliases) = $self->_all_aliases($signature)
MC/DC100%2/2
$args{"is_named"} and my(@aliases) = $self->_all_aliases($signature)
$args{"is_named"}
my(@aliases) = $self->_all_aliases($signature)
Truth table100%3/3
A and B
A= $args{"is_named"}B= my(@aliases) = $self->_all_aliases($signature)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 22 | $coderef->add_line( sprintf( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 'for my $alias ( %s ) {', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | join( q{, }, map B::perlstring($_), @aliases ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 22 | $coderef->increase_indent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 22 | $coderef->add_line( 'exists $in{$alias} or next;' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 22 | $coderef->add_line( sprintf( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 'if ( %s ) {', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | $exists_check, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 22 | $coderef->increase_indent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | $coderef->add_line( sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | '%s;', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | $signature->_make_general_fail( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | coderef => $coderef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 22 | ▶ | message => q{sprintf( 'Superfluous alias "%s" for argument "%s"', $alias, } . B::perlstring( $self->name || $args{input_slot} ) . q{ )}, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->name || $args{'input_slot'}
MC/DC0%0/2
$self->name || $args{'input_slot'}
$self->name
$args{'input_slot'}
Truth table33%1/3
A || B
A= $self->nameB= $args{'input_slot'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 22 | $coderef->decrease_indent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 22 | $coderef->add_line( '}' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 22 | $coderef->add_line( 'else {' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 22 | $coderef->increase_indent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 22 | $coderef->add_line( sprintf( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | '%s = delete( $in{$alias} );', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | $varname, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 22 | $coderef->decrease_indent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 22 | $coderef->add_line( '}' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 22 | $coderef->decrease_indent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 22 | $coderef->add_line( '}' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 740 | ▶ | if ( $args{is_named} and $signature->list_to_named and $self->in_list ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$args{"is_named"} and $signature->list_to_named and $self->in_list
$args{"is_named"} and $signature->list_to_named
MC/DC100%3/3
$args{"is_named"} and $signature->list_to_named and $self->in_list
$args{"is_named"}
$signature->list_to_named
$self->in_list
Truth table100%4/4
A and B and C
A= $args{"is_named"}B= $signature->list_to_namedC= $self->in_list
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 9 | $coderef->addf( 'if ( not exists %s ) {', $varname ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 9 | $coderef->increase_indent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 9 | $coderef->addf( 'for my $ix ( 0 .. $#positional ) {' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 9 | $coderef->increase_indent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 9 | ▶ | $coderef->addf( '%s or next;', ( $really_optional or $constraint )->coercibles->inline_check( '$positional[$ix]' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$really_optional || $constraint
MC/DC0%0/2
$really_optional || $constraint
$really_optional
$constraint
Truth table33%1/3
A || B
A= $really_optionalB= $constraint
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 9 | $coderef->addf( '( %s ) = splice( @positional, $ix, 1 );', $varname ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 9 | $coderef->addf( 'last;' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 9 | $coderef->decrease_indent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 9 | $coderef->addf( '}' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 9 | $coderef->decrease_indent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 9 | $coderef->addf( '}' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 740 | ▶ | if ( $self->has_default ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 22 | my $check = $exists_check; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 22 | ▶ | if ( $self->default_on_undef ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 2 | $check = "( $check and defined $varname )"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 22 | $self->{vartail} = $vartail; # hack | |||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 22 | $coderef->add_line( sprintf( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | '$dtmp = %s ? %s : %s;', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | $check, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | $self->_maybe_clone( $varname ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | $self->_code_for_default( $signature, $coderef ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 21 | $varname = '$dtmp'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 21 | $needs_clone = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | elsif ( $self->optional ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 104 | ▶ | if ( $args{is_named} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 85 | $coderef->add_line( sprintf( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 'if ( %s ) {', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | $exists_check, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 85 | $coderef->{indent} .= "\t"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 85 | ++$block_needs_ending; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 85 | ++$in_big_optional_block; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 19 | $coderef->add_line( sprintf( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | "%s\n\tor %s;", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | $exists_check, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | $signature->_make_return_expression( is_early => 1 ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | elsif ( $args{is_named} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 286 | $coderef->add_line( sprintf( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | "%s\n\tor %s;", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | $exists_check, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | $signature->_make_general_fail( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | coderef => $coderef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | message => "'Missing required parameter: $args{key}'", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 739 | ▶ | if ( $needs_clone ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 2 | $coderef->add_line( sprintf( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | '$dtmp = %s;', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | $self->_maybe_clone( $varname ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 2 | $varname = '$dtmp'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 2 | $needs_clone = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 739 | ▶ | if ( $constraint->has_coercion and $constraint->coercion->can_be_inlined ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$constraint->has_coercion and $constraint->coercion->can_be_inlined
MC/DC100%2/2
$constraint->has_coercion and $constraint->coercion->can_be_inlined
$constraint->has_coercion
$constraint->coercion->can_be_inlined
Truth table100%3/3
A and B
A= $constraint->has_coercionB= $constraint->coercion->can_be_inlined
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 84 | ▶ | $coderef->add_line( sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | '$tmp%s = %s;', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | ( $is_optional ? '{x}' : '' ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | $constraint->coercion->inline_coercion( $varname ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 84 | ▶ | $varname = '$tmp' . ( $is_optional ? '{x}' : '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | elsif ( $constraint->has_coercion ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 83 | my $coercion_varname = $coderef->add_variable( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | '$coercion_for_' . $vartail, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | \ $constraint->coercion->compiled_coercion, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 83 | ▶ | $coderef->add_line( sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | '$tmp%s = &%s( %s );', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | ( $is_optional ? '{x}' : '' ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | $coercion_varname, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | $varname, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 83 | ▶ | $varname = '$tmp' . ( $is_optional ? '{x}' : '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 739 | undef $Type::Tiny::ALL_TYPES{ $constraint->{uniq} }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 739 | $Type::Tiny::ALL_TYPES{ $constraint->{uniq} } = $constraint; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 739 | my $strictness_test = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 739 | ▶ | if ( $strictness and $$strictness eq 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$strictness and $$strictness eq 1
MC/DC100%2/2
$strictness and $$strictness eq 1
$strictness
$$strictness eq 1
Truth table100%3/3
A and B
A= $strictnessB= $$strictness eq 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 3 | $strictness_test = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | ▶ | elsif ( $strictness and $$strictness ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$strictness and $$strictness
MC/DC100%2/2
$strictness and $$strictness
$strictness
$$strictness
Truth table100%3/3
A and B
A= $strictnessB= $$strictness
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 5 | $strictness_test = sprintf "( not %s )\n\tor ", $$strictness; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 739 | ▶ | if ( $strictness and not $$strictness ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition100%3/3
$strictness and not $$strictness
MC/DC100%2/2
$strictness and not $$strictness
$strictness
not $$strictness
Truth table100%3/3
A and not(B)
A= $strictnessB= not $$strictness
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 2 | $coderef->add_line( '1; # ... nothing to do' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | elsif ( $constraint->{uniq} == Any->{uniq} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 13 | $coderef->add_line( '1; # ... nothing to do' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | ▶ | elsif ( $args{is_slurpy} and $self->_dont_validate_slurpy ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$args{"is_slurpy"} and $self->_dont_validate_slurpy
MC/DC100%2/2
$args{"is_slurpy"} and $self->_dont_validate_slurpy
$args{"is_slurpy"}
$self->_dont_validate_slurpy
Truth table100%3/3
A and B
A= $args{"is_slurpy"}B= $self->_dont_validate_slurpy
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 3 | $coderef->add_line( '1; # ... nothing to do' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | elsif ( $constraint->can_be_inlined ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | $coderef->add_line( $strictness_test . sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | "%s\n\tor %s;", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | ( $really_optional or $constraint )->inline_check( $varname ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | $signature->_make_constraint_fail( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | coderef => $coderef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | parameter => $self, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | constraint => $constraint, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | varname => $varname, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | display_var => $args{display_var}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 660 | ▶ | ), | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$really_optional || $constraint
MC/DC0%0/2
$really_optional || $constraint
$really_optional
$constraint
Truth table66%2/3
A || B
A= $really_optionalB= $constraint
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 61 | ▶ | my $compiled_check_varname = $coderef->add_variable( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$really_optional || $constraint
MC/DC0%0/2
$really_optional || $constraint
$really_optional
$constraint
Truth table66%2/3
A || B
A= $really_optionalB= $constraint
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | '$check_for_' . $vartail, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | \ ( ( $really_optional or $constraint )->compiled_check ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | $coderef->add_line( $strictness_test . sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | "&%s( %s )\n\tor %s;", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | $compiled_check_varname, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | $varname, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | $signature->_make_constraint_fail( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | coderef => $coderef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | parameter => $self, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | constraint => $constraint, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | varname => $varname, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | display_var => $args{display_var}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 61 | ), | |||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 739 | ▶ | if ( $args{output_var} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | $coderef->add_line( sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 'push( %s, %s );', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | $args{output_var}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 110 | $varname, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | ▶ | elsif ( $args{output_slot} and $args{output_slot} ne $varname ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$args{"output_slot"} and $args{"output_slot"} ne $varname
MC/DC100%2/2
$args{"output_slot"} and $args{"output_slot"} ne $varname
$args{"output_slot"}
$args{"output_slot"} ne $varname
Truth table100%3/3
A and B
A= $args{"output_slot"}B= $args{"output_slot"} ne $varname
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 419 | ▶ | if ( !$in_big_optional_block and $varname =~ /\{/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $in_big_optional_block and $varname =~ /\{/
MC/DC100%2/2
not $in_big_optional_block and $varname =~ /\{/
not $in_big_optional_block
$varname =~ /\{/
Truth table100%3/3
not(A) and B
A= not $in_big_optional_blockB= $varname =~ /\{/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | $coderef->add_line( sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | '%s = %s if exists( %s );', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | $args{output_slot}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 226 | $varname, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | $varname, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | $coderef->add_line( sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | '%s = %s;', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | $args{output_slot}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 193 | $varname, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 739 | ▶ | if ( $args{is_named} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | $coderef->add_line( sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 'delete( %s );', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | $args{input_slot}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 379 | ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 739 | ▶ | if ( $block_needs_ending ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 85 | $coderef->{indent} =~ s/\s$//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 85 | $coderef->add_line( '}' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 739 | $coderef->add_gap; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 739 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | # This list can be reused safely. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 58 | my @uniqs; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | # If $SLURPY is one of a handful of very loose type constraints, there is | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | # no need to validate it because we built it as a hashref or arrayref ourself, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | # so there's no way it couldn't be a hashref or arrayref. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 70 | ▶ | sub _dont_validate_slurpy { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dont_validate_slurpy: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 70 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 70 | ▶ | my $type = $self->type or return 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 70 | ▶ | if ( not @uniqs ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 20 | @uniqs = map { $_->{uniq} } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | Slurpy, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | Slurpy[Any], Any, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | Slurpy[Item], Item, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | Slurpy[Ref], Ref, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | Slurpy[HashRef], HashRef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | Slurpy[ArrayRef], ArrayRef; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 70 | ▶ | ( $_ == $type->{uniq} and return 1 ) for @uniqs; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 67 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 58 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||