lib/Catalyst/Action.pm

filter: Statementstmt 90.0% 190 / 211 Branchbran 76.7% 89 / 116 Conditioncond 66.1% 43 / 65 MC/DCmcdc 47.3% 18 / 38 Subroutinesub 93.3% 28 / 30 Podpod 100% 13 / 13 totaltotal 80.5% 381 / 473 CC 88 SCAR 24.7
CC
88
Cov
82%
resolve_type_constraint
27.8
_build_number_of_args_constraints
19.6
_build_number_of_capture_constraints
13.8
CRAP 11.9
« lib/Catalyst/Request.pm ↑ Summary lib/Catalyst/Test.pm »
1 package Catalyst::Action;
2  
3 =head1 NAME
4  
5 Catalyst::Action - Catalyst Action
6  
7 =head1 SYNOPSIS
8  
9 <form action="[%c.uri_for(c.action)%]">
10  
11 $c->forward( $action->private_path );
12  
13 =head1 DESCRIPTION
14  
15 This class represents a Catalyst Action. You can access the object for the
16 currently dispatched action via $c->action. See the L<Catalyst::Dispatcher>
17 for more information on how actions are dispatched. Actions are defined in
18 L<Catalyst::Controller> subclasses.
19  
20 =cut
21  
22 155 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 155 ▶use Scalar::Util 'looks_like_number', 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 155 ▶use Moose::Util::TypeConstraints ();
Subroutine BEGIN: called CC=1 SCAR=0.0
25 155 with 'MooseX::Emulate::Class::Accessor::Fast';
26 155 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 155 has class => (is => 'rw');
29 155 has instance => (is=>'ro', required=>0, predicate=>'has_instance');
30 155 has namespace => (is => 'rw');
31 155 has 'reverse' => (is => 'rw');
32 155 has attributes => (is => 'rw');
33 155 has name => (is => 'rw');
34 155 has code => (is => 'rw');
35 has private_path => (
36 reader => 'private_path',
37 isa => 'Str',
38 lazy => 1,
39 required => 1,
40 0 ▶ default => sub { '/'.shift->reverse },
Subroutine __ANON__: not called CC=1 SCAR=6.9
41 155 );
42  
43 155 has number_of_args => (
44 is=>'ro',
45 init_arg=>undef,
46 isa=>'Int|Undef',
47 required=>1,
48 lazy=>1,
49 builder=>'_build_number_of_args');
50  
51 1327 ▶ sub _build_number_of_args {
Subroutine _build_number_of_args: called CC=5 SCAR=16.1
52 1327 my $self = shift;
53 1327 ▶ if( ! exists $self->attributes->{Args} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not exists $self->attributes->{'Args'}) { } 859 468 1327
elsif (not defined $self->attributes->{'Args'}[0]) { } 16 452 468
elsif (scalar @{$self->attributes->{'Args'};} == 1 and &looks_like_number($self->attributes->{'Args'}[0])) { } 426 26 452
54 # When 'Args' does not exist, that means we want 'any number of args'.
55 859 return undef;
56 } elsif(!defined($self->attributes->{Args}[0])) {
57 # When its 'Args' that internal cue for 'unlimited'
58 16 return undef;
59 ▶ } elsif(
Condition66%2/3
scalar @{$self->attributes->{"Args"};} == 1 and &looks_like_number($self->attributes->{"Args"}[0])
!ll&&!rl&&r
026426
MC/DC50%1/2
scalar @{$self->attributes->{"Args"};} == 1 and &looks_like_number($self->attributes->{"Args"}[0])
scalar @{$self->attributes->{"Args"};} == 1 &looks_like_number($self->attributes->{"Args"}[0])
Truth table66%2/3
A and B
A= scalar @{$self->attributes->{"Args"};} == 1B= &looks_like_number($self->attributes->{"Args"}[0])
ABresult
0X0
100
111
60 452 scalar(@{$self->attributes->{Args}}) == 1 &&
61 looks_like_number($self->attributes->{Args}[0])
62 ) {
63 # 'Old school' numbered args (is allowed to be undef as well)
64 426 return $self->attributes->{Args}[0];
65 } else {
66 # New hotness named arg constraints
67 26 return $self->number_of_args_constraints;
68 }
69 }
70  
71 56 ▶sub normalized_arg_number {
Subroutine normalized_arg_number: called CC=1 SCAR=0.0
Pod documented
72 56 return $_[0]->number_of_args;
73 }
74  
75 6447 ▶sub comparable_arg_number {
Subroutine comparable_arg_number: called CC=2 SCAR=6.9
Pod documented
76 6447 ▶ return defined($_[0]->number_of_args) ? $_[0]->number_of_args : ~0;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->number_of_args ? : 4366 2081 6447
77 }
78  
79 155 has number_of_args_constraints => (
80 is=>'ro',
81 isa=>'Int|Undef',
82 init_arg=>undef,
83 required=>1,
84 lazy=>1,
85 builder=>'_build_number_of_args_constraints');
86  
87 26 ▶ sub _build_number_of_args_constraints {
Subroutine _build_number_of_args_constraints: called CC=15 SCAR=29.7
88 26 my $self = shift;
89 26 ▶ return unless $self->has_args_constraints;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_args_constraints 0 26 26
90  
91 # If there is one constraint and its a ref, we need to decide
92 # if this number 'unknown' number or if the ref allows us to
93 # determine a length.
94  
95 26 ▶ if(scalar @{$self->args_constraints} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$self->args_constraints;} == 1) { } 24 2 26
96 24 my $tc = $self->args_constraints->[0];
97 24 ▶ if(
Branch: 2 branches
BranchTrueFalseTotal
if ($tc->can('is_strictly_a_type_of') and $tc->is_strictly_a_type_of('Tuple')) { } 2 22 24
elsif ($tc->is_a_type_of('Ref')) { } 1 21 22
Condition100%3/3
$tc->can("is_strictly_a_type_of") and $tc->is_strictly_a_type_of("Tuple")
!ll&&!rl&&r
2202
MC/DC100%2/2
$tc->can("is_strictly_a_type_of") and $tc->is_strictly_a_type_of("Tuple")
$tc->can("is_strictly_a_type_of") $tc->is_strictly_a_type_of("Tuple")
Truth table100%3/3
A and B
A= $tc->can("is_strictly_a_type_of")B= $tc->is_strictly_a_type_of("Tuple")
ABresult
0X0
100
111
98 $tc->can('is_strictly_a_type_of') &&
99 $tc->is_strictly_a_type_of('Tuple'))
100 {
101 2 ▶ my @parameters = @{ $tc->parameters||[] };
Condition50%1/2
$tc->parameters || []
l!l
20
MC/DC0%0/1
$tc->parameters || []
$tc->parameters
Truth table50%1/2
A
A= $tc->parameters
Aresult
11
00
102 2 my $final = $parameters[-1];
103 2 ▶ if ( defined $final ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $final) 2 0 2
104 2 ▶ if ( blessed $final ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($final)) { } 2 0 2
105 # modern form of slurpy
106 2 ▶ if ($final->can('is_strictly_a_type_of') && $final->is_strictly_a_type_of('Slurpy')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($final->can("is_strictly_a_type_of") and $final->is_strictly_a_type_of("Slurpy")) 1 1 2
Condition66%2/3
$final->can("is_strictly_a_type_of") and $final->is_strictly_a_type_of("Slurpy")
!ll&&!rl&&r
011
MC/DC50%1/2
$final->can("is_strictly_a_type_of") and $final->is_strictly_a_type_of("Slurpy")
$final->can("is_strictly_a_type_of") $final->is_strictly_a_type_of("Slurpy")
Truth table66%2/3
A and B
A= $final->can("is_strictly_a_type_of")B= $final->is_strictly_a_type_of("Slurpy")
ABresult
0X0
100
111
107 1 return undef;
108 }
109 }
110 else {
111 # old form of slurpy
112 0 ▶ if (ref $final eq 'HASH' && $final->{slurpy}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $final eq "HASH" and $final->{"slurpy"}) 0 0 0
Condition0%0/3
ref $final eq "HASH" and $final->{"slurpy"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $final eq "HASH" and $final->{"slurpy"}
ref $final eq "HASH" $final->{"slurpy"}
Truth table0%0/3
A and B
A= ref $final eq "HASH"B= $final->{"slurpy"}
ABresult
0X0
100
111
113 0 return undef;
114 }
115 }
116 }
117 1 return scalar @parameters;
118 } elsif($tc->is_a_type_of('Ref')) {
119 1 return undef;
120 } else {
121 21 return 1; # Its a normal 1 arg type constraint.
122 }
123 } else {
124 # We need to loop through and error on ref types. We don't allow a ref type
125 # in the middle.
126 2 my $total = 0;
127 2 foreach my $tc( @{$self->args_constraints}) {
128 4 ▶ if($tc->is_a_type_of('Ref')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tc->is_a_type_of('Ref')) { } 0 4 4
129 0 die "$tc is a Ref type constraint. You cannot mix Ref and non Ref type constraints in Args for action ${\$self->reverse}";
130 } else {
131 4 ++$total;
132 }
133 }
134 2 return $total;
135 }
136 }
137  
138 155 has args_constraints => (
139 is=>'ro',
140 init_arg=>undef,
141 traits=>['Array'],
142 isa=>'ArrayRef',
143 required=>1,
144 lazy=>1,
145 builder=>'_build_args_constraints',
146 handles => {
147 has_args_constraints => 'count',
148 args_constraint_count => 'count',
149 all_args_constraints => 'elements',
150 });
151  
152 575 ▶ sub _build_args_constraints {
Subroutine _build_args_constraints: called CC=7 SCAR=19.5
153 575 my $self = shift;
154 575 ▶ my @arg_protos = @{$self->attributes->{Args}||[]};
Condition100%2/2
$self->attributes->{'Args'} || []
l!l
260315
MC/DC100%1/1
$self->attributes->{'Args'} || []
$self->attributes->{'Args'}
Truth table100%2/2
A
A= $self->attributes->{'Args'}
Aresult
11
00
155  
156 575 ▶ return [] unless scalar(@arg_protos);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @arg_protos 315 260 575
157 260 ▶ return [] unless defined($arg_protos[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg_protos[0] 16 244 260
158  
159 # If there is only one arg and it looks like a number
160 # we assume its 'classic' and the number is the number of
161 # constraints.
162 244 my @args = ();
163 244 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @arg_protos == 1 and &looks_like_number($arg_protos[0])) { } 218 26 244
Condition66%2/3
scalar @arg_protos == 1 and &looks_like_number($arg_protos[0])
!ll&&!rl&&r
026218
MC/DC50%1/2
scalar @arg_protos == 1 and &looks_like_number($arg_protos[0])
scalar @arg_protos == 1 &looks_like_number($arg_protos[0])
Truth table66%2/3
A and B
A= scalar @arg_protos == 1B= &looks_like_number($arg_protos[0])
ABresult
0X0
100
111
164 scalar(@arg_protos) == 1 &&
165 looks_like_number($arg_protos[0])
166 ) {
167 218 return \@args;
168 } else {
169 @args =
170 26 ▶ map { my @tc = $self->resolve_type_constraint($_); scalar(@tc) ? @tc : die "$_ is not a constraint!" }
Branch: 1 branch
BranchTrueFalseTotal
scalar @tc ? : 26 0 26
171 @arg_protos;
172 }
173 26 return \@args;
174 }
175  
176 155 has number_of_captures_constraints => (
177 is=>'ro',
178 isa=>'Int|Undef',
179 init_arg=>undef,
180 required=>1,
181 lazy=>1,
182 builder=>'_build_number_of_capture_constraints');
183  
184 6 ▶ sub _build_number_of_capture_constraints {
Subroutine _build_number_of_capture_constraints: called CC=11 SCAR=26.3
185 6 my $self = shift;
186 6 ▶ return unless $self->has_captures_constraints;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_captures_constraints 0 6 6
187  
188 # If there is one constraint and its a ref, we need to decide
189 # if this number 'unknown' number or if the ref allows us to
190 # determine a length.
191  
192 6 ▶ if(scalar @{$self->captures_constraints} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$self->captures_constraints;} == 1) { } 5 1 6
193 5 my $tc = $self->captures_constraints->[0];
194 5 ▶ if(
Branch: 2 branches
BranchTrueFalseTotal
if ($tc->can('is_strictly_a_type_of') and $tc->is_strictly_a_type_of('Tuple')) { } 1 4 5
elsif ($tc->is_a_type_of('Ref')) { } 0 4 4
Condition100%3/3
$tc->can("is_strictly_a_type_of") and $tc->is_strictly_a_type_of("Tuple")
!ll&&!rl&&r
131
MC/DC100%2/2
$tc->can("is_strictly_a_type_of") and $tc->is_strictly_a_type_of("Tuple")
$tc->can("is_strictly_a_type_of") $tc->is_strictly_a_type_of("Tuple")
Truth table100%3/3
A and B
A= $tc->can("is_strictly_a_type_of")B= $tc->is_strictly_a_type_of("Tuple")
ABresult
0X0
100
111
195 $tc->can('is_strictly_a_type_of') &&
196 $tc->is_strictly_a_type_of('Tuple'))
197 {
198 1 ▶ my @parameters = @{ $tc->parameters||[]};
Condition50%1/2
$tc->parameters || []
l!l
10
MC/DC0%0/1
$tc->parameters || []
$tc->parameters
Truth table50%1/2
A
A= $tc->parameters
Aresult
11
00
199 1 ▶ if( defined($parameters[-1]) and exists($parameters[-1]->{slurpy})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parameters[-1] and exists $parameters[-1]{'slurpy'}) { } 0 1 1
Condition33%1/3
defined $parameters[-1] and exists $parameters[-1]{"slurpy"}
!ll&&!rl&&r
010
MC/DC0%0/2
defined $parameters[-1] and exists $parameters[-1]{"slurpy"}
defined $parameters[-1] exists $parameters[-1]{"slurpy"}
Truth table33%1/3
A and B
A= defined $parameters[-1]B= exists $parameters[-1]{"slurpy"}
ABresult
0X0
100
111
200 0 return undef;
201 } else {
202 1 return my $total_params = scalar(@parameters);
203 }
204 } elsif($tc->is_a_type_of('Ref')) {
205 0 die "You cannot use CaptureArgs($tc) in ${\$self->reverse} because we cannot determined the number of its parameters";
206 } else {
207 4 return 1; # Its a normal 1 arg type constraint.
208 }
209 } else {
210 # We need to loop through and error on ref types. We don't allow a ref type
211 # in the middle.
212 1 my $total = 0;
213 1 foreach my $tc( @{$self->captures_constraints}) {
214 2 ▶ if($tc->is_a_type_of('Ref')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tc->is_a_type_of('Ref')) { } 0 2 2
215 0 die "$tc is a Ref type constraint. You cannot mix Ref and non Ref type constraints in CaptureArgs for action ${\$self->reverse}";
216 } else {
217 2 ++$total;
218 }
219 }
220 1 return $total;
221 }
222 }
223  
224 155 has captures_constraints => (
225 is=>'ro',
226 init_arg=>undef,
227 traits=>['Array'],
228 isa=>'ArrayRef',
229 required=>1,
230 lazy=>1,
231 builder=>'_build_captures_constraints',
232 handles => {
233 has_captures_constraints => 'count',
234 captures_constraints_count => 'count',
235 all_captures_constraints => 'elements',
236 });
237  
238 83 ▶ sub _build_captures_constraints {
Subroutine _build_captures_constraints: called CC=7 SCAR=19.6
239 83 my $self = shift;
240 83 ▶ my @arg_protos = @{$self->attributes->{CaptureArgs}||[]};
Condition100%2/2
$self->attributes->{'CaptureArgs'} || []
l!l
6815
MC/DC100%1/1
$self->attributes->{'CaptureArgs'} || []
$self->attributes->{'CaptureArgs'}
Truth table100%2/2
A
A= $self->attributes->{'CaptureArgs'}
Aresult
11
00
241  
242 83 ▶ return [] unless scalar(@arg_protos);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @arg_protos 15 68 83
243 68 ▶ return [] unless defined($arg_protos[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg_protos[0] 0 68 68
244 # If there is only one arg and it looks like a number
245 # we assume its 'classic' and the number is the number of
246 # constraints.
247 68 my @args = ();
248 68 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @arg_protos == 1 and &looks_like_number($arg_protos[0])) { } 62 6 68
Condition66%2/3
scalar @arg_protos == 1 and &looks_like_number($arg_protos[0])
!ll&&!rl&&r
0662
MC/DC50%1/2
scalar @arg_protos == 1 and &looks_like_number($arg_protos[0])
scalar @arg_protos == 1 &looks_like_number($arg_protos[0])
Truth table66%2/3
A and B
A= scalar @arg_protos == 1B= &looks_like_number($arg_protos[0])
ABresult
0X0
100
111
249 scalar(@arg_protos) == 1 &&
250 looks_like_number($arg_protos[0])
251 ) {
252 62 return \@args;
253 } else {
254 @args =
255 6 ▶ map { my @tc = $self->resolve_type_constraint($_); scalar(@tc) ? @tc : die "$_ is not a constraint!" }
Branch: 1 branch
BranchTrueFalseTotal
scalar @tc ? : 6 0 6
256 @arg_protos;
257 }
258  
259 6 return \@args;
260 }
261  
262 32 ▶sub resolve_type_constraint {
Subroutine resolve_type_constraint: called CC=19 SCAR=33.2
Pod documented
263 32 my ($self, $name) = @_;
264  
265 32 ▶ if(defined($name) && blessed($name) && $name->can('check')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name and builtin::blessed($name) and $name->can("check")) 0 32 32
Condition33%2/6
defined $name and builtin::blessed($name) and $name->can("check")
!ll&&!rl&&r
3200
defined $name and builtin::blessed($name)
!ll&&!rl&&r
0320
MC/DC0%0/3
defined $name and builtin::blessed($name) and $name->can("check")
defined $name builtin::blessed($name) $name->can("check")
Truth table25%1/4
A and B and C
A= defined $nameB= builtin::blessed($name)C= $name->can("check")
ABCresult
0XX0
10X0
1100
1111
266 # Its already a TC, good to go.
267 0 return $name;
268 }
269  
270 # This is broken for when there is more than one constraint
271 32 ▶ if($name=~m/::/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /::/) 1 31 32
272 1 ▶ eval "use Type::Registry; 1" || die "Can't resolve type constraint $name without installing Type::Tiny";
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
eval "use Type::Registry; 1" or die "Can't resolve type constraint $name without installing Type::Tiny" 1 0 1
273 1 my $tc = Type::Registry->new->foreign_lookup($name);
274 0 ▶ return defined $tc ? $tc : die "'$name' not a full namespace type constraint in ${\$self->private_path}";
Branch: 1 branch
BranchTrueFalseTotal
defined $tc ? : 1 0 1
275 }
276  
277 31 my @tc = grep { defined $_ } (eval("package ${\$self->class}; $name"));
278  
279 31 ▶ unless(scalar @tc) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @tc) 2 29 31
280 # ok... so its not defined in the package. we need to look at all the roles
281 # and superclasses, look for attributes and figure it out.
282 # Superclasses take precedence;
283  
284 2 ▶ my @supers = $self->class->can('meta') ? map { $_->meta } $self->class->meta->superclasses : ();
Branch: 1 branch
BranchTrueFalseTotal
$self->class->can('meta') ? : 2 0 2
285 2 ▶ my @roles = $self->class->can('meta') ? $self->class->meta->calculate_all_roles : ();
Branch: 1 branch
BranchTrueFalseTotal
$self->class->can('meta') ? : 2 0 2
286  
287 # So look through all the super and roles in order and return the
288 # first type constraint found. We should probably find all matching
289 # type constraints and try to do some sort of resolution.
290  
291 2 foreach my $parent (@roles, @supers) {
292 4 ▶ if(my $m = $parent->get_method($self->name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $m = $parent->get_method($self->name)) 2 2 4
293 2 ▶ if($m->can('attributes')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m->can("attributes")) 2 0 2
294 2 my ($key, $value) = map { $_ =~ /^(.*?)(?:\(\s*(.+?)\s*\))?$/ }
295 4 ▶ grep { $_=~/^Args\(/ or $_=~/^CaptureArgs\(/ }
Condition66%2/3
$_ =~ /^Args\(/ || $_ =~ /^CaptureArgs\(/
l!l&&r!l&&!r
202
MC/DC50%1/2
$_ =~ /^Args\(/ || $_ =~ /^CaptureArgs\(/
$_ =~ /^Args\(/ $_ =~ /^CaptureArgs\(/
Truth table66%2/3
A || B
A= $_ =~ /^Args\(/B= $_ =~ /^CaptureArgs\(/
ABresult
1X1
011
000
296 2 @{$m->attributes};
297 2 ▶ next unless $value eq $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $value eq $name 0 2 2
298 2 my @tc = eval "package ${\$parent->name}; $name";
299 2 ▶ if(scalar(@tc)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @tc) { } 2 0 2
300 2 ▶ return map { ref($_) ? $_ : Moose::Util::TypeConstraints::find_or_parse_type_constraint($_) } @tc;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 2 0 2
301 } else {
302 0 return;
303 }
304 }
305 }
306 }
307  
308 0 my $classes = join(',', $self->class, @roles, @supers);
309 0 die "'$name' not a type constraint in '${\$self->private_path}', Looked in: $classes";
310 }
311  
312 29 ▶ if(scalar(@tc)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @tc) { } 29 0 29
313 29 ▶ return map { ref($_) ? $_ : Moose::Util::TypeConstraints::find_or_parse_type_constraint($_) } @tc;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 28 4 32
314 } else {
315 0 return;
316 }
317 }
318  
319 155 has number_of_captures => (
320 is=>'ro',
321 init_arg=>undef,
322 isa=>'Int',
323 required=>1,
324 lazy=>1,
325 builder=>'_build_number_of_captures');
326  
327 148 ▶ sub _build_number_of_captures {
Subroutine _build_number_of_captures: called CC=5 SCAR=16.4
328 148 my $self = shift;
329 148 ▶ if( ! exists $self->attributes->{CaptureArgs} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not exists $self->attributes->{'CaptureArgs'}) { } 30 118 148
elsif (not defined $self->attributes->{'CaptureArgs'}[0]) { } 0 118 118
elsif (scalar @{$self->attributes->{'CaptureArgs'};} == 1 and &looks_like_number($self->attributes->{'CaptureArgs'}[0])) { } 112 6 118
330 # If there are no defined capture args, thats considered 0.
331 30 return 0;
332 } elsif(!defined($self->attributes->{CaptureArgs}[0])) {
333 # If you fail to give a defined value, that's also 0
334 0 return 0;
335 ▶ } elsif(
Condition66%2/3
scalar @{$self->attributes->{"CaptureArgs"};} == 1 and &looks_like_number($self->attributes->{"CaptureArgs"}[0])
!ll&&!rl&&r
06112
MC/DC50%1/2
scalar @{$self->attributes->{"CaptureArgs"};} == 1 and &looks_like_number($self->attributes->{"CaptureArgs"}[0])
scalar @{$self->attributes->{"CaptureArgs"};} == 1 &looks_like_number($self->attributes->{"CaptureArgs"}[0])
Truth table66%2/3
A and B
A= scalar @{$self->attributes->{"CaptureArgs"};} == 1B= &looks_like_number($self->attributes->{"CaptureArgs"}[0])
ABresult
0X0
100
111
336 118 scalar(@{$self->attributes->{CaptureArgs}}) == 1 &&
337 looks_like_number($self->attributes->{CaptureArgs}[0])
338 ) {
339 # 'Old school' numbered captures
340 112 return $self->attributes->{CaptureArgs}[0];
341 } else {
342 # New hotness named arg constraints
343 6 return $self->number_of_captures_constraints;
344 }
345 }
346  
347  
348 155 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
349  
350 # Stringify to reverse for debug output etc.
351 35588 ▶ q{""} => sub { shift->{reverse} },
Subroutine __ANON__: called CC=1 SCAR=0.0
352  
353 # Codulate to execute to invoke the encapsulated action coderef
354 1 ▶ '&{}' => sub { my $self = shift; sub { $self->execute(@_); }; },
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
355  
356 # Make general $stuff still work
357 155 fallback => 1,
358  
359 155 );
360  
361 155 ▶no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
362  
363 9194 ▶sub dispatch { # Execute ourselves against a context
Subroutine dispatch: called CC=2 SCAR=6.9
Pod documented
364 9194 my ( $self, $c ) = @_;
365 9194 ▶ if($self->has_instance) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_instance) { } 2 9192 9194
366 2 return $c->execute( $self->instance, $self );
367 } else {
368 9192 return $c->execute( $self->class, $self );
369 }
370 }
371  
372 9194 ▶sub execute {
Subroutine execute: called CC=1 SCAR=0.0
Pod documented
373 9194 my $self = shift;
374 9194 $self->code->(@_);
375 }
376  
377 1562 ▶sub match {
Subroutine match: called CC=1 SCAR=0.0
Pod documented
378 1562 my ( $self, $c ) = @_;
379 1562 return $self->match_args($c, $c->req->args);
380 }
381  
382 1572 ▶sub match_args {
Subroutine match_args: called CC=12 SCAR=24.9
Pod documented
383 1572 my ($self, $c, $args) = @_;
384 1572 ▶ my @args = @{$args||[]};
Condition50%1/2
$args || []
l!l
15720
MC/DC0%0/1
$args || []
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
385  
386 # There there are arg constraints, we must see to it that the constraints
387 # check positive for each arg in the list.
388 1572 ▶ if($self->has_args_constraints) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_args_constraints) { } 89 1483 1572
389 # If there is only one type constraint, and its a Ref or subtype of Ref,
390 # That means we expect a reference, so use the full args arrayref.
391 89 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if ($self->args_constraint_count == 1 and $self->args_constraints->[0]->is_a_type_of('Ref') || $self->args_constraints->[0]->is_a_type_of('ClassName')) { } 8 81 89
Condition83%5/6
$self->args_constraint_count == 1 and $self->args_constraints->[0]->is_a_type_of("Ref") || $self->args_constraints->[0]->is_a_type_of("ClassName")
!ll&&!rl&&r
5768
$self->args_constraints->[0]->is_a_type_of("Ref") or $self->args_constraints->[0]->is_a_type_of("ClassName")
l!l&&r!l&&!r
8076
MC/DC66%2/3
$self->args_constraint_count == 1 and $self->args_constraints->[0]->is_a_type_of("Ref") || $self->args_constraints->[0]->is_a_type_of("ClassName")
$self->args_constraint_count == 1 $self->args_constraints->[0]->is_a_type_of("Ref") $self->args_constraints->[0]->is_a_type_of("ClassName")
Truth table75%3/4
A and B or C
A= $self->args_constraint_count == 1B= $self->args_constraints->[0]->is_a_type_of("Ref")C= $self->args_constraints->[0]->is_a_type_of("ClassName")
ABCresult
0XX0
1000
11X1
1011
392 $self->args_constraint_count == 1 &&
393 (
394 $self->args_constraints->[0]->is_a_type_of('Ref') ||
395 $self->args_constraints->[0]->is_a_type_of('ClassName')
396 )
397 ) {
398 # Ok, the the type constraint is a ref type, which is allowed to have
399 # any number of args. We need to check the arg length, if one is defined.
400 # If we had a ref type constraint that allowed us to determine the allowed
401 # number of args, we need to match that number. Otherwise if there was an
402 # undetermined number (~0) then we allow all the args. This is more of an
403 # Optimization since Tuple[Int, Int] would fail on 3,4,5 anyway, but this
404 # way we can avoid calling the constraint when the arg length is incorrect.
405 8 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if ($self->comparable_arg_number == 18446744073709551615 or scalar @args == $self->comparable_arg_number) { } 7 1 8
Condition100%3/3
$self->comparable_arg_number == '18446744073709551615' or scalar @args == $self->comparable_arg_number
l!l&&r!l&&!r
521
MC/DC100%2/2
$self->comparable_arg_number == '18446744073709551615' or scalar @args == $self->comparable_arg_number
$self->comparable_arg_number == '18446744073709551615' scalar @args == $self->comparable_arg_number
Truth table100%3/3
A or B
A= $self->comparable_arg_number == '18446744073709551615'B= scalar @args == $self->comparable_arg_number
ABresult
1X1
011
000
406 $self->comparable_arg_number == ~0 ||
407 scalar( @args ) == $self->comparable_arg_number
408 ) {
409 7 return $self->args_constraints->[0]->check($args);
410 } else {
411 1 return 0;
412 }
413 # Removing coercion stuff for the first go
414 #if($self->args_constraints->[0]->coercion && $self->attributes->{Coerce}) {
415 # my $coerced = $self->args_constraints->[0]->coerce($c) || return 0;
416 # $c->req->args([$coerced]);
417 # return 1;
418 #}
419 } else {
420 # Because of the way chaining works, we can expect args that are totally not
421 # what you'd expect length wise. When they don't match length, thats a fail
422 81 ▶ return 0 unless scalar( @args ) == $self->comparable_arg_number;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @args == $self->comparable_arg_number 37 44 81
423  
424 44 for my $i(0..$#args) {
425 47 ▶ $self->args_constraints->[$i]->check($args[$i]) || return 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->args_constraints->[$i]->check($args[$i]) or return 0 30 17 47
426 }
427 27 return 1;
428 }
429 } else {
430 # If infinite args with no constraints, we always match
431 1483 ▶ return 1 if $self->comparable_arg_number == ~0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->comparable_arg_number == '18446744073709551615' 644 839 1483
432  
433 # Otherwise, we just need to match the number of args.
434 839 return scalar( @args ) == $self->comparable_arg_number;
435 }
436 }
437  
438 672 ▶sub match_captures {
Subroutine match_captures: called CC=4 SCAR=14.0
Pod documented
439 672 my ($self, $c, $captures) = @_;
440 672 ▶ my @captures = @{$captures||[]};
Condition50%1/2
$captures || []
l!l
6720
MC/DC0%0/1
$captures || []
$captures
Truth table50%1/2
A
A= $captures
Aresult
11
00
441  
442 672 ▶ return 1 unless scalar(@captures); # If none, just say its ok
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @captures 210 462 672
443 462 ▶ return $self->has_captures_constraints ?
Branch: 1 branch
BranchTrueFalseTotal
$self->has_captures_constraints ? : 38 424 462
444 $self->match_captures_constraints($c, $captures) : 1;
445  
446 0 return 1;
447 }
448  
449 51 ▶sub match_captures_constraints {
Subroutine match_captures_constraints: called CC=8 SCAR=21.0
Pod documented
450 51 my ($self, $c, $captures) = @_;
451 51 ▶ my @captures = @{$captures||[]};
Condition50%1/2
$captures || []
l!l
510
MC/DC0%0/1
$captures || []
$captures
Truth table50%1/2
A
A= $captures
Aresult
11
00
452  
453 # Match is positive if you don't have any.
454 51 ▶ return 1 unless $self->has_captures_constraints;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_captures_constraints 0 51 51
455  
456 51 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if ($self->captures_constraints_count == 1 and $self->captures_constraints->[0]->is_a_type_of('Ref') || $self->captures_constraints->[0]->is_a_type_of('ClassName')) { } 13 38 51
Condition83%5/6
$self->captures_constraints_count == 1 and $self->captures_constraints->[0]->is_a_type_of("Ref") || $self->captures_constraints->[0]->is_a_type_of("ClassName")
!ll&&!rl&&r
112713
$self->captures_constraints->[0]->is_a_type_of("Ref") or $self->captures_constraints->[0]->is_a_type_of("ClassName")
l!l&&r!l&&!r
13027
MC/DC66%2/3
$self->captures_constraints_count == 1 and $self->captures_constraints->[0]->is_a_type_of("Ref") || $self->captures_constraints->[0]->is_a_type_of("ClassName")
$self->captures_constraints_count == 1 $self->captures_constraints->[0]->is_a_type_of("Ref") $self->captures_constraints->[0]->is_a_type_of("ClassName")
Truth table75%3/4
A and B or C
A= $self->captures_constraints_count == 1B= $self->captures_constraints->[0]->is_a_type_of("Ref")C= $self->captures_constraints->[0]->is_a_type_of("ClassName")
ABCresult
0XX0
1000
11X1
1011
457 $self->captures_constraints_count == 1 &&
458 (
459 $self->captures_constraints->[0]->is_a_type_of('Ref') ||
460 $self->captures_constraints->[0]->is_a_type_of('ClassName')
461 )
462 ) {
463 13 return $self->captures_constraints->[0]->check($captures);
464 } else {
465 38 for my $i(0..$#captures) {
466 45 ▶ $self->captures_constraints->[$i]->check($captures[$i]) || return 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->captures_constraints->[$i]->check($captures[$i]) or return 0 30 15 45
467 }
468 23 return 1;
469 }
470  
471 }
472  
473  
474 1868 ▶sub compare {
Subroutine compare: called CC=1 SCAR=0.0
Pod documented
475 1868 my ($a1, $a2) = @_;
476 1868 return $a1->comparable_arg_number <=> $a2->comparable_arg_number;
477 }
478  
479 0 ▶sub equals {
Subroutine equals: not called CC=2 SCAR=17.9
Pod documented
480 0 my ($self, $target) = @_;
481 0 ▶ return $self->private_path eq $target->private_path ? $self : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->private_path eq $target->private_path ? : 0 0 0
482 }
483  
484 32 ▶sub scheme {
Subroutine scheme: called CC=2 SCAR=6.9
Pod documented
485 32 ▶ return exists $_[0]->attributes->{Scheme} ? $_[0]->attributes->{Scheme}[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $_[0]->attributes->{'Scheme'} ? : 14 18 32
486 }
487  
488 55 ▶sub list_extra_info {
Subroutine list_extra_info: called CC=1 SCAR=0.0
Pod documented
489 55 my $self = shift;
490 return {
491 55 Args => $self->normalized_arg_number,
492 CaptureArgs => $self->number_of_captures,
493 }
494 }
495  
496 155 __PACKAGE__->meta->make_immutable;
497  
498 155 1;
499  
500 __END__
« lib/Catalyst/Request.pm ↑ Summary lib/Catalyst/Test.pm »