blib/lib/Plack/App/Cascade.pm

filter: Statementstmt 100% 46 / 46 Branchbran 100% 12 / 12 Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 83.3% 10 / 12 Podpod 100% 3 / 3 totaltotal 97.4% 77 / 79 CC 10 SCAR 11.9
CC
10
Cov
100%
__ANON__
7.0
add
2.0
prepare_app
2.0
CRAP 3.3
« blib/lib/Plack/Middleware/IIS6ScriptNameFix.pm ↑ Summary blib/lib/Plack/Response.pm »
1 package Plack::App::Cascade;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use parent qw(Plack::Component);
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Plack::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Plack::Util::Accessor qw(apps catch codes);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 6 ▶sub add {
Subroutine add: called CC=2 SCAR=6.9
Pod documented
9 6 my $self = shift;
10 6 ▶ $self->apps([]) unless $self->apps;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->apps 2 4 6
11 6 push @{$self->apps}, @_;
12 }
13  
14 6 ▶sub prepare_app {
Subroutine prepare_app: called CC=2 SCAR=6.9
Pod documented
15 6 my $self = shift;
16 6 ▶ my %codes = map { $_ => 1 } @{ $self->catch || [ 404 ] };
Condition100%2/2
$self->catch || [404]
l!l
24
MC/DC100%1/1
$self->catch || [404]
$self->catch
Truth table100%2/2
A
A= $self->catch
Aresult
11
00
17 6 $self->codes(\%codes);
18 }
19  
20 6 ▶sub call {
Subroutine call: called CC=1 SCAR=0.0
Pod documented
21 6 my($self, $env) = @_;
22  
23 6 ▶ return sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
24 6 my $respond = shift;
25  
26 6 my $done;
27 9 ▶ my $respond_wrapper = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
28 9 my $res = shift;
29 9 ▶ if ($self->codes->{$res->[0]}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->codes->{$res->[0]}) { } 7 2 9
30 # suppress output by giving the app an
31 # output spool which drops everything on the floor
32 return Plack::Util::inline_object
33 7 ▶ write => sub { }, close => sub { };
Subroutine __ANON__: not called CC=1 SCAR=0.0
Subroutine __ANON__: not called CC=1 SCAR=0.0
34 } else {
35 2 $done = 1;
36 2 return $respond->($res);
37 }
38 6 };
39  
40 6 ▶ my @try = @{$self->apps || []};
Condition100%2/2
$self->apps || []
l!l
51
MC/DC100%1/1
$self->apps || []
$self->apps
Truth table100%2/2
A
A= $self->apps
Aresult
11
00
41 6 my $tries_left = 0 + @try;
42  
43 6 ▶ if (not $tries_left) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tries_left) 1 5 6
44 1 return $respond->([ 404, [ 'Content-Type' => 'text/html' ], [ '404 Not Found' ] ])
45 }
46  
47 5 for my $app (@try) {
48 12 my $res = $app->($env);
49 12 ▶ if ($tries_left-- == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tries_left-- == 1) 3 9 12
50 3 ▶ $respond_wrapper = sub { $respond->(shift) };
Subroutine __ANON__: called CC=1 SCAR=0.0
51 }
52  
53 12 ▶ if (ref $res eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $res eq 'CODE') { } 4 8 12
54 4 $res->($respond_wrapper);
55 } else {
56 8 $respond_wrapper->($res);
57 }
58 12 ▶ return if $done;
Branch: 1 branch
BranchTrueFalseTotal
if $done 2 10 12
59 }
60 6 };
61 }
62  
63 2 1;
64  
65 __END__
« blib/lib/Plack/Middleware/IIS6ScriptNameFix.pm ↑ Summary blib/lib/Plack/Response.pm »