blib/lib/Catalyst/Seal/Execute.pm

filter: Statementstmt 68.4% 141 / 206 Branchbran 39.4% 45 / 114 Conditioncond 30.2% 13 / 43 MC/DCmcdc 7.4% 2 / 27 Subroutinesub 95.2% 20 / 21 Podpod n/a totaltotal 53.7% 221 / 411 CC 77 SCAR 41.8
CC
77
Cov
55%
_execute_stats
272.8
_execute
38.2
_plain_slot
22.9
CRAP 65.2
↑ Summary blib/lib/Catalyst/Seal/Middleware.pm »
1 package Catalyst::Seal::Execute;
2  
3 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 19 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 19 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 19 ▶use Catalyst::Seal ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 19 ▶use Catalyst::Seal::Guard ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 19 our $VERSION = '0.04';
13  
14 84 ▶sub _plain_slot {
Subroutine _plain_slot: called CC=16 SCAR=31.3
15 84 my ($class, $name, %want) = @_;
16  
17 84 ▶ my $meta = Class::MOP::class_of($class) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $meta = Class::MOP::class_of($class) or return 0 84 0 84
18 84 ▶ return 0 unless $meta->isa('Class::MOP::Class');
Branch: 1 branch
BranchTrueFalseTotal
unless $meta->isa("Class::MOP::Class") 0 84 84
19 84 ▶ return 0 unless $meta->is_immutable;
Branch: 1 branch
BranchTrueFalseTotal
unless $meta->is_immutable 0 84 84
20  
21 84 my $im = $meta->instance_metaclass;
22 84 ▶ return 0 unless $im->isa('Class::MOP::Instance');
Branch: 1 branch
BranchTrueFalseTotal
unless $im->isa("Class::MOP::Instance") 0 84 84
23  
24 84 ▶ my $attr = $meta->find_attribute_by_name($name) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $attr = $meta->find_attribute_by_name($name) or return 0 84 0 84
25  
26 84 my @slots = $attr->slots;
27 84 ▶ return 0 unless @slots == 1 && $slots[0] eq $name;
Branch: 1 branch
BranchTrueFalseTotal
unless @slots == 1 and $slots[0] eq $name 0 84 84
Condition33%1/3
@slots == 1 and $slots[0] eq $name
!ll&&!rl&&r
0084
MC/DC0%0/2
@slots == 1 and $slots[0] eq $name
@slots == 1 $slots[0] eq $name
Truth table33%1/3
A and B
A= @slots == 1B= $slots[0] eq $name
ABresult
0X0
100
111
28  
29 84 ▶ return 0 if $attr->is_lazy;
Branch: 1 branch
BranchTrueFalseTotal
if $attr->is_lazy 0 84 84
30 84 ▶ return 0 if $attr->has_type_constraint;
Branch: 1 branch
BranchTrueFalseTotal
if $attr->has_type_constraint 0 84 84
31 84 ▶ return 0 if $attr->has_trigger;
Branch: 1 branch
BranchTrueFalseTotal
if $attr->has_trigger 0 84 84
32 84 ▶ return 0 if $attr->should_coerce;
Branch: 1 branch
BranchTrueFalseTotal
if $attr->should_coerce 0 84 84
33 84 ▶ return 0 if $attr->is_weak_ref;
Branch: 1 branch
BranchTrueFalseTotal
if $attr->is_weak_ref 0 84 84
34 84 ▶ return 0 if $attr->has_initializer;
Branch: 1 branch
BranchTrueFalseTotal
if $attr->has_initializer 0 84 84
35  
36 84 ▶ if ($want{write}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($want{"write"}) 12 72 84
37 12 my $w = $attr->get_write_method;
38 12 ▶ return 0 unless defined $w;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $w 0 12 12
39 }
40  
41 84 return 1;
42 }
43  
44 3528 ▶sub _execute {
Subroutine _execute: called CC=17 SCAR=36.4
45 3528 my ( $c, $class, $code ) = @_;
46 3528 ▶ $class = $c->component($class) || $class;
Condition33%1/3
$c->component($class) || $class
l!l&&r!l&&!r
352800
MC/DC0%0/2
$c->component($class) || $class
$c->component($class) $class
Truth table33%1/3
A || B
A= $c->component($class)B= $class
ABresult
1X1
011
000
47  
48 3528 my $stack = $c->{stack};
49  
50 3528 ▶ if ( @$stack >= $Catalyst::RECURSION ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$stack >= $Catalyst::RECURSION) 0 3528 3528
51 0 my $action = $code->reverse();
52 0 ▶ $action = "/$action" unless $action =~ /->/;
Branch: 1 branch
BranchTrueFalseTotal
unless $action =~ /->/ 0 0 0
53 0 my $error = qq/Deep recursion detected calling "${action}"/;
54 0 $c->log->error($error);
55 0 $c->error($error);
56 0 $c->{state} = 0;
57 0 return $c->{state};
58 }
59  
60 3528 push @$stack, $code;
61  
62 19 ▶ no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
63 3528 eval {
64 3528 ▶ my $ret = $code->execute( $class, $c, @{ $c->{request}{arguments} } ) || 0;
Condition100%2/2
$code->execute($class, $c, @{$$c{'request'}{'arguments'};}) || 0
l!l
21611362
MC/DC100%1/1
$code->execute($class, $c, @{$$c{'request'}{'arguments'};}) || 0
$code->execute($class, $c, @{$$c{'request'}{'arguments'};})
Truth table100%2/2
A
A= $code->execute($class, $c, @{$$c{'request'}{'arguments'};})
Aresult
11
00
65 3523 $c->{state} = $ret;
66 };
67  
68 3528 my $last = pop @$stack;
69  
70 3528 ▶ if ( my $error = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 4 3524 3528
71 4 ▶ if ( $c->_handle_http_exception($error) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->_handle_http_exception($error)) 0 4 4
72 0 foreach my $err (@{ $c->error }) {
73 0 $c->log->error($err);
74 }
75 0 $c->clear_errors;
76 0 ▶ $c->log->_flush if $c->log->can('_flush');
Branch: 1 branch
BranchTrueFalseTotal
if $c->log->can("_flush") 0 0 0
77  
78 0 ▶ $error->can('rethrow') ? $error->rethrow : Carp::croak $error;
Branch: 1 branch
BranchTrueFalseTotal
$error->can('rethrow') ? : 0 0 0
79 }
80 4 ▶ if ( Scalar::Util::blessed($error)
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($error) and $error->isa('Catalyst::Exception::Detach')) { } 2 2 4
elsif (builtin::blessed($error) and $error->isa('Catalyst::Exception::Go')) { } 0 2 2
Condition66%2/3
builtin::blessed($error) and $error->isa("Catalyst::Exception::Detach")
!ll&&!rl&&r
202
MC/DC50%1/2
builtin::blessed($error) and $error->isa("Catalyst::Exception::Detach")
builtin::blessed($error) $error->isa("Catalyst::Exception::Detach")
Truth table66%2/3
A and B
A= builtin::blessed($error)B= $error->isa("Catalyst::Exception::Detach")
ABresult
0X0
100
111
81 and $error->isa('Catalyst::Exception::Detach') ) {
82 2 ▶ $error->rethrow if @$stack > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$stack > 1 1 1 2
83 }
84 ▶ elsif ( Scalar::Util::blessed($error)
Condition33%1/3
builtin::blessed($error) and $error->isa("Catalyst::Exception::Go")
!ll&&!rl&&r
200
MC/DC0%0/2
builtin::blessed($error) and $error->isa("Catalyst::Exception::Go")
builtin::blessed($error) $error->isa("Catalyst::Exception::Go")
Truth table33%1/3
A and B
A= builtin::blessed($error)B= $error->isa("Catalyst::Exception::Go")
ABresult
0X0
100
111
85 and $error->isa('Catalyst::Exception::Go') ) {
86 0 ▶ $error->rethrow if @$stack > 0;
Branch: 1 branch
BranchTrueFalseTotal
if @$stack > 0 0 0 0
87 }
88 else {
89 2 ▶ unless ( ref $error ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $error) 2 0 2
90 19 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
91 2 chomp $error;
92 2 my $class = $last->class;
93 2 my $name = $last->name;
94 2 $error = qq/Caught exception in $class->$name "$error"/;
95 }
96 2 $c->error($error);
97 }
98 }
99 3527 return $c->{state};
100 }
101  
102 0 ▶sub _execute_stats {
Subroutine _execute_stats: not called CC=18 SCAR=56.1
103 0 my ( $c, $class, $code ) = @_;
104 0 ▶ $class = $c->component($class) || $class;
Condition0%0/3
$c->component($class) || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
$c->component($class) || $class
$c->component($class) $class
Truth table0%0/3
A || B
A= $c->component($class)B= $class
ABresult
1X1
011
000
105  
106 0 my $stack = $c->{stack};
107  
108 0 ▶ if ( @$stack >= $Catalyst::RECURSION ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$stack >= $Catalyst::RECURSION) 0 0 0
109 0 my $action = $code->reverse();
110 0 ▶ $action = "/$action" unless $action =~ /->/;
Branch: 1 branch
BranchTrueFalseTotal
unless $action =~ /->/ 0 0 0
111 0 my $error = qq/Deep recursion detected calling "${action}"/;
112 0 $c->log->error($error);
113 0 $c->error($error);
114 0 $c->{state} = 0;
115 0 return $c->{state};
116 }
117  
118 0 my $stats_info = $c->_stats_start_execute( $code );
119  
120 0 push @$stack, $code;
121  
122 19 ▶ no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
123 0 eval {
124 0 ▶ my $ret = $code->execute( $class, $c, @{ $c->{request}{arguments} } ) || 0;
Condition0%0/2
$code->execute($class, $c, @{$$c{'request'}{'arguments'};}) || 0
l!l
00
MC/DC0%0/1
$code->execute($class, $c, @{$$c{'request'}{'arguments'};}) || 0
$code->execute($class, $c, @{$$c{'request'}{'arguments'};})
Truth table0%0/2
A
A= $code->execute($class, $c, @{$$c{'request'}{'arguments'};})
Aresult
11
00
125 0 $c->{state} = $ret;
126 };
127  
128 0 ▶ $c->_stats_finish_execute( $stats_info ) if $stats_info;
Branch: 1 branch
BranchTrueFalseTotal
if $stats_info 0 0 0
129  
130 0 my $last = pop @$stack;
131  
132 0 ▶ if ( my $error = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 0 0 0
133 0 ▶ if ( $c->_handle_http_exception($error) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->_handle_http_exception($error)) 0 0 0
134 0 foreach my $err (@{ $c->error }) {
135 0 $c->log->error($err);
136 }
137 0 $c->clear_errors;
138 0 ▶ $c->log->_flush if $c->log->can('_flush');
Branch: 1 branch
BranchTrueFalseTotal
if $c->log->can("_flush") 0 0 0
139  
140 0 ▶ $error->can('rethrow') ? $error->rethrow : Carp::croak $error;
Branch: 1 branch
BranchTrueFalseTotal
$error->can('rethrow') ? : 0 0 0
141 }
142 0 ▶ if ( Scalar::Util::blessed($error)
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($error) and $error->isa('Catalyst::Exception::Detach')) { } 0 0 0
elsif (builtin::blessed($error) and $error->isa('Catalyst::Exception::Go')) { } 0 0 0
Condition0%0/3
builtin::blessed($error) and $error->isa("Catalyst::Exception::Detach")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($error) and $error->isa("Catalyst::Exception::Detach")
builtin::blessed($error) $error->isa("Catalyst::Exception::Detach")
Truth table0%0/3
A and B
A= builtin::blessed($error)B= $error->isa("Catalyst::Exception::Detach")
ABresult
0X0
100
111
143 and $error->isa('Catalyst::Exception::Detach') ) {
144 0 ▶ $error->rethrow if @$stack > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$stack > 1 0 0 0
145 }
146 ▶ elsif ( Scalar::Util::blessed($error)
Condition0%0/3
builtin::blessed($error) and $error->isa("Catalyst::Exception::Go")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($error) and $error->isa("Catalyst::Exception::Go")
builtin::blessed($error) $error->isa("Catalyst::Exception::Go")
Truth table0%0/3
A and B
A= builtin::blessed($error)B= $error->isa("Catalyst::Exception::Go")
ABresult
0X0
100
111
147 and $error->isa('Catalyst::Exception::Go') ) {
148 0 ▶ $error->rethrow if @$stack > 0;
Branch: 1 branch
BranchTrueFalseTotal
if @$stack > 0 0 0 0
149 }
150 else {
151 0 ▶ unless ( ref $error ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $error) 0 0 0
152 19 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
153 0 chomp $error;
154 0 my $class = $last->class;
155 0 my $name = $last->name;
156 0 $error = qq/Caught exception in $class->$name "$error"/;
157 }
158 0 $c->error($error);
159 }
160 }
161 0 return $c->{state};
162 }
163  
164 12 ▶sub _seal_execute {
Subroutine _seal_execute: called CC=8 SCAR=26.7
165 12 my ($app) = @_;
166  
167 12 ▶ my $ctx = $app->context_class || $app;
Condition33%1/3
$app->context_class || $app
l!l&&r!l&&!r
1200
MC/DC0%0/2
$app->context_class || $app
$app->context_class $app
Truth table33%1/3
A || B
A= $app->context_classB= $app
ABresult
1X1
011
000
168 12 ▶ my $req = eval { $app->composed_request_class } || $app->request_class;
Condition33%1/3
eval { do { $app->composed_request_class } } || $app->request_class
l!l&&r!l&&!r
1200
MC/DC0%0/2
eval { do { $app->composed_request_class } } || $app->request_class
eval { do { $app->composed_request_class } } $app->request_class
Truth table33%1/3
A || B
A= eval { do { $app->composed_request_class } }B= $app->request_class
ABresult
1X1
011
000
169  
170 12 ▶ unless (_plain_slot($ctx, 'stack')
Branch: 1 branch
BranchTrueFalseTotal
unless (_plain_slot($ctx, "stack") and _plain_slot($ctx, "state", "write", 1) and _plain_slot($req, "arguments")) 0 12 12
Condition33%2/6
_plain_slot($ctx, "stack") and _plain_slot($ctx, "state", "write", 1) and _plain_slot($req, "arguments")
!ll&&!rl&&r
0012
_plain_slot($ctx, "stack") and _plain_slot($ctx, "state", "write", 1)
!ll&&!rl&&r
0012
MC/DC0%0/3
_plain_slot($ctx, "stack") and _plain_slot($ctx, "state", "write", 1) and _plain_slot($req, "arguments")
_plain_slot($ctx, "stack") _plain_slot($ctx, "state", "write", 1) _plain_slot($req, "arguments")
Truth table25%1/4
A and B and C
A= _plain_slot($ctx, "stack")B= _plain_slot($ctx, "state", "write", 1)C= _plain_slot($req, "arguments")
ABCresult
0XX0
10X0
1100
1111
171 && _plain_slot($ctx, 'state', write => 1)
172 && _plain_slot($req, 'arguments')) {
173 0 Catalyst::Seal::note(
174 'execute not hoisted: stack, state or arguments is not a plain slot');
175 0 return 0;
176 }
177  
178 12 ▶ my $stats = eval { $app->use_stats } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $app->use_stats } } ? : 0 12 12
179  
180 12 ▶ return Catalyst::Seal::Guard::replace(
Branch: 1 branch
BranchTrueFalseTotal
$stats ? : 0 12 12
181 'Catalyst::execute' => $stats ? \&_execute_stats : \&_execute);
182 }
183  
184 12 ▶sub _seal_use_stats {
Subroutine _seal_use_stats: called CC=5 SCAR=17.8
185 12 my ($app) = @_;
186  
187 12 ▶ my $ctx = $app->context_class || $app;
Condition33%1/3
$app->context_class || $app
l!l&&r!l&&!r
1200
MC/DC0%0/2
$app->context_class || $app
$app->context_class $app
Truth table33%1/3
A || B
A= $app->context_classB= $app
ABresult
1X1
011
000
188 12 ▶ my $orig = $ctx->can('use_stats') or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $orig = $ctx->can("use_stats") or return 0 12 0 12
189  
190 12 my $value = eval { $app->use_stats };
191 12 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 12 12
192 0 Catalyst::Seal::note("could not resolve use_stats, not sealed: $@");
193 0 return 0;
194 }
195  
196 12 my $ok = eval {
197 19 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
198 12 Catalyst::Seal::_install_const($ctx, 'use_stats', $value, $orig, undef);
199 12 1;
200 };
201 12 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 12 12
202 0 Catalyst::Seal::note("could not seal use_stats: $@");
203 0 return 0;
204 }
205 12 return 1;
206 }
207  
208 12 ▶sub _seal_depth {
Subroutine _seal_depth: called CC=5 SCAR=17.4
209 12 my ($app) = @_;
210  
211 12 ▶ my $ctx = $app->context_class || $app;
Condition33%1/3
$app->context_class || $app
l!l&&r!l&&!r
1200
MC/DC0%0/2
$app->context_class || $app
$app->context_class $app
Truth table33%1/3
A || B
A= $app->context_classB= $app
ABresult
1X1
011
000
212 12 ▶ return 0 unless _plain_slot($ctx, 'stack');
Branch: 1 branch
BranchTrueFalseTotal
unless _plain_slot($ctx, "stack") 0 12 12
213  
214 12 ▶ my $orig = $ctx->can('depth') or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $orig = $ctx->can("depth") or return 0 12 0 12
215  
216 12 my $ok = eval {
217 19 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
218 12 Catalyst::Seal::_install_count($ctx, 'depth', 'stack', $orig);
219 12 1;
220 };
221 12 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 12 12
222 0 Catalyst::Seal::note("could not seal depth: $@");
223 0 return 0;
224 }
225 12 return 1;
226 }
227  
228 19 my @ACTION_SLOTS = qw(code instance class);
229  
230 12 ▶sub _seal_actions {
Subroutine _seal_actions: called CC=12 SCAR=28.3
231 12 my ($app) = @_;
232  
233 12 my $class = 'Catalyst::Action';
234 12 ▶ my $meta = Class::MOP::class_of($class) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $meta = Class::MOP::class_of($class) or return 0 12 0 12
235 12 ▶ return 0 unless $meta->isa('Class::MOP::Class');
Branch: 1 branch
BranchTrueFalseTotal
unless $meta->isa("Class::MOP::Class") 0 12 12
236  
237 12 for my $slot (@ACTION_SLOTS) {
238 36 ▶ next if _plain_slot($class, $slot);
Branch: 1 branch
BranchTrueFalseTotal
if _plain_slot($class, $slot) 36 0 36
239 0 Catalyst::Seal::note(
240 "Catalyst::Action::$slot is not a plain slot, the action pair was not sealed");
241 0 return 0;
242 }
243  
244 12 my $sealed = 0;
245 12 for my $name (qw(execute dispatch)) {
246 24 ▶ my $method = $meta->get_method($name) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $method = $meta->get_method($name) or next 24 0 24
247 24 ▶ if ($method->isa('Class::MOP::Method::Wrapped')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method->isa("Class::MOP::Method::Wrapped")) 0 24 24
248 0 Catalyst::Seal::note("Catalyst::Action::$name is wrapped, not sealed");
249 0 next;
250 }
251  
252 24 ▶ my $body = $method->body or next;
Branch: 1 branch
BranchTrueFalseTotal
my $body = $method->body or next 24 0 24
253 24 ▶ my $installed = $class->can($name) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $installed = $class->can($name) or next 24 0 24
254 24 ▶ next unless $installed == $body;
Branch: 1 branch
BranchTrueFalseTotal
unless $installed == $body 0 24 24
255  
256 24 my $ok = eval {
257 19 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
258 24 Catalyst::Seal::_install_action(
259 $class, $name, $name, 'code', 'instance', 'class', $body);
260 24 1;
261 };
262 24 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 24 24
263 0 Catalyst::Seal::note("could not seal Catalyst::Action::$name: $@");
264 0 next;
265 }
266 24 $sealed++;
267 }
268  
269 12 return $sealed;
270 }
271  
272 19 my $PATCHED = 0;
273  
274 12 ▶Catalyst::Seal::register_step('execute' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
275 12 my ($app) = @_;
276  
277 12 require Class::MOP;
278  
279 12 my $stats = _seal_use_stats($app);
280 12 my $depth = _seal_depth($app);
281  
282 12 my ($execute, $actions) = (0, 0);
283 12 ▶ unless ($PATCHED++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($PATCHED++) 12 0 12
284 12 $execute = _seal_execute($app);
285 12 $actions = _seal_actions($app);
286 }
287  
288 Catalyst::Seal::note(
289 12 ▶ "execute: hoisted=$execute actions=$actions use_stats=$stats depth=$depth")
Branch: 1 branch
BranchTrueFalseTotal
if $Catalyst::Seal::DEBUG 0 12 12
290 if $Catalyst::Seal::DEBUG;
291 12 return;
292 19 });
293  
294 19 1;
295  
296 __END__
↑ Summary blib/lib/Catalyst/Seal/Middleware.pm »