blib/lib/Type/Params/Signature.pm

filter: Statementstmt 97.0% 595 / 613 Branchbran 85.0% 272 / 320 Conditioncond 70.3% 128 / 182 MC/DCmcdc 49.5% 53 / 107 Subroutinesub 97.7% 88 / 90 Podpod 91.1% 41 / 45 totaltotal 86.7% 1177 / 1357 CC 252 SCAR 22.4
CC
252
Cov
89%
make_extra_methods
26.3
_coderef_check_count
26.0
_rationalize_slurpies
20.0
CRAP 9.4
« blib/lib/Type/Library.pm ↑ Summary blib/lib/Type/Coercion.pm »
1 package Type::Params::Signature;
2  
3 67 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 67 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 67 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 67 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.2
8 67 ▶ if ( $] < 5.010 ) { require Devel::TypeTiny::Perl58Compat }
Branch: 1 branch
BranchTrueFalseTotal
if ($] < "5.01") 0 58 58
9 }
10  
11 67 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 67 $Type::Params::Signature::AUTHORITY = 'cpan:TOBYINK';
13 67 $Type::Params::Signature::VERSION = '2.010001';
14 }
15  
16 60 $Type::Params::Signature::VERSION =~ tr/_//d;
17  
18 67 ▶use B ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 65 ▶use Eval::TypeTiny::CodeAccumulator;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 65 ▶use Types::Standard qw( -is -types -assert );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 65 ▶use Types::TypeTiny qw( -is -types to_TypeTiny );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 65 ▶use Type::Params::Parameter;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 63 my $Attrs = Enum[ qw/
25 caller_level package subname description _is_signature_for ID
26 method head tail parameters slurpy
27 message on_die next fallback strictness is_named allow_dash method_invocant
28 bless class constructor named_to_list list_to_named oo_trace
29 class_prefix class_attributes
30 returns_scalar returns_list
31 want_details want_object want_source can_shortcut coderef
32 quux mite_signature is_wrapper
33 / ]; # quux for reasons
34  
35 18 ▶sub _croak {
Subroutine _croak: called CC=1 SCAR=0.0
36 18 require Error::TypeTiny;
37 18 return Error::TypeTiny::croak( pop );
38 }
39  
40 761 ▶sub _new_parameter {
Subroutine _new_parameter: called CC=1 SCAR=0.0
41 761 shift;
42 761 'Type::Params::Parameter'->new( @_ );
43 }
44  
45 392 ▶sub _new_code_accumulator {
Subroutine _new_code_accumulator: called CC=1 SCAR=0.0
46 392 shift;
47 392 'Eval::TypeTiny::CodeAccumulator'->new( @_ );
48 }
49  
50 322 ▶sub new {
Subroutine new: called CC=8 SCAR=21.2
Pod documented
51 322 my $class = shift;
52 322 ▶ my %self = @_ == 1 ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 317 317
53 322 my $self = bless \%self, $class;
54 322 ▶ $self->{parameters} ||= [];
Condition50%1/2
$self->{"parameters"} ||= []
l!l
3170
MC/DC0%0/1
$self->{"parameters"} ||= []
$self->{"parameters"}
Truth table50%1/2
A
A= $self->{"parameters"}
Aresult
11
00
55 322 ▶ $self->{class_prefix} ||= 'Type::Params::OO::Klass';
Condition50%1/2
$self->{"class_prefix"} ||= "Type::Params::OO::Klass"
l!l
0317
MC/DC0%0/1
$self->{"class_prefix"} ||= "Type::Params::OO::Klass"
$self->{"class_prefix"}
Truth table50%1/2
A
A= $self->{"class_prefix"}
Aresult
11
00
56 322 ▶ $self->{next} ||= delete $self->{goto_next} if exists $self->{goto_next};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"goto_next"} 4 313 317
Condition33%1/3
$self->{"next"} ||= delete $self->{"goto_next"}
l!l&&r!l&&!r
040
MC/DC0%0/2
$self->{"next"} ||= delete $self->{"goto_next"}
$self->{"next"} delete $self->{"goto_next"}
Truth table33%1/3
A ||= B
A= $self->{"next"}B= delete $self->{"goto_next"}
ABresult
1X1
011
000
57 322 $self->BUILD;
58 315 ▶ $Attrs->all( sort keys %$self ) or do {
Branch: 1 branch
BranchTrueFalseTotal
$Attrs->all(sort(keys %$self)) or do { require Carp; require Type::Utils; my(@bad) = (~$Attrs)->grep(sort(keys %$self)); Carp::carp(sprintf("Warning: unrecognized signature %s: %s, continuing anyway", @bad == 1 ? "option" : "options", Type::Utils::english_list(@bad))) } 307 3 310
59 6 require Carp;
60 6 require Type::Utils;
61 6 my @bad = ( ~ $Attrs )->grep( sort keys %$self );
62 6 ▶ Carp::carp( sprintf(
Branch: 1 branch
BranchTrueFalseTotal
@bad == 1 ? : 1 2 3
63 "Warning: unrecognized signature %s: %s, continuing anyway",
64 @bad == 1 ? 'option' : 'options',
65 Type::Utils::english_list( @bad ),
66 ) );
67 };
68 313 return $self;
69 }
70  
71 {
72 62 my $klass_id;
73 62 my %klass_cache;
74 320 ▶ sub BUILD {
Subroutine BUILD: called CC=16 SCAR=27.9
Pod documented
75 320 my $self = shift;
76  
77 320 ▶ if ( $self->{named_to_list} and not is_ArrayRef $self->{named_to_list} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"named_to_list"} and not is_ArrayRef($self->{"named_to_list"})) 12 305 317
Condition100%3/3
$self->{"named_to_list"} and not is_ArrayRef($self->{"named_to_list"})
!ll&&!rl&&r
303212
MC/DC100%2/2
$self->{"named_to_list"} and not is_ArrayRef($self->{"named_to_list"})
$self->{"named_to_list"} not is_ArrayRef($self->{"named_to_list"})
Truth table100%3/3
A and not(B)
A= $self->{"named_to_list"}B= not is_ArrayRef($self->{"named_to_list"})
ABresult
0X0
100
111
78 15 $self->{named_to_list} = [ map $_->name, @{ $self->{parameters} } ];
79 }
80  
81 320 ▶ if ( delete $self->{rationalize_slurpies} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $self->{"rationalize_slurpies"}) 317 0 317
82 320 $self->_rationalize_slurpies;
83 }
84  
85 315 ▶ if ( $self->{method} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"method"}) 26 286 312
86 29 my $type = $self->{method};
87 $type =
88 is_Int($type) ? Defined :
89 29 ▶ is_Str($type) ? do { require Type::Utils; Type::Utils::dwim_type( $type, $self->{package} ? ( for => $self->{package} ) : () ) } :
Branch: 3 branches
BranchTrueFalseTotal
is_Int($type) ? : 23 3 26
is_Str($type) ? : 0 3 3
$self->{'package'} ? : 0 0 0
90 to_TypeTiny( $type );
91 29 ▶ unshift @{ $self->{head} ||= [] }, $self->_new_parameter(
Condition50%1/2
$self->{"head"} ||= []
l!l
026
MC/DC0%0/1
$self->{"head"} ||= []
$self->{"head"}
Truth table50%1/2
A
A= $self->{"head"}
Aresult
11
00
92 name => 'invocant',
93 type => $type,
94 );
95 }
96  
97 315 $self->_rationalize_returns;
98  
99 315 ▶ if ( defined $self->{bless} and is_BoolLike $self->{bless} and $self->{bless} and not $self->{named_to_list} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"bless"} and is_BoolLike($self->{"bless"}) and $self->{"bless"} and not $self->{"named_to_list"}) 43 269 312
Condition100%9/9
defined $self->{"bless"} and is_BoolLike($self->{"bless"}) and $self->{"bless"} and not $self->{"named_to_list"}
!ll&&!rl&&r
2581143
defined $self->{"bless"} and is_BoolLike($self->{"bless"}) and $self->{"bless"}
!ll&&!rl&&r
15210654
defined $self->{"bless"} and is_BoolLike($self->{"bless"})
!ll&&!rl&&r
1448160
MC/DC100%4/4
defined $self->{"bless"} and is_BoolLike($self->{"bless"}) and $self->{"bless"} and not $self->{"named_to_list"}
defined $self->{"bless"} is_BoolLike($self->{"bless"}) $self->{"bless"} not $self->{"named_to_list"}
Truth table100%5/5
A and B and C and not(D)
A= defined $self->{"bless"}B= is_BoolLike($self->{"bless"})C= $self->{"bless"}D= not $self->{"named_to_list"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
100 46 my $klass_key = $self->_klass_key;
101 46 ▶ $self->{bless} = ( $klass_cache{$klass_key} ||= sprintf( '%s%d', $self->{class_prefix}, ++$klass_id ) );
Condition66%2/3
$klass_cache{$klass_key} ||= sprintf("%s%d", $self->{"class_prefix"}, ++$klass_id)
l!l&&r!l&&!r
23200
MC/DC0%0/2
$klass_cache{$klass_key} ||= sprintf("%s%d", $self->{"class_prefix"}, ++$klass_id)
$klass_cache{$klass_key} sprintf("%s%d", $self->{"class_prefix"}, ++$klass_id)
Truth table66%2/3
A ||= B
A= $klass_cache{$klass_key}B= sprintf("%s%d", $self->{"class_prefix"}, ++$klass_id)
ABresult
1X1
011
000
102 46 ▶ $self->{oo_trace} = 1 unless exists $self->{oo_trace};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"oo_trace"} 40 3 43
103 46 $self->make_class;
104 }
105 313 ▶ if ( is_ArrayRef $self->{class} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_ArrayRef($self->{"class"})) 8 302 310
106 11 $self->{constructor} = $self->{class}->[1];
107 11 $self->{class} = $self->{class}->[0];
108 }
109 }
110 }
111  
112 63 ▶sub _klass_key {
Subroutine _klass_key: called CC=2 SCAR=6.9
113 46 my $self = shift;
114  
115 46 my @parameters = @{ $self->parameters };
116 45 ▶ if ( $self->has_slurpy ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_slurpy) 1 42 43
117 3 push @parameters, $self->slurpy;
118 }
119  
120 65 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
121 join(
122 '|',
123 map sprintf( '%s*%s*%s', $_->name, $_->getter, $_->predicate ),
124 45 sort { $a->{name} cmp $b->{name} } @parameters
125 );
126 }
127  
128 320 ▶sub _rationalize_slurpies {
Subroutine _rationalize_slurpies: called CC=20 SCAR=30.0
129 319 my $self = shift;
130  
131 319 my $parameters = $self->parameters;
132  
133 319 ▶ if ( $self->is_named ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->is_named) { } 171 146 317
elsif (@$parameters) { } 143 3 146
134 173 my ( @slurpy, @rest );
135  
136 173 for my $parameter ( @$parameters ) {
137 412 ▶ if ( $parameter->type->is_strictly_a_type_of( Slurpy ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($parameter->type->is_strictly_a_type_of(&Slurpy())) { } 26 384 410
elsif ($parameter->{'slurpy'}) { } 1 383 384
138 28 push @slurpy, $parameter;
139 }
140 elsif ( $parameter->{slurpy} ) {
141 3 $parameter->{type} = Slurpy[ $parameter->type ];
142 3 push @slurpy, $parameter;
143 }
144 else {
145 385 push @rest, $parameter;
146 }
147 }
148  
149 173 ▶ if ( @slurpy == 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@slurpy == 1) { } 25 146 171
elsif (@slurpy) { } 1 145 146
150 25 my $constraint = $slurpy[0]->type;
151 25 ▶ if ( $constraint->type_parameter && $constraint->type_parameter->{uniq} == Any->{uniq} or $constraint->my_slurp_into eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($constraint->type_parameter and $constraint->type_parameter->{'uniq'} == &Any()->{'uniq'} or $constraint->my_slurp_into eq 'HASH') { } 24 1 25
Condition83%5/6
$constraint->type_parameter and $constraint->type_parameter->{"uniq"} == &Any()->{"uniq"} or $constraint->my_slurp_into eq "HASH"
l!l&&r!l&&!r
1231
$constraint->type_parameter and $constraint->type_parameter->{"uniq"} == &Any()->{"uniq"}
!ll&&!rl&&r
0241
MC/DC66%2/3
$constraint->type_parameter and $constraint->type_parameter->{"uniq"} == &Any()->{"uniq"} or $constraint->my_slurp_into eq "HASH"
$constraint->type_parameter $constraint->type_parameter->{"uniq"} == &Any()->{"uniq"} $constraint->my_slurp_into eq "HASH"
Truth table60%3/5
A and B or C
A= $constraint->type_parameterB= $constraint->type_parameter->{"uniq"} == &Any()->{"uniq"}C= $constraint->my_slurp_into eq "HASH"
ABCresult
11X1
0X11
1011
0X00
1000
152 24 $self->{slurpy} = $slurpy[0];
153 24 @$parameters = @rest;
154 }
155 else {
156 1 $self->_croak( 'Signatures with named parameters can only have slurpy parameters which are a subtype of HashRef' );
157 }
158 }
159 elsif ( @slurpy ) {
160 1 $self->_croak( 'Found multiple slurpy parameters! There can be only one' );
161 }
162 }
163 elsif ( @$parameters ) {
164 143 ▶ if ( $parameters->[-1]->type->is_strictly_a_type_of( Slurpy ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($parameters->[-1]->type->is_strictly_a_type_of(&Slurpy())) { } 40 103 143
elsif ($parameters->[-1]{'slurpy'}) { } 7 96 103
165 40 $self->{slurpy} = pop @$parameters;
166 }
167 elsif ( $parameters->[-1]{slurpy} ) {
168 7 $self->{slurpy} = pop @$parameters;
169 7 $self->{slurpy}{type} = Slurpy[ $self->{slurpy}{type} ];
170 }
171  
172 143 for my $parameter ( @$parameters ) {
173 198 ▶ if ( $parameter->type->is_strictly_a_type_of( Slurpy ) or $parameter->{slurpy} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parameter->type->is_strictly_a_type_of(&Slurpy()) or $parameter->{"slurpy"}) 3 195 198
Condition66%2/3
$parameter->type->is_strictly_a_type_of(&Slurpy()) or $parameter->{"slurpy"}
l!l&&r!l&&!r
30195
MC/DC50%1/2
$parameter->type->is_strictly_a_type_of(&Slurpy()) or $parameter->{"slurpy"}
$parameter->type->is_strictly_a_type_of(&Slurpy()) $parameter->{"slurpy"}
Truth table66%2/3
A or B
A= $parameter->type->is_strictly_a_type_of(&Slurpy())B= $parameter->{"slurpy"}
ABresult
1X1
011
000
174 3 $self->_croak( 'Parameter following slurpy parameter' );
175 }
176 }
177 }
178  
179 312 ▶ if ( $self->{slurpy} and $self->{slurpy}->has_default ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"slurpy"} and $self->{"slurpy"}->has_default) 1 311 312
Condition100%3/3
$self->{"slurpy"} and $self->{"slurpy"}->has_default
!ll&&!rl&&r
242691
MC/DC100%2/2
$self->{"slurpy"} and $self->{"slurpy"}->has_default
$self->{"slurpy"} $self->{"slurpy"}->has_default
Truth table100%3/3
A and B
A= $self->{"slurpy"}B= $self->{"slurpy"}->has_default
ABresult
0X0
100
111
180 1 require Carp;
181 1 our @CARP_NOT = ( __PACKAGE__, 'Type::Params' );
182 1 Carp::carp( "Warning: the default for the slurpy parameter will be ignored, continuing anyway" );
183 1 delete $self->{slurpy}{default};
184 }
185
186 312 ▶ if ( $self->{slurpy} and $self->{slurpy}->optional ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"slurpy"} and $self->{"slurpy"}->optional) 1 311 312
Condition100%3/3
$self->{"slurpy"} and $self->{"slurpy"}->optional
!ll&&!rl&&r
242691
MC/DC100%2/2
$self->{"slurpy"} and $self->{"slurpy"}->optional
$self->{"slurpy"} $self->{"slurpy"}->optional
Truth table100%3/3
A and B
A= $self->{"slurpy"}B= $self->{"slurpy"}->optional
ABresult
0X0
100
111
187 1 require Carp;
188 1 our @CARP_NOT = ( __PACKAGE__, 'Type::Params' );
189 1 Carp::carp( "Warning: the optional for the slurpy parameter will be ignored, continuing anyway" );
190 1 delete $self->{slurpy}{optional};
191 }
192 }
193  
194 337 ▶sub _rationalize_returns {
Subroutine _rationalize_returns: called CC=6 SCAR=18.3
195 334 my $self = shift;
196
197 128 ▶ my $typify = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
198 125 my $ref = shift;
199 125 ▶ if ( is_Str $$ref ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_Str($$ref)) { } 1 124 125
200 1 require Type::Utils;
201 1 ▶ $$ref = Type::Utils::dwim_type( $$ref, $self->{package} ? ( for => $self->{package} ) : () );
Branch: 1 branch
BranchTrueFalseTotal
$self->{'package'} ? : 1 0 1
202 }
203 else {
204 124 $$ref = to_TypeTiny( $$ref );
205 }
206 334 };
207
208 334 ▶ if ( my $r = delete $self->{returns} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = delete $self->{"returns"}) 5 329 334
209 5 $typify->( \ $r );
210 5 ▶ $self->{returns_scalar} ||= $r;
Condition33%1/3
$self->{"returns_scalar"} ||= $r
l!l&&r!l&&!r
050
MC/DC0%0/2
$self->{"returns_scalar"} ||= $r
$self->{"returns_scalar"} $r
Truth table33%1/3
A ||= B
A= $self->{"returns_scalar"}B= $r
ABresult
1X1
011
000
211 5 ▶ $self->{returns_list} ||= ArrayRef->of( $r );
Condition33%1/3
$self->{"returns_list"} ||= &ArrayRef()->of($r)
l!l&&r!l&&!r
050
MC/DC0%0/2
$self->{"returns_list"} ||= &ArrayRef()->of($r)
$self->{"returns_list"} &ArrayRef()->of($r)
Truth table33%1/3
A ||= B
A= $self->{"returns_list"}B= &ArrayRef()->of($r)
ABresult
1X1
011
000
212 }
213  
214 exists $self->{$_} && $typify->( \ $self->{$_} )
215 334 ▶ for qw/ returns_scalar returns_list /;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{$_} and &$typify(\$self->{$_}) 120 548 668
216
217 334 return $self;
218 }
219  
220 359 ▶sub _parameters_from_list {
Subroutine _parameters_from_list: called CC=13 SCAR=25.7
221 356 my ( $class, $style, $list, %opts ) = @_;
222 356 my @return;
223 356 my $is_named = ( $style eq 'named' );
224  
225 356 ▶ while ( @$list ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$list) 730 356 1086
226 730 my ( $type, %param_opts );
227 730 ▶ if ( $is_named ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_named) 410 320 730
228 410 $param_opts{name} = assert_Str( shift( @$list ) );
229 }
230 730 ▶ if ( is_HashRef $list->[0] and exists $list->[0]{slurpy} and not is_Bool $list->[0]{slurpy} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_HashRef($list->[0]) and exists $list->[0]{'slurpy'} and not is_Bool($list->[0]{'slurpy'})) { } 2 728 730
Condition66%4/6
is_HashRef($list->[0]) and exists $list->[0]{"slurpy"} and not is_Bool($list->[0]{"slurpy"})
!ll&&!rl&&r
72802
is_HashRef($list->[0]) and exists $list->[0]{"slurpy"}
!ll&&!rl&&r
72802
MC/DC33%1/3
is_HashRef($list->[0]) and exists $list->[0]{"slurpy"} and not is_Bool($list->[0]{"slurpy"})
is_HashRef($list->[0]) exists $list->[0]{"slurpy"} not is_Bool($list->[0]{"slurpy"})
Truth table50%2/4
A and B and not(C)
A= is_HashRef($list->[0])B= exists $list->[0]{"slurpy"}C= not is_Bool($list->[0]{"slurpy"})
ABCresult
0XX0
10X0
1100
1111
231 2 my %new_opts = %{ shift( @$list ) };
232 2 $type = delete $new_opts{slurpy};
233 2 %param_opts = ( %param_opts, %new_opts, slurpy => 1 );
234 }
235 else {
236 728 $type = shift( @$list );
237 }
238 730 ▶ if ( is_HashRef( $list->[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_HashRef($list->[0])) 74 656 730
239 74 ▶ unless ( exists $list->[0]{slurpy} and not is_Bool $list->[0]{slurpy} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $list->[0]{"slurpy"} and not is_Bool($list->[0]{"slurpy"})) 72 2 74
Condition100%3/3
exists $list->[0]{"slurpy"} and not is_Bool($list->[0]{"slurpy"})
!ll&&!rl&&r
6662
MC/DC100%2/2
exists $list->[0]{"slurpy"} and not is_Bool($list->[0]{"slurpy"})
exists $list->[0]{"slurpy"} not is_Bool($list->[0]{"slurpy"})
Truth table100%3/3
A and not(B)
A= exists $list->[0]{"slurpy"}B= not is_Bool($list->[0]{"slurpy"})
ABresult
0X0
100
111
240 72 %param_opts = ( %param_opts, %{ +shift( @$list ) } );
241 }
242 }
243 $param_opts{type} =
244 4 ▶ is_Int($type) ? ( $type ? Any : do { $param_opts{optional} = !!1; Any; } ) :
Branch: 1 branch
BranchTrueFalseTotal
is_Str($type) ? : 2 721 723
245 730 ▶ is_Str($type) ? do { require Type::Utils; Type::Utils::dwim_type( $type, $opts{package} ? ( for => $opts{package} ) : () ) } :
Branch: 3 branches
BranchTrueFalseTotal
is_Int($type) ? : 7 723 730
$type ? : 3 4 7
$opts{'package'} ? : 2 0 2
246 to_TypeTiny( $type );
247 730 my $parameter = $class->_new_parameter( %param_opts );
248 730 push @return, $parameter;
249 }
250  
251 356 return \@return;
252 }
253  
254 320 ▶sub new_from_compile {
Subroutine new_from_compile: called CC=6 SCAR=17.9
Pod documented
255 317 my $class = shift;
256 317 my $style = shift;
257 317 my $is_named = ( $style eq 'named' );
258  
259 317 my %opts = ();
260 317 ▶ while ( is_HashRef $_[0] and not exists $_[0]{slurpy} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_HashRef($_[0]) and not exists $_[0]{"slurpy"}) 409 317 726
Condition66%2/3
is_HashRef($_[0]) and not exists $_[0]{"slurpy"}
!ll&&!rl&&r
3170409
MC/DC50%1/2
is_HashRef($_[0]) and not exists $_[0]{"slurpy"}
is_HashRef($_[0]) not exists $_[0]{"slurpy"}
Truth table66%2/3
A and not(B)
A= is_HashRef($_[0])B= not exists $_[0]{"slurpy"}
ABresult
0X0
100
111
261 409 %opts = ( %opts, %{ +shift } );
262 }
263  
264 317 for my $pos ( qw/ head tail / ) {
265 634 ▶ next unless defined $opts{$pos};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts{$pos} 595 39 634
266 39 ▶ if ( is_Int( $opts{$pos} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_Int($opts{$pos})) 6 33 39
267 6 $opts{$pos} = [ ( Any ) x $opts{$pos} ];
268 }
269 39 $opts{$pos} = $class->_parameters_from_list( positional => $opts{$pos}, %opts );
270 }
271  
272 317 my $list = [ @_ ];
273 317 $opts{is_named} = $is_named;
274 317 $opts{parameters} = $class->_parameters_from_list( $style => $list, %opts );
275  
276 317 my $self = $class->new( %opts, rationalize_slurpies => 1 );
277 310 return $self;
278 }
279  
280 345 ▶sub new_from_v2api {
Subroutine new_from_v2api: called CC=18 SCAR=28.9
Pod documented
281 342 my ( $class, $opts ) = @_;
282  
283 342 ▶ my $positional = delete( $opts->{positional} ) || delete( $opts->{pos} );
Condition100%3/3
delete $opts->{'positional'} || delete $opts->{'pos'}
l!l&&r!l&&!r
12129192
MC/DC100%2/2
delete $opts->{'positional'} || delete $opts->{'pos'}
delete $opts->{'positional'} delete $opts->{'pos'}
Truth table100%3/3
A || B
A= delete $opts->{'positional'}B= delete $opts->{'pos'}
ABresult
1X1
011
000
284 342 my $named = delete( $opts->{named} );
285 342 ▶ my $multiple = delete( $opts->{multiple} ) || delete( $opts->{multi} );
Condition100%3/3
delete $opts->{'multiple'} || delete $opts->{'multi'}
l!l&&r!l&&!r
220320
MC/DC100%2/2
delete $opts->{'multiple'} || delete $opts->{'multi'}
delete $opts->{'multiple'} delete $opts->{'multi'}
Truth table100%3/3
A || B
A= delete $opts->{'multiple'}B= delete $opts->{'multi'}
ABresult
1X1
011
000
286  
287 342 ▶ $class->_croak( "Signature must be positional, named, or multiple" )
Branch: 1 branch
BranchTrueFalseTotal
unless $positional or $named or $multiple 2 340 342
Condition100%6/6
$positional or $named or $multiple
l!l&&r!l&&!r
320202
$positional or $named
l!l&&r!l&&!r
15017022
MC/DC100%3/3
$positional or $named or $multiple
$positional $named $multiple
Truth table100%4/4
A or B or C
A= $positionalB= $namedC= $multiple
ABCresult
1XX1
01X1
0011
0000
288 unless $positional || $named || $multiple;
289  
290 340 ▶ if ( $multiple ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($multiple) 22 318 340
291 22 ▶ if ( is_HashRef $multiple ) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_HashRef($multiple)) { } 1 21 22
elsif (not is_ArrayRef($multiple)) { } 2 19 21
292 1 my @tmp;
293 1 ▶ while ( my ( $name, $alt ) = each %$multiple ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$multiple) 6 1 7
294 6 ▶ push @tmp,
Branch: 3 branches
BranchTrueFalseTotal
is_HashRef($alt) ? : 5 1 6
is_ArrayRef($alt) ? : 0 1 1
is_CodeRef($alt) ? : 1 0 1
295 is_HashRef($alt) ? { ID => $name, %$alt } :
296 is_ArrayRef($alt) ? { ID => $name, pos => $alt } :
297 is_CodeRef($alt) ? { ID => $name, closure => $alt } :
298 $class->_croak( "Bad alternative in multiple signature" );
299 }
300 1 $multiple = \@tmp;
301 }
302 elsif ( not is_ArrayRef $multiple ) {
303 2 $multiple = [];
304 }
305 22 ▶ unshift @$multiple, { positional => $positional } if $positional;
Branch: 1 branch
BranchTrueFalseTotal
if $positional 2 20 22
306 22 ▶ unshift @$multiple, { named => $named } if $named;
Branch: 1 branch
BranchTrueFalseTotal
if $named 2 20 22
307 22 require Type::Params::Alternatives;
308 22 return 'Type::Params::Alternatives'->new(
309 base_options => $opts,
310 alternatives => $multiple,
311 sig_class => $class,
312 );
313 }
314  
315 318 my ( $sig_kind, $args ) = ( pos => $positional );
316 318 ▶ if ( $named ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($named) 172 146 318
317 172 ▶ $opts->{bless} = 1 unless exists $opts->{bless};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"bless"} 38 134 172
318 172 ( $sig_kind, $args ) = ( named => $named );
319 172 ▶ $class->_croak( "Signature cannot have both positional and named arguments" )
Branch: 1 branch
BranchTrueFalseTotal
if $positional 2 170 172
320 if $positional;
321 }
322  
323 316 return $class->new_from_compile( $sig_kind, $opts, @$args );
324 }
325  
326 649 ▶sub package { $_[0]{package} }
Subroutine package: called CC=1 SCAR=0.0
Pod documented
327 651 ▶sub subname { $_[0]{subname} }
Subroutine subname: called CC=1 SCAR=0.0
Pod documented
328 0 ▶sub description { $_[0]{description} } sub has_description { exists $_[0]{description} }
Subroutine description: called CC=1 SCAR=1.2
Subroutine has_description: called CC=1 SCAR=1.2
Pod documented
Pod documented
329 330 ▶sub method { $_[0]{method} }
Subroutine method: called CC=1 SCAR=0.0
Pod documented
330 1499 ▶sub head { $_[0]{head} } sub has_head { exists $_[0]{head} }
Subroutine has_head: called CC=1 SCAR=0.0
Subroutine head: called CC=1 SCAR=0.0
Pod documented
Pod documented
331 1305 ▶sub tail { $_[0]{tail} } sub has_tail { exists $_[0]{tail} }
Subroutine has_tail: called CC=1 SCAR=0.0
Subroutine tail: called CC=1 SCAR=0.0
Pod documented
Pod documented
332 1 ▶sub parameters { $_[0]{parameters} } sub has_parameters { exists $_[0]{parameters} }
Subroutine has_parameters: called CC=1 SCAR=0.0
Subroutine parameters: called CC=1 SCAR=0.0
Pod documented
Pod documented
333 830 ▶sub slurpy { $_[0]{slurpy} } sub has_slurpy { exists $_[0]{slurpy} }
Subroutine has_slurpy: called CC=1 SCAR=0.0
Subroutine slurpy: called CC=1 SCAR=0.0
Pod documented
Pod documented
334 1873 ▶sub on_die { $_[0]{on_die} } sub has_on_die { exists $_[0]{on_die} }
Subroutine has_on_die: called CC=1 SCAR=0.0
Subroutine on_die: called CC=1 SCAR=0.0
Pod documented
Pod documented
335 1308 ▶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
336 675 ▶sub next { $_[0]{next} }
Subroutine next: called CC=1 SCAR=0.0
Pod documented
337 0 ▶sub goto_next { $_[0]{next} }
Subroutine goto_next: not called CC=1 SCAR=6.9
Pod documented
338 2123 ▶sub is_named { $_[0]{is_named} }
Subroutine is_named: called CC=1 SCAR=0.0
Pod documented
339 554 ▶sub allow_dash { $_[0]{allow_dash} }
Subroutine allow_dash: called CC=1 SCAR=0.0
Pod documented
340 666 ▶sub bless { $_[0]{bless} }
Subroutine bless: called CC=1 SCAR=0.0
Pod documented
341 176 ▶sub class { $_[0]{class} }
Subroutine class: called CC=1 SCAR=0.0
Pod documented
342 24 ▶sub constructor { $_[0]{constructor} }
Subroutine constructor: called CC=1 SCAR=0.0
Pod documented
343 203 ▶sub named_to_list { $_[0]{named_to_list} }
Subroutine named_to_list: called CC=1 SCAR=0.0
Pod documented
344 877 ▶sub list_to_named { $_[0]{list_to_named} }
Subroutine list_to_named: called CC=1 SCAR=0.0
Pod documented
345 60 ▶sub oo_trace { $_[0]{oo_trace} }
Subroutine oo_trace: called CC=1 SCAR=0.0
Pod documented
346 76 ▶sub returns_scalar{ $_[0]{returns_scalar} } sub has_returns_scalar{ defined $_[0]{returns_scalar} }
Subroutine has_returns_scalar: called CC=1 SCAR=0.0
Subroutine returns_scalar: called CC=1 SCAR=0.0
Pod documented
Pod undocumented
347 82 ▶sub returns_list { $_[0]{returns_list} } sub has_returns_list { defined $_[0]{returns_list} }
Subroutine has_returns_list: called CC=1 SCAR=0.0
Subroutine returns_list: called CC=1 SCAR=0.0
Pod documented
Pod undocumented
348  
349 41 ▶sub method_invocant { $_[0]{method_invocant} = defined( $_[0]{method_invocant} ) ? $_[0]{method_invocant} : 'undef' }
Subroutine method_invocant: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{'method_invocant'} ? : 37 4 41
350  
351 484 ▶sub can_shortcut {
Subroutine can_shortcut: called CC=3 SCAR=11.0
Pod documented
352 return $_[0]{can_shortcut}
353 484 ▶ if exists $_[0]{can_shortcut};
Branch: 1 branch
BranchTrueFalseTotal
if exists $_[0]{"can_shortcut"} 321 163 484
354 $_[0]{can_shortcut} = !(
355 $_[0]->slurpy or
356 163 ▶ grep $_->might_supply_new_value, @{ $_[0]->parameters }
Condition100%3/3
$_[0]->slurpy || grep($_->might_supply_new_value, @{$_[0]->parameters;})
l!l&&r!l&&!r
462394
MC/DC100%2/2
$_[0]->slurpy || grep($_->might_supply_new_value, @{$_[0]->parameters;})
$_[0]->slurpy grep($_->might_supply_new_value, @{$_[0]->parameters;})
Truth table100%3/3
A || B
A= $_[0]->slurpyB= grep($_->might_supply_new_value, @{$_[0]->parameters;})
ABresult
1X1
011
000
357 );
358 }
359  
360 330 ▶sub coderef {
Subroutine coderef: called CC=2 SCAR=7.2
Pod documented
361 330 ▶ $_[0]{coderef} ||= $_[0]->_build_coderef;
Condition66%2/3
$_[0]{"coderef"} ||= $_[0]->_build_coderef
l!l&&r!l&&!r
03282
MC/DC50%1/2
$_[0]{"coderef"} ||= $_[0]->_build_coderef
$_[0]{"coderef"} $_[0]->_build_coderef
Truth table66%2/3
A ||= B
A= $_[0]{"coderef"}B= $_[0]->_build_coderef
ABresult
1X1
011
000
362 }
363  
364 330 ▶sub _build_coderef {
Subroutine _build_coderef: called CC=8 SCAR=20.9
365 330 my $self = shift;
366 330 ▶ my $coderef = $self->_new_code_accumulator(
Condition57%4/7
$self->description || sprintf(q[parameter validation for '%s::%s'], $self->package || '', $self->subname || '__ANON__')
l!l&&r!l&&!r
53250
$self->package || ''
l!l
3250
$self->subname || '__ANON__'
l!l
3250
MC/DC0%0/2
$self->description || sprintf(q[parameter validation for '%s::%s'], $self->package || '', $self->subname || '__ANON__')
$self->description sprintf(q[parameter validation for '%s::%s'], $self->package || '', $self->subname || '__ANON__')
MC/DC0%0/1
$self->package || ''
$self->package
MC/DC0%0/1
$self->subname || '__ANON__'
$self->subname
Truth table66%2/3
A || B
A= $self->descriptionB= sprintf(q[parameter validation for '%s::%s'], $self->package || '', $self->subname || '__ANON__')
ABresult
1X1
011
000
Truth table50%1/2
A
A= $self->package
Aresult
11
00
Truth table50%1/2
A
A= $self->subname
Aresult
11
00
367 description => $self->description
368 || sprintf( q{parameter validation for '%s::%s'}, $self->package || '', $self->subname || '__ANON__' )
369 );
370  
371 330 $self->_coderef_start( $coderef );
372 328 ▶ $self->_coderef_head( $coderef ) if $self->has_head;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_head 48 280 328
373 328 ▶ $self->_coderef_tail( $coderef ) if $self->has_tail;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_tail 16 312 328
374 328 $self->_coderef_parameters( $coderef );
375 327 ▶ if ( $self->has_slurpy ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->has_slurpy) { } 70 257 327
elsif ($self->is_named) { } 142 115 257
376 70 $self->_coderef_slurpy( $coderef );
377 }
378 elsif ( $self->is_named ) {
379 142 $self->_coderef_extra_names( $coderef );
380 }
381 327 $self->_coderef_end( $coderef );
382  
383 327 return $coderef;
384 }
385  
386 330 ▶sub _coderef_start {
Subroutine _coderef_start: called CC=9 SCAR=22.0
387 330 my ( $self, $coderef ) = ( shift, @_ );
388  
389 330 $coderef->add_line( 'sub {' );
390 330 $coderef->{indent} .= "\t";
391  
392 330 ▶ if ( my $next = $self->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $next = $self->next) 57 273 330
393 57 ▶ if ( is_CodeLike $next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_CodeLike($next)) { } 56 1 57
394 56 $coderef->add_variable( '$__NEXT__', \$next );
395 }
396 else {
397 1 $coderef->add_line( 'my $__NEXT__ = shift;' );
398 1 $coderef->add_gap;
399 }
400 }
401  
402 330 ▶ if ( $self->method ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->method) 36 294 330
403 # Passed to parameter defaults
404 36 $self->{method_invocant} = '$__INVOCANT__';
405 36 $coderef->add_line( sprintf 'my %s = $_[0];', $self->method_invocant );
406 36 $coderef->add_gap;
407 }
408  
409 330 $self->_coderef_start_extra( $coderef );
410  
411 329 my $extravars = '';
412 329 ▶ if ( $self->has_head ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_head) 48 281 329
413 48 $extravars .= ', @head';
414 }
415 329 ▶ if ( $self->has_tail ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_tail) 16 313 329
416 16 $extravars .= ', @tail';
417 }
418  
419 329 ▶ if ( $self->is_named ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->is_named) { } 166 163 329
elsif ($self->can_shortcut) { } 94 69 163
420 166 $coderef->add_line( "my ( \%out, \%in, \%tmp, \$tmp, \$dtmp$extravars );" );
421 }
422 elsif ( $self->can_shortcut ) {
423 94 $coderef->add_line( "my ( \%tmp, \$tmp$extravars );" );
424 }
425 else {
426 69 $coderef->add_line( "my ( \@out, \%tmp, \$tmp, \$dtmp$extravars );" );
427 }
428  
429 329 ▶ if ( $self->has_on_die ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_on_die) 7 322 329
430 7 $coderef->add_variable( '$__ON_DIE__', \ $self->on_die );
431 }
432  
433 329 $coderef->add_gap;
434  
435 329 $self->_coderef_check_count( $coderef );
436  
437 328 $coderef->add_gap;
438  
439 328 $self;
440 }
441  
442 308 ▶sub _coderef_start_extra {}
Subroutine _coderef_start_extra: called CC=1 SCAR=0.0
443  
444 308 ▶sub _coderef_check_count {
Subroutine _coderef_check_count: called CC=26 SCAR=32.6
445 308 my ( $self, $coderef ) = ( shift, @_ );
446  
447 308 my $strictness_test = '';
448 308 ▶ if ( defined $self->strictness and $self->strictness eq 1 ) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $self->strictness and $self->strictness eq 1) { } 1 307 308
elsif ($self->strictness) { } 3 304 307
elsif ($self->has_strictness) { } 1 303 304
Condition100%3/3
defined $self->strictness and $self->strictness eq 1
!ll&&!rl&&r
30341
MC/DC100%2/2
defined $self->strictness and $self->strictness eq 1
defined $self->strictness $self->strictness eq 1
Truth table100%3/3
A and B
A= defined $self->strictnessB= $self->strictness eq 1
ABresult
0X0
100
111
449 1 $strictness_test = '';
450 }
451 elsif ( $self->strictness ) {
452 3 $strictness_test = sprintf '( not %s ) or ', $self->strictness;
453 }
454 elsif ( $self->has_strictness ) {
455 1 return $self;
456 }
457  
458 307 my $headtail = 0;
459 307 ▶ $headtail += @{ $self->head } if $self->has_head;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_head 48 259 307
460 307 ▶ $headtail += @{ $self->tail } if $self->has_tail;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_tail 16 291 307
461  
462 307 my $is_named = $self->is_named;
463 307 my $min_args = 0;
464 307 my $max_args = 0;
465 307 my $seen_optional = 0;
466 307 for my $parameter ( @{ $self->parameters } ) {
467 572 ▶ if ( $parameter->optional ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parameter->optional) { } 127 445 572
468 127 ++$seen_optional;
469 127 ++$max_args;
470 }
471 else {
472 445 ▶ $seen_optional and !$is_named and $self->_croak(
Branch: 1 branch
BranchTrueFalseTotal
$seen_optional and not $is_named and $self->_croak("Non-Optional parameter following Optional parameter") 1 444 445
Condition100%3/3
$seen_optional and not $is_named
!ll&&!rl&&r
43681
MC/DC100%2/2
$seen_optional and not $is_named
$seen_optional not $is_named
Truth table100%3/3
A and not(B)
A= $seen_optionalB= not $is_named
ABresult
0X0
100
111
473 'Non-Optional parameter following Optional parameter',
474 );
475 444 ++$max_args;
476 444 ++$min_args;
477 }
478 }
479  
480 306 ▶ undef $max_args if $self->has_slurpy;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_slurpy 70 236 306
481  
482 # Note: code related to $max_args_if_hash is currently commented out
483 # because it handles this badly:
484 #
485 # my %opts = ( x => 1, y => 1 );
486 # your_func( %opts, y => 2 ); # override y
487 #
488  
489 306 ▶ if ( $is_named and $self->list_to_named ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($is_named and $self->list_to_named) { } 5 301 306
elsif ($is_named) { } 161 140 301
Condition100%3/3
$is_named and $self->list_to_named
!ll&&!rl&&r
1401615
MC/DC100%2/2
$is_named and $self->list_to_named
$is_named $self->list_to_named
Truth table100%3/3
A and B
A= $is_namedB= $self->list_to_named
ABresult
0X0
100
111
490 5 require List::Util;
491 5 my $args_if_hashref = $headtail + 1;
492 5 ▶ my $min_args_if_list = $headtail + List::Util::sum( 0, map { $_->optional ? 0 : $_->in_list ? 1 : 2 } @{ $self->parameters } );
Branch: 2 branches
BranchTrueFalseTotal
$_->optional ? : 0 10 10
$_->in_list ? : 9 1 10
493 5 $self->{min_args} = List::Util::min( $args_if_hashref, $min_args_if_list );
494
495 $coderef->add_line( $strictness_test . sprintf(
496 "\@_ >= %d\n\tor %s;",
497 $self->{min_args},
498 5 $self->_make_count_fail(
499 coderef => $coderef,
500 got => 'scalar( @_ )',
501 ),
502 ) );
503 }
504 elsif ( $is_named ) {
505 161 my $args_if_hashref = $headtail + 1;
506 161 ▶ my $hashref_index = @{ $self->head || [] };
Condition100%2/2
$self->head || []
l!l
17144
MC/DC100%1/1
$self->head || []
$self->head
Truth table100%2/2
A
A= $self->head
Aresult
11
00
507 161 my $arity_if_hash = $headtail % 2;
508 161 my $min_args_if_hash = $headtail + ( 2 * $min_args );
509 #my $max_args_if_hash = defined( $max_args )
510 # ? ( $headtail + ( 2 * $max_args ) )
511 # : undef;
512  
513 161 require List::Util;
514 161 $self->{min_args} = List::Util::min( $args_if_hashref, $min_args_if_hash );
515 #if ( defined $max_args_if_hash ) {
516 # $self->{max_args} = List::Util::max( $args_if_hashref, $max_args_if_hash );
517 #}
518  
519 161 my $extra_conditions = '';
520 #if ( defined $max_args_if_hash and $min_args_if_hash==$max_args_if_hash ) {
521 # $extra_conditions .= " && \@_ == $min_args_if_hash"
522 #}
523 #else {
524 161 ▶ $extra_conditions .= " && \@_ >= $min_args_if_hash"
Branch: 1 branch
BranchTrueFalseTotal
if $min_args_if_hash 151 10 161
525 if $min_args_if_hash;
526 # $extra_conditions .= " && \@_ <= $max_args_if_hash"
527 # if defined $max_args_if_hash;
528 #}
529  
530 161 $coderef->add_line( $strictness_test . sprintf(
531 "\@_ == %d && %s\n\tor \@_ %% 2 == %d%s\n\tor %s;",
532 $args_if_hashref,
533 HashRef->inline_check( sprintf '$_[%d]', $hashref_index ),
534 $arity_if_hash,
535 $extra_conditions,
536 $self->_make_count_fail(
537 coderef => $coderef,
538 got => 'scalar( @_ )',
539 ),
540 ) );
541 }
542 else {
543 140 $min_args += $headtail;
544 140 ▶ $max_args += $headtail if defined $max_args;
Branch: 1 branch
BranchTrueFalseTotal
if defined $max_args 94 46 140
545  
546 140 $self->{min_args} = $min_args;
547 140 $self->{max_args} = $max_args;
548  
549 140 ▶ if ( defined $max_args and $min_args == $max_args ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $max_args and $min_args == $max_args) { } 73 67 140
elsif ($min_args and defined $max_args) { } 11 56 67
Condition100%3/3
defined $max_args and $min_args == $max_args
!ll&&!rl&&r
462173
MC/DC100%2/2
defined $max_args and $min_args == $max_args
defined $max_args $min_args == $max_args
Truth table100%3/3
A and B
A= defined $max_argsB= $min_args == $max_args
ABresult
0X0
100
111
550 73 $coderef->add_line( $strictness_test . sprintf(
551 "\@_ == %d\n\tor %s;",
552 $min_args,
553 $self->_make_count_fail(
554 coderef => $coderef,
555 minimum => $min_args,
556 maximum => $max_args,
557 got => 'scalar( @_ )',
558 ),
559 ) );
560 }
561 ▶ elsif ( $min_args and defined $max_args ) {
Condition100%3/3
$min_args and defined $max_args
!ll&&!rl&&r
282811
MC/DC100%2/2
$min_args and defined $max_args
$min_args defined $max_args
Truth table100%3/3
A and B
A= $min_argsB= defined $max_args
ABresult
0X0
100
111
562 11 $coderef->add_line( $strictness_test . sprintf(
563 "\@_ >= %d && \@_ <= %d\n\tor %s;",
564 $min_args,
565 $max_args,
566 $self->_make_count_fail(
567 coderef => $coderef,
568 minimum => $min_args,
569 maximum => $max_args,
570 got => 'scalar( @_ )',
571 ),
572 ) );
573 }
574 else {
575 56 ▶ $coderef->add_line( $strictness_test . sprintf(
Condition100%4/4
$min_args || 0
l!l
2828
$min_args || 0
l!l
2828
MC/DC100%1/1
$min_args || 0
$min_args
MC/DC100%1/1
$min_args || 0
$min_args
Truth table100%2/2
A
A= $min_args
Aresult
11
00
Truth table100%2/2
A
A= $min_args
Aresult
11
00
576 "\@_ >= %d\n\tor %s;",
577 $min_args || 0,
578 $self->_make_count_fail(
579 coderef => $coderef,
580 minimum => $min_args || 0,
581 got => 'scalar( @_ )',
582 ),
583 ) );
584 }
585 }
586 }
587  
588 48 ▶sub _coderef_head {
Subroutine _coderef_head: called CC=3 SCAR=11.0
589 48 my ( $self, $coderef ) = ( shift, @_ );
590 48 ▶ $self->has_head or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->has_head or return 48 0 48
591  
592 48 my $size = @{ $self->head };
593 48 $coderef->add_line( sprintf(
594 '@head = splice( @_, 0, %d );',
595 $size,
596 ) );
597  
598 48 $coderef->add_gap;
599  
600 48 my $i = 0;
601 48 for my $parameter ( @{ $self->head } ) {
602 56 $parameter->_make_code(
603 signature => $self,
604 coderef => $coderef,
605 input_slot => sprintf( '$head[%d]', $i ),
606 input_var => '@head',
607 output_slot => sprintf( '$head[%d]', $i ),
608 output_var => undef,
609 index => $i,
610 type => 'head',
611 display_var => sprintf( '$_[%d]', $i ),
612 );
613 56 ++$i;
614 }
615  
616 48 $self;
617 }
618  
619 16 ▶sub _coderef_tail {
Subroutine _coderef_tail: called CC=3 SCAR=11.0
620 16 my ( $self, $coderef ) = ( shift, @_ );
621 16 ▶ $self->has_tail or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->has_tail or return 16 0 16
622  
623 16 my $size = @{ $self->tail };
624 16 $coderef->add_line( sprintf(
625 '@tail = splice( @_, -%d );',
626 $size,
627 ) );
628  
629 16 $coderef->add_gap;
630  
631 16 my $i = 0;
632 16 my $n = @{ $self->tail };
633 16 for my $parameter ( @{ $self->tail } ) {
634 42 $parameter->_make_code(
635 signature => $self,
636 coderef => $coderef,
637 input_slot => sprintf( '$tail[%d]', $i ),
638 input_var => '@tail',
639 output_slot => sprintf( '$tail[%d]', $i ),
640 output_var => undef,
641 index => $i,
642 type => 'tail',
643 display_var => sprintf( '$_[-%d]', $n - $i ),
644 );
645 42 ++$i;
646 }
647  
648 16 $self;
649 }
650  
651 328 ▶sub _coderef_parameters {
Subroutine _coderef_parameters: called CC=9 SCAR=22.0
652 328 my ( $self, $coderef ) = ( shift, @_ );
653  
654 328 ▶ if ( $self->is_named ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_named) { } 166 162 328
655
656 166 ▶ if ( $self->list_to_named ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->list_to_named) 5 161 166
657 5 require Type::Tiny::Enum;
658 5 my $Keys = Type::Tiny::Enum->new( values => [ map { $_->name, $_->_all_aliases($self) } @{ $self->parameters } ] );
659 5 $coderef->addf( 'my @positional;' );
660 5 $coderef->addf( '{' );
661 5 $coderef->increase_indent;
662 5 $coderef->addf( 'last if ( @_ == 0 );' );
663 5 $coderef->addf( 'last if ( @_ == 1 and %s );', HashRef->inline_check( '$_[0]' ) );
664 5 $coderef->addf( 'last if ( @_ %% 2 == 0 and %s );', $Keys->inline_check( '$_[0]' ) );
665 5 $coderef->addf( 'push @positional, shift @_;' );
666 5 $coderef->addf( 'redo;' );
667 5 $coderef->decrease_indent;
668 5 $coderef->addf( '}' );
669 5 $coderef->add_gap;
670 }
671  
672 166 $coderef->add_line( sprintf(
673 '%%in = ( @_ == 1 and %s ) ? %%{ $_[0] } : @_;',
674 HashRef->inline_check( '$_[0]' ),
675 ) );
676 166 $coderef->add_gap;
677  
678 166 for my $parameter ( @{ $self->parameters } ) {
679 379 my $qname = B::perlstring( $parameter->name );
680 379 $parameter->_make_code(
681 signature => $self,
682 coderef => $coderef,
683 is_named => 1,
684 input_slot => sprintf( '$in{%s}', $qname ),
685 output_slot => sprintf( '$out{%s}', $qname ),
686 display_var => sprintf( '$_{%s}', $qname ),
687 key => $parameter->name,
688 type => 'named_arg',
689 );
690 }
691
692 166 ▶ if ( $self->list_to_named ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->list_to_named) 5 161 166
693 5 $coderef->add_line( sprintf(
694 '@positional and %s;',
695 $self->_make_general_fail(
696 coderef => $coderef,
697 message => q{'Superfluous positional arguments'},
698 ),
699 ) );
700 }
701 }
702 else {
703 162 my $can_shortcut = $self->can_shortcut;
704 162 ▶ my $head_size = $self->has_head ? @{ $self->head } : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->has_head ? : 30 132 162
705  
706 162 my $i = 0;
707 162 for my $parameter ( @{ $self->parameters } ) {
708 193 ▶ $parameter->_make_code(
Branch: 2 branches
BranchTrueFalseTotal
$can_shortcut ? : 128 65 193
$can_shortcut ? : 128 65 193
709 signature => $self,
710 coderef => $coderef,
711 is_named => 0,
712 input_slot => sprintf( '$_[%d]', $i ),
713 input_var => '@_',
714 output_slot => ( $can_shortcut ? undef : sprintf( '$_[%d]', $i ) ),
715 output_var => ( $can_shortcut ? undef : '@out' ),
716 index => $i,
717 display_var => sprintf( '$_[%d]', $i + $head_size ),
718 );
719 192 ++$i;
720 }
721 }
722 }
723  
724 70 ▶sub _coderef_slurpy {
Subroutine _coderef_slurpy: called CC=8 SCAR=20.9
725 70 my ( $self, $coderef ) = ( shift, @_ );
726 70 ▶ return unless $self->has_slurpy;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_slurpy 0 70 70
727  
728 70 my $parameter = $self->slurpy;
729 70 my $constraint = $parameter->type;
730 70 my $slurp_into = $constraint->my_slurp_into;
731 70 my $real_type = $constraint->my_unslurpy;
732  
733 70 ▶ if ( $self->is_named ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->is_named) { } 24 46 70
elsif ($real_type and $real_type->{'uniq'} == &Any()->{'uniq'}) { } 1 45 46
elsif ($slurp_into eq 'HASH') { } 29 16 45
734 24 $coderef->add_line( 'my $SLURPY = \\%in;' );
735 }
736 ▶ elsif ( $real_type and $real_type->{uniq} == Any->{uniq} ) {
Condition66%2/3
$real_type and $real_type->{"uniq"} == &Any()->{"uniq"}
!ll&&!rl&&r
0451
MC/DC50%1/2
$real_type and $real_type->{"uniq"} == &Any()->{"uniq"}
$real_type $real_type->{"uniq"} == &Any()->{"uniq"}
Truth table66%2/3
A and B
A= $real_typeB= $real_type->{"uniq"} == &Any()->{"uniq"}
ABresult
0X0
100
111
737  
738 $coderef->add_line( sprintf(
739 'my $SLURPY = [ @_[ %d .. $#_ ] ];',
740 1 scalar( @{ $self->parameters } ),
741 ) );
742 }
743 elsif ( $slurp_into eq 'HASH' ) {
744  
745 29 my $index = scalar( @{ $self->parameters } );
746 29 ▶ $coderef->add_line( sprintf(
Condition33%1/3
$real_type || $constraint
l!l&&r!l&&!r
2900
MC/DC0%0/2
$real_type || $constraint
$real_type $constraint
Truth table33%1/3
A || B
A= $real_typeB= $constraint
ABresult
1X1
011
000
747 'my $SLURPY = ( $#_ == %d and ( %s ) ) ? { %%{ $_[%d] } } : ( ( $#_ - %d ) %% 2 ) ? { @_[ %d .. $#_ ] } : %s;',
748 $index,
749 HashRef->inline_check("\$_[$index]"),
750 $index,
751 $index,
752 $index,
753 $self->_make_general_fail(
754 coderef => $coderef,
755 message => sprintf(
756 qq{sprintf( "Odd number of elements in %%s", %s )},
757 B::perlstring( ( $real_type or $constraint )->display_name ),
758 ),
759 ),
760 ) );
761 }
762 else {
763
764 $coderef->add_line( sprintf(
765 'my $SLURPY = [ @_[ %d .. $#_ ] ];',
766 16 scalar( @{ $self->parameters } ),
767 ) );
768 }
769  
770 70 $coderef->add_gap;
771  
772 70 ▶ $parameter->_make_code(
Branch: 1 branch
BranchTrueFalseTotal
$self->is_named ? : 24 46 70
773 signature => $self,
774 coderef => $coderef,
775 input_slot => '$SLURPY',
776 display_var => '$SLURPY',
777 index => 0,
778 is_slurpy => 1,
779 $self->is_named
780 ? ( output_slot => sprintf( '$out{%s}', B::perlstring( $parameter->name ) ) )
781 : ( output_var => '@out' )
782 );
783 }
784  
785 142 ▶sub _coderef_extra_names {
Subroutine _coderef_extra_names: called CC=6 SCAR=19.2
786 142 my ( $self, $coderef ) = ( shift, @_ );
787  
788 142 ▶ return $self if $self->has_strictness && ! $self->strictness;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_strictness and not $self->strictness 0 142 142
Condition33%1/3
$self->has_strictness and not $self->strictness
!ll&&!rl&&r
14200
MC/DC0%0/2
$self->has_strictness and not $self->strictness
$self->has_strictness not $self->strictness
Truth table33%1/3
A and not(B)
A= $self->has_strictnessB= not $self->strictness
ABresult
0X0
100
111
789  
790 142 require Type::Utils;
791 142 my $english_list = 'Type::Utils::english_list';
792 142 ▶ if ( $Type::Tiny::AvoidCallbacks ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Type::Tiny::AvoidCallbacks) 8 134 142
793 8 $english_list = 'join q{, } => ';
794 }
795  
796 142 $coderef->add_line( '# Unrecognized parameters' );
797 142 ▶ $coderef->add_line( sprintf(
Branch: 1 branch
BranchTrueFalseTotal
defined $self->strictness && $self->strictness ne 1 ? : 0 142 142
Condition33%1/3
defined $self->strictness and $self->strictness ne 1
!ll&&!rl&&r
14200
MC/DC0%0/2
defined $self->strictness and $self->strictness ne 1
defined $self->strictness $self->strictness ne 1
Truth table33%1/3
A and B
A= defined $self->strictnessB= $self->strictness ne 1
ABresult
0X0
100
111
798 '%s if %skeys %%in;',
799 $self->_make_general_fail(
800 coderef => $coderef,
801 message => "sprintf( q{Unrecognized parameter%s: %s}, keys( %in ) > 1 ? q{s} : q{}, $english_list( sort keys %in ) )",
802 ),
803 defined( $self->strictness ) && $self->strictness ne 1
804 ? sprintf( '%s && ', $self->strictness )
805 : ''
806 ) );
807 142 $coderef->add_gap;
808 }
809  
810 327 ▶sub _coderef_end {
Subroutine _coderef_end: called CC=9 SCAR=22.0
811 327 my ( $self, $coderef ) = ( shift, @_ );
812  
813 327 ▶ if ( $self->{_is_signature_for} and $self->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_is_signature_for"} and $self->next) 38 289 327
Condition100%3/3
$self->{"_is_signature_for"} and $self->next
!ll&&!rl&&r
280938
MC/DC100%2/2
$self->{"_is_signature_for"} and $self->next
$self->{"_is_signature_for"} $self->next
Truth table100%3/3
A and B
A= $self->{"_is_signature_for"}B= $self->next
ABresult
0X0
100
111
814 38 ▶ $coderef->add_variable( '$return_check_for_scalar', \ $self->returns_scalar->compiled_check )
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_returns_scalar 6 32 38
815 if $self->has_returns_scalar;
816 38 ▶ $coderef->add_variable( '$return_check_for_list', \ $self->returns_list->compiled_check )
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_returns_list 6 32 38
817 if $self->has_returns_list;
818 }
819  
820 327 ▶ if ( $self->bless and $self->oo_trace ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->bless and $self->oo_trace) 38 289 327
Condition100%3/3
$self->bless and $self->oo_trace
!ll&&!rl&&r
2672238
MC/DC100%2/2
$self->bless and $self->oo_trace
$self->bless $self->oo_trace
Truth table100%3/3
A and B
A= $self->blessB= $self->oo_trace
ABresult
0X0
100
111
821 38 my $package = $self->package;
822 38 my $subname = $self->subname;
823 38 ▶ if ( defined $package and defined $subname ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $package and defined $subname) 38 0 38
Condition33%1/3
defined $package and defined $subname
!ll&&!rl&&r
0038
MC/DC0%0/2
defined $package and defined $subname
defined $package defined $subname
Truth table33%1/3
A and B
A= defined $packageB= defined $subname
ABresult
0X0
100
111
824 38 $coderef->add_line( sprintf(
825 '$out{"~~caller"} = %s;',
826 B::perlstring( "$package\::$subname" ),
827 ) );
828 38 $coderef->add_gap;
829 }
830 }
831  
832 327 $self->_coderef_end_extra( $coderef );
833 327 $coderef->add_line( $self->_make_return_expression( is_early => 0, allow_full_statements => 1 ) . ';' );
834 327 $coderef->{indent} =~ s/\t$//;
835 327 $coderef->add_line( '}' );
836  
837 327 $self;
838 }
839  
840 306 ▶sub _coderef_end_extra {}
Subroutine _coderef_end_extra: called CC=1 SCAR=0.0
841  
842 325 ▶sub _make_return_list {
Subroutine _make_return_list: called CC=9 SCAR=22.0
843 325 my $self = shift;
844  
845 325 my @return_list;
846 325 ▶ if ( $self->has_head ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_head) 48 277 325
847 48 push @return_list, '@head';
848 }
849  
850 325 ▶ if ( not $self->is_named ) {
Branch: 4 branches
BranchTrueFalseTotal
if (not $self->is_named) { } 159 166 325
elsif ($self->named_to_list) { } 14 152 166
elsif ($self->class) { } 24 128 152
elsif ($self->bless) { } 49 79 128
851 159 ▶ push @return_list, $self->can_shortcut ? '@_' : '@out';
Branch: 1 branch
BranchTrueFalseTotal
$self->can_shortcut ? : 91 68 159
852 }
853 elsif ( $self->named_to_list ) {
854 push @return_list, map(
855 sprintf( '$out{%s}', B::perlstring( $_ ) ),
856 14 @{ $self->named_to_list },
857 );
858 }
859 elsif ( $self->class ) {
860 24 ▶ push @return_list, sprintf(
Condition100%2/2
$self->constructor || 'new'
l!l
168
MC/DC100%1/1
$self->constructor || 'new'
$self->constructor
Truth table100%2/2
A
A= $self->constructor
Aresult
11
00
861 '%s->%s( \%%out )',
862 B::perlstring( $self->class ),
863 $self->constructor || 'new',
864 );
865 }
866 elsif ( $self->bless ) {
867 49 push @return_list, sprintf(
868 'bless( \%%out, %s )',
869 B::perlstring( $self->bless ),
870 );
871 }
872 else {
873 79 push @return_list, '\%out';
874 }
875  
876 325 ▶ if ( $self->has_tail ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_tail) 16 309 325
877 16 push @return_list, '@tail';
878 }
879  
880 325 return @return_list;
881 }
882  
883 346 ▶sub _make_return_expression {
Subroutine _make_return_expression: called CC=11 SCAR=25.1
884 346 my ( $self, %args ) = @_;
885  
886 346 my $list = join q{, }, $self->_make_return_list;
887  
888 346 ▶ if ( $self->next ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->next) { } 57 289 346
elsif ($args{'is_early'} or not exists $args{'is_early'}) { } 19 270 289
889 57 ▶ if ( $self->{_is_signature_for} and ( $self->has_returns_list or $self->has_returns_scalar ) ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'_is_signature_for'} and $self->has_returns_list || $self->has_returns_scalar) { } 6 51 57
elsif ($list eq '@_') { } 8 43 51
elsif ($args{'allow_full_statements'} and not $args{'is_early'} || !exists $args{'is_early'}) { } 43 0 43
Condition83%5/6
$self->{"_is_signature_for"} and $self->has_returns_list || $self->has_returns_scalar
!ll&&!rl&&r
19326
$self->has_returns_list or $self->has_returns_scalar
l!l&&r!l&&!r
6032
MC/DC66%2/3
$self->{"_is_signature_for"} and $self->has_returns_list || $self->has_returns_scalar
$self->{"_is_signature_for"} $self->has_returns_list $self->has_returns_scalar
Truth table75%3/4
A and B or C
A= $self->{"_is_signature_for"}B= $self->has_returns_listC= $self->has_returns_scalar
ABCresult
0XX0
1000
11X1
1011
890 6 my $call = sprintf '$__NEXT__->( %s )', $list;
891 6 return $self->_make_typed_return_expression( $call );
892 }
893 elsif ( $list eq '@_' ) {
894 8 return sprintf 'goto( $__NEXT__ )';
895 }
896 ▶ elsif ( $args{allow_full_statements} and not ( $args{is_early} or not exists $args{is_early} ) ) {
Condition33%2/6
$args{"allow_full_statements"} and not $args{"is_early"} || !exists $args{"is_early"}
!ll&&!rl&&r
0043
$args{'is_early'} || !exists $args{'is_early'}
l!l&&r!l&&!r
0043
MC/DC0%0/3
$args{"allow_full_statements"} and not $args{"is_early"} || !exists $args{"is_early"}
$args{"allow_full_statements"} $args{'is_early'} !exists $args{'is_early'}
Truth table25%1/4
A and not(B || not(C))
A= $args{"allow_full_statements"}B= $args{'is_early'}C= !exists $args{'is_early'}
ABCresult
0XX0
11X0
1010
1001
897 # We are allowed to return full statements, not
898 # forced to use do {...} to make an expression.
899 43 return sprintf '@_ = ( %s ); goto $__NEXT__', $list;
900 }
901 else {
902 0 return sprintf 'do { @_ = ( %s ); goto $__NEXT__ }', $list;
903 }
904 }
905 ▶ elsif ( $args{is_early} or not exists $args{is_early} ) {
Condition66%2/3
$args{"is_early"} or not exists $args{"is_early"}
l!l&&r!l&&!r
190270
MC/DC50%1/2
$args{"is_early"} or not exists $args{"is_early"}
$args{"is_early"} not exists $args{"is_early"}
Truth table66%2/3
A or not(B)
A= $args{"is_early"}B= not exists $args{"is_early"}
ABresult
1X1
011
000
906 19 return sprintf 'return( %s )', $list;
907 }
908 else {
909 270 return sprintf '( %s )', $list;
910 }
911 }
912  
913 6 ▶sub _make_typed_return_expression {
Subroutine _make_typed_return_expression: called CC=3 SCAR=12.0
914 6 my ( $self, $expr ) = @_;
915  
916 6 ▶ return sprintf 'wantarray ? %s : defined( wantarray ) ? %s : do { %s; undef; }',
Branch: 2 branches
BranchTrueFalseTotal
$self->has_returns_list ? : 6 0 6
$self->has_returns_scalar ? : 6 0 6
917 $self->has_returns_list ? $self->_make_typed_list_return_expression( $expr, $self->returns_list ) : $expr,
918 $self->has_returns_scalar ? $self->_make_typed_scalar_return_expression( $expr, $self->returns_scalar ) : $expr,
919 $expr;
920 }
921  
922 6 ▶sub _make_typed_scalar_return_expression {
Subroutine _make_typed_scalar_return_expression: called CC=3 SCAR=11.3
923 6 my ( $self, $expr, $constraint ) = @_;
924  
925 6 ▶ if ( $constraint->{uniq} == Any->{uniq} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($constraint->{'uniq'} == &Any()->{'uniq'}) { } 0 6 6
elsif ($constraint->can_be_inlined) { } 5 1 6
926 0 return $expr;
927 }
928 elsif ( $constraint->can_be_inlined ) {
929 5 return sprintf 'do { my $__RETURN__ = %s; ( %s ) ? $__RETURN__ : %s }',
930 $expr,
931 $constraint->inline_check( '$__RETURN__' ),
932 $self->_make_constraint_fail( constraint => $constraint, varname => '$__RETURN__' );
933 }
934 else {
935 1 return sprintf 'do { my $__RETURN__ = %s; $return_check_for_scalar->( $__RETURN__ ) ? $__RETURN__ : %s }',
936 $expr,
937 $self->_make_constraint_fail( constraint => $constraint, varname => '$__RETURN__' );
938 }
939 }
940  
941 6 ▶sub _make_typed_list_return_expression {
Subroutine _make_typed_list_return_expression: called CC=4 SCAR=14.0
942 6 my ( $self, $expr, $constraint ) = @_;
943  
944 6 my $slurp_into = Slurpy->of( $constraint )->my_slurp_into;
945 6 ▶ my $varname = $slurp_into eq 'HASH' ? '%__RETURN__' : '@__RETURN__';
Branch: 1 branch
BranchTrueFalseTotal
$slurp_into eq 'HASH' ? : 1 5 6
946  
947 6 ▶ if ( $constraint->{uniq} == Any->{uniq} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($constraint->{'uniq'} == &Any()->{'uniq'}) { } 0 6 6
elsif ($constraint->can_be_inlined) { } 5 1 6
948 0 return $expr;
949 }
950 elsif ( $constraint->can_be_inlined ) {
951 5 return sprintf 'do { my %s = %s; my $__RETURN__ = \ %s; ( %s ) ? %s : %s }',
952 $varname,
953 $expr,
954 $varname,
955 $constraint->inline_check( '$__RETURN__' ),
956 $varname,
957 $self->_make_constraint_fail( constraint => $constraint, varname => '$__RETURN__', display_var => "\\$varname" );
958 }
959 else {
960 1 return sprintf 'do { my %s = %s; my $__RETURN__ = \ %s; $return_check_for_list->( $__RETURN__ ) ? %s : %s }',
961 $varname,
962 $expr,
963 $varname,
964 $varname,
965 $self->_make_constraint_fail( constraint => $constraint, varname => '$__RETURN__', display_var => "\\$varname" );
966 }
967 }
968  
969 505 ▶sub _make_general_fail {
Subroutine _make_general_fail: called CC=2 SCAR=6.9
970 505 my ( $self, %args ) = ( shift, @_ );
971  
972 return sprintf(
973 $self->has_on_die
974 ? q{return( "Error::TypeTiny"->throw_cb( $__ON_DIE__, message => %s ) )}
975 : q{"Error::TypeTiny"->throw( message => %s )},
976 $args{message},
977 505 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$self->has_on_die ? : 4 501 505
978 }
979  
980 733 ▶sub _make_constraint_fail {
Subroutine _make_constraint_fail: called CC=3 SCAR=11.1
981 733 my ( $self, %args ) = ( shift, @_ );
982  
983 return sprintf(
984 $self->has_on_die
985 ? q{return( Type::Tiny::_failed_check( %d, %s, %s, varname => %s, on_die => $__ON_DIE__ ) )}
986 : q{Type::Tiny::_failed_check( %d, %s, %s, varname => %s )},
987 $args{constraint}{uniq},
988 B::perlstring( $args{constraint}->display_name ),
989 $args{varname},
990 733 ▶ B::perlstring( $args{display_var} || $args{varname} ),
Branch: 1 branch
BranchTrueFalseTotal
$self->has_on_die ? : 8 725 733
Condition66%2/3
$args{'display_var'} || $args{'varname'}
l!l&&r!l&&!r
72760
MC/DC0%0/2
$args{'display_var'} || $args{'varname'}
$args{'display_var'} $args{'varname'}
Truth table66%2/3
A || B
A= $args{'display_var'}B= $args{'varname'}
ABresult
1X1
011
000
991 );
992 }
993  
994 306 ▶sub _make_count_fail {
Subroutine _make_count_fail: called CC=9 SCAR=22.3
995 306 my ( $self, %args ) = ( shift, @_ );
996  
997 306 my @counts;
998 306 ▶ if ( $args{got} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"got"}) 306 0 306
999 push @counts, sprintf(
1000 'got => %s',
1001 $args{got},
1002 306 );
1003 }
1004 306 for my $c ( qw/ minimum maximum / ) {
1005 612 ▶ is_Int( $args{$c} ) or next;
Branch: 1 branch
BranchTrueFalseTotal
is_Int($args{$c}) or next 224 388 612
1006 push @counts, sprintf(
1007 '%s => %s',
1008 $c,
1009 224 $args{$c},
1010 );
1011 }
1012  
1013 306 ▶ if ( my $package = $self->package and my $subname = $self->subname ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $package = $self->package and my $subname = $self->subname) 306 0 306
Condition33%1/3
my $package = $self->package and my $subname = $self->subname
!ll&&!rl&&r
00306
MC/DC0%0/2
my $package = $self->package and my $subname = $self->subname
my $package = $self->package my $subname = $self->subname
Truth table33%1/3
A and B
A= my $package = $self->packageB= my $subname = $self->subname
ABresult
0X0
100
111
1014 306 ▶ push @counts, sprintf(
Branch: 1 branch
BranchTrueFalseTotal
if $package ne "__ANON__" and $subname ne "__ANON__" 116 190 306
Condition100%3/3
$package ne "__ANON__" and $subname ne "__ANON__"
!ll&&!rl&&r
41149116
MC/DC100%2/2
$package ne "__ANON__" and $subname ne "__ANON__"
$package ne "__ANON__" $subname ne "__ANON__"
Truth table100%3/3
A and B
A= $package ne "__ANON__"B= $subname ne "__ANON__"
ABresult
0X0
100
111
1015 'target => %s',
1016 B::perlstring( "$package\::$subname" ),
1017 ) if $package ne '__ANON__' && $subname ne '__ANON__';
1018 }
1019  
1020 306 ▶ return sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$self->has_on_die ? : 6 300 306
1021 $self->has_on_die
1022 ? q{return( "Error::TypeTiny::WrongNumberOfParameters"->throw_cb( $__ON_DIE__, %s ) )}
1023 : q{"Error::TypeTiny::WrongNumberOfParameters"->throw( %s )},
1024 join( q{, }, @counts ),
1025 );
1026 }
1027  
1028 59 ▶sub class_attributes {
Subroutine class_attributes: called CC=2 SCAR=7.1
Pod documented
1029 59 my $self = shift;
1030 59 ▶ $self->{class_attributes} ||= $self->_build_class_attributes;
Condition66%2/3
$self->{"class_attributes"} ||= $self->_build_class_attributes
l!l&&r!l&&!r
16430
MC/DC0%0/2
$self->{"class_attributes"} ||= $self->_build_class_attributes
$self->{"class_attributes"} $self->_build_class_attributes
Truth table66%2/3
A ||= B
A= $self->{"class_attributes"}B= $self->_build_class_attributes
ABresult
1X1
011
000
1031 }
1032  
1033 43 ▶sub _build_class_attributes {
Subroutine _build_class_attributes: called CC=7 SCAR=19.5
1034 43 my $self = shift;
1035 43 my %predicates;
1036 my %getters;
1037  
1038 43 my @parameters = @{ $self->parameters };
1039 43 ▶ if ( $self->has_slurpy ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_slurpy) 1 42 43
1040 1 push @parameters, $self->slurpy;
1041 }
1042  
1043 43 for my $parameter ( @parameters ) {
1044  
1045 86 my $name = $parameter->name;
1046 86 ▶ if ( my $predicate = $parameter->predicate ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $predicate = $parameter->predicate) 27 59 86
1047 27 ▶ $predicate =~ /^[^0-9\W]\w*$/
Branch: 1 branch
BranchTrueFalseTotal
$predicate =~ /^[^0-9\W]\w*$/ or $self->_croak(qq[Bad accessor name: "$predicate"]) 27 0 27
1048 or $self->_croak( "Bad accessor name: \"$predicate\"" );
1049 27 $predicates{$predicate} = $name;
1050 }
1051 86 ▶ if ( my $getter = $parameter->getter ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $getter = $parameter->getter) 86 0 86
1052 86 ▶ $getter =~ /^[^0-9\W]\w*$/
Branch: 1 branch
BranchTrueFalseTotal
$getter =~ /^[^0-9\W]\w*$/ or $self->_croak(qq[Bad accessor name: "$getter"]) 84 2 86
1053 or $self->_croak( "Bad accessor name: \"$getter\"" );
1054 84 $getters{$getter} = $name;
1055 }
1056 }
1057  
1058 return {
1059 41 exists_predicates => \%predicates,
1060 getters => \%getters,
1061 };
1062 }
1063  
1064 43 ▶sub make_class {
Subroutine make_class: called CC=4 SCAR=16.4
Pod documented
1065 43 my $self = shift;
1066
1067 43 ▶ my $env = uc( $ENV{PERL_TYPE_PARAMS_XS} || 'XS' );
Condition50%1/2
$ENV{'PERL_TYPE_PARAMS_XS'} || 'XS'
l!l
043
MC/DC0%0/1
$ENV{'PERL_TYPE_PARAMS_XS'} || 'XS'
$ENV{'PERL_TYPE_PARAMS_XS'}
Truth table50%1/2
A
A= $ENV{'PERL_TYPE_PARAMS_XS'}
Aresult
11
00
1068 43 ▶ if ( $env eq 'PP' or $ENV{PERL_ONLY} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($env eq "PP" or $ENV{"PERL_ONLY"}) 0 43 43
Condition33%1/3
$env eq "PP" or $ENV{"PERL_ONLY"}
l!l&&r!l&&!r
0043
MC/DC0%0/2
$env eq "PP" or $ENV{"PERL_ONLY"}
$env eq "PP" $ENV{"PERL_ONLY"}
Truth table33%1/3
A or B
A= $env eq "PP"B= $ENV{"PERL_ONLY"}
ABresult
1X1
011
000
1069 0 $self->make_class_pp;
1070 }
1071  
1072 43 $self->make_class_xs;
1073 }
1074  
1075 43 ▶sub make_class_xs {
Subroutine make_class_xs: called CC=2 SCAR=7.0
Pod documented
1076 43 my $self = shift;
1077  
1078 43 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Class::XSAccessor; "Class::XSAccessor"->VERSION("1.17"); 1 } } or return $self->make_class_pp 43 0 43
1079 43 require Class::XSAccessor;
1080 43 'Class::XSAccessor'->VERSION( '1.17' );
1081 43 1;
1082 } or return $self->make_class_pp;
1083  
1084 43 my $attr = $self->class_attributes;
1085  
1086 41 'Class::XSAccessor'->import(
1087 class => $self->bless,
1088 replace => 1,
1089 %$attr,
1090 );
1091
1092 41 $self->make_extra_methods;
1093 }
1094  
1095 0 ▶sub make_class_pp {
Subroutine make_class_pp: not called CC=2 SCAR=17.9
Pod documented
1096 0 my $self = shift;
1097  
1098 0 my $code = $self->make_class_pp_code;
1099 0 do {
1100 0 local $@;
1101 0 ▶ eval( $code ) or die( $@ );
Branch: 1 branch
BranchTrueFalseTotal
eval $code or die $@ 0 0 0
1102 };
1103
1104 0 $self->make_extra_methods;
1105 }
1106  
1107 58 ▶sub make_class_pp_code {
Subroutine make_class_pp_code: called CC=6 SCAR=17.9
Pod documented
1108 58 my $self = shift;
1109  
1110 58 ▶ return ''
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_named and $self->bless and not $self->named_to_list 42 16 58
Condition83%5/6
$self->is_named and $self->bless and not $self->named_to_list
!ll&&!rl&&r
35716
$self->is_named and $self->bless
!ll&&!rl&&r
35023
MC/DC66%2/3
$self->is_named and $self->bless and not $self->named_to_list
$self->is_named $self->bless not $self->named_to_list
Truth table75%3/4
A and B and not(C)
A= $self->is_namedB= $self->blessC= not $self->named_to_list
ABCresult
0XX0
10X0
1100
1111
1111 unless $self->is_named && $self->bless && !$self->named_to_list;
1112  
1113 16 my $coderef = $self->_new_code_accumulator;
1114 16 my $attr = $self->class_attributes;
1115  
1116 16 $coderef->add_line( '{' );
1117 16 $coderef->{indent} = "\t";
1118 16 $coderef->add_line( sprintf( 'package %s;', $self->bless ) );
1119 16 $coderef->add_line( 'use strict;' );
1120 16 $coderef->add_line( 'no warnings;' );
1121  
1122 16 for my $function ( sort keys %{ $attr->{getters} } ) {
1123 34 my $slot = $attr->{getters}{$function};
1124 34 $coderef->add_line( sprintf(
1125 'sub %s { $_[0]{%s} }',
1126 $function,
1127 B::perlstring( $slot ),
1128 ) );
1129 }
1130  
1131 16 for my $function ( sort keys %{ $attr->{exists_predicates} } ) {
1132 12 my $slot = $attr->{exists_predicates}{$function};
1133 12 $coderef->add_line( sprintf(
1134 'sub %s { exists $_[0]{%s} }',
1135 $function,
1136 B::perlstring( $slot ),
1137 ) );
1138 }
1139
1140 16 $coderef->add_line( '1;' );
1141 16 $coderef->{indent} = "";
1142 16 $coderef->add_line( '}' );
1143  
1144 16 return $coderef->code;
1145 }
1146  
1147 41 ▶sub make_extra_methods {
Subroutine make_extra_methods: called CC=18 SCAR=32.7
Pod undocumented
1148 41 my $self = shift;
1149  
1150 41 my @parameters = @{ $self->parameters };
1151 41 ▶ if ( $self->has_slurpy ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_slurpy) 1 40 41
1152 1 push @parameters, $self->slurpy;
1153 }
1154  
1155 41 my $coderef = $self->_new_code_accumulator;
1156 41 $coderef->add_line( '{' );
1157 41 $coderef->{indent} = "\t";
1158 41 $coderef->add_line( sprintf( 'package %s;', $self->bless ) );
1159 41 $coderef->add_line( 'use strict;' );
1160 41 $coderef->add_line( 'no warnings;' );
1161
1162 41 $coderef->add_line( 'my @FIELDS = (' );
1163 41 for my $p ( @parameters ) {
1164 84 $coderef->add_line( "\t" . B::perlstring( $p->name ) . "," )
1165 }
1166 41 $coderef->add_line( ');' );
1167
1168 41 my @enum;
1169 41 $coderef->add_line( 'my %FIELDS = (' );
1170 41 for my $p ( @parameters ) {
1171 84 $coderef->add_line( "\t" . B::perlstring( $p->name ) . " => " . B::perlstring( $p->name ) . "," );
1172 84 for my $p2 ( $p->_all_aliases($self) ) {
1173 15 $coderef->add_line( "\t" . B::perlstring( $p2 ) . " => " . B::perlstring( $p->name ) . "," );
1174 }
1175 84 push @enum, $p->name, $p->_all_aliases($self);
1176 }
1177 41 $coderef->add_line( ');' );
1178 41 my $enum = ArrayRef[ Enum[ @enum ] ];
1179
1180 41 $coderef->add_line( 'sub __TO_LIST__ {' );
1181 41 $coderef->add_line( "\t" . 'my ( $arg, $fields ) = @_;' );
1182 41 $coderef->add_line( "\t" . 'return map $arg->{$_}, @FIELDS if not defined $fields;' );
1183 41 ▶ if ( ( defined $self->strictness and $self->strictness eq 1 ) or not $self->has_strictness ){
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->strictness and $self->strictness eq 1 or not $self->has_strictness) { } 41 0 41
elsif ($self->strictness) { } 0 0 0
Condition33%2/6
defined $self->strictness and $self->strictness eq 1 or not $self->has_strictness
l!l&&r!l&&!r
0410
defined $self->strictness and $self->strictness eq 1
!ll&&!rl&&r
4100
MC/DC0%0/3
defined $self->strictness and $self->strictness eq 1 or not $self->has_strictness
defined $self->strictness $self->strictness eq 1 not $self->has_strictness
Truth table20%1/5
A and B or not(C)
A= defined $self->strictnessB= $self->strictness eq 1C= not $self->has_strictness
ABCresult
11X1
0X11
1011
0X00
1000
1184 41 $coderef->add_line( "\t" . $enum->inline_assert( '$fields' ) );
1185 }
1186 elsif ( $self->strictness ) {
1187 0 $coderef->add_line( "\t" . sprintf( 'if ( %s ) { %s }', $self->strictness, $enum->inline_assert( '$fields' ) ) );
1188 }
1189 41 $coderef->add_line( "\t" . 'return map $arg->{$FIELDS{$_}}, @$fields;' );
1190 41 $coderef->add_line( '}' );
1191  
1192 41 $coderef->add_line( 'sub __TO_ARRAYREF__ {' );
1193 41 $coderef->add_line( "\t" . 'my ( $arg, $fields ) = @_;' );
1194 41 $coderef->add_line( "\t" . 'return [ map $arg->{$_}, @FIELDS ] if not defined $fields;' );
1195 41 ▶ if ( ( defined $self->strictness and $self->strictness eq 1 ) or not $self->has_strictness ){
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->strictness and $self->strictness eq 1 or not $self->has_strictness) { } 41 0 41
elsif ($self->strictness) { } 0 0 0
Condition33%2/6
defined $self->strictness and $self->strictness eq 1 or not $self->has_strictness
l!l&&r!l&&!r
0410
defined $self->strictness and $self->strictness eq 1
!ll&&!rl&&r
4100
MC/DC0%0/3
defined $self->strictness and $self->strictness eq 1 or not $self->has_strictness
defined $self->strictness $self->strictness eq 1 not $self->has_strictness
Truth table20%1/5
A and B or not(C)
A= defined $self->strictnessB= $self->strictness eq 1C= not $self->has_strictness
ABCresult
11X1
0X11
1011
0X00
1000
1196 41 $coderef->add_line( "\t" . $enum->inline_assert( '$fields' ) );
1197 }
1198 elsif ( $self->strictness ) {
1199 0 $coderef->add_line( "\t" . sprintf( 'if ( %s ) { %s }', $self->strictness, $enum->inline_assert( '$fields' ) ) );
1200 }
1201 41 $coderef->add_line( "\t" . 'return [ map $arg->{$FIELDS{$_}}, @$fields ];' );
1202 41 $coderef->add_line( '}' );
1203  
1204 41 $coderef->add_line( 'sub __TO_HASHREF__ {' );
1205 41 $coderef->add_line( "\t" . 'my ( $arg, $fields ) = @_;' );
1206 41 $coderef->add_line( "\t" . 'return +{ map { ; $_ => $arg->{$_} } @FIELDS } if not defined $fields;' );
1207 41 ▶ if ( ( defined $self->strictness and $self->strictness eq 1 ) or not $self->has_strictness ){
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->strictness and $self->strictness eq 1 or not $self->has_strictness) { } 41 0 41
elsif ($self->strictness) { } 0 0 0
Condition33%2/6
defined $self->strictness and $self->strictness eq 1 or not $self->has_strictness
l!l&&r!l&&!r
0410
defined $self->strictness and $self->strictness eq 1
!ll&&!rl&&r
4100
MC/DC0%0/3
defined $self->strictness and $self->strictness eq 1 or not $self->has_strictness
defined $self->strictness $self->strictness eq 1 not $self->has_strictness
Truth table20%1/5
A and B or not(C)
A= defined $self->strictnessB= $self->strictness eq 1C= not $self->has_strictness
ABCresult
11X1
0X11
1011
0X00
1000
1208 41 $coderef->add_line( "\t" . $enum->inline_assert( '$fields' ) );
1209 }
1210 elsif ( $self->strictness ) {
1211 0 $coderef->add_line( "\t" . sprintf( 'if ( %s ) { %s }', $self->strictness, $enum->inline_assert( '$fields' ) ) );
1212 }
1213 41 $coderef->add_line( "\t" . 'return +{ map { ; $_ => $arg->{$FIELDS{$_}} } @$fields };' );
1214 41 $coderef->add_line( '}' );
1215
1216 41 $coderef->add_line( '1;' );
1217 41 $coderef->{indent} = "";
1218 41 $coderef->add_line( '}' );
1219  
1220 41 my $code = $coderef->code;
1221 41 local $@;
1222 0 ▶ eval( $code ) or die( $@ );
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine BEGIN: called CC=1 SCAR=0.4
Branch: 8 branches
BranchTrueFalseTotal
eval $code or die $@ 41 0 41
unless defined $fields 4 1 5
Type::Tiny::XS::AUTO::TC4($fields) or _failed_check(48, "ArrayRef[Enum[\"first_number\",\"x\",\"second_number\",\"y\"]]", $fields, "exception_class", "Error::TypeTiny::Assertion") 1 4 5
unless defined $fields 3 1 4
Type::Tiny::XS::AUTO::TC4($fields) or _failed_check(48, "ArrayRef[Enum[\"first_number\",\"x\",\"second_number\",\"y\"]]", $fields, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
unless defined $fields 0 0 0
Type::Tiny::XS::AUTO::TC4($fields) or _failed_check(48, "ArrayRef[Enum[\"first_number\",\"x\",\"second_number\",\"y\"]]", $fields, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
unless defined $fields 0 0 0
1223
1224 Type::Tiny::_install_overloads(
1225 $self->bless,
1226 7 ▶ 'bool' => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
1227 41 '@{}' => '__TO_ARRAYREF__',
1228 'fallback' => !!1,
1229 );
1230 }
1231  
1232 305 ▶sub return_wanted {
Subroutine return_wanted: called CC=4 SCAR=13.9
Pod documented
1233 306 my $self = shift;
1234 303 my $coderef = $self->coderef;
1235  
1236 300 ▶ if ( $self->{want_source} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'want_source'}) { } 10 293 303
elsif ($self->{'want_object'}) { } 4 289 293
elsif ($self->{'want_details'}) { } 63 231 294
1237 10 return $coderef->code;
1238 }
1239 elsif ( $self->{want_object} ) { # undocumented for now
1240 4 return $self;
1241 }
1242 elsif ( $self->{want_details} ) {
1243 return {
1244 min_args => $self->{min_args},
1245 max_args => $self->{max_args},
1246 environment => $coderef->{env},
1247 68 source => $coderef->code,
1248 closure => $coderef->compile,
1249 named => $self->is_named,
1250 class_definition => $self->make_class_pp_code,
1251 };
1252 }
1253  
1254 232 return $coderef->compile;
1255 }
1256  
1257 68 1;
1258  
1259 __END__
« blib/lib/Type/Library.pm ↑ Summary blib/lib/Type/Coercion.pm »