| 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
| |||||||||||||
| 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]
MC/DC100%1/1
$self->catch || [404]
$self->catch
Truth table100%2/2
A
A= $self->catch
| |||||||||||||
| 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
| |||||||||||||
| 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 || []
MC/DC100%1/1
$self->apps || []
$self->apps
Truth table100%2/2
A
A= $self->apps
| |||||||||||||
| 41 | 6 | my $tries_left = 0 + @try; | |||||||||||
| 42 | |||||||||||||
| 43 | 6 | ▶ | if (not $tries_left) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 54 | 4 | $res->($respond_wrapper); | |||||||||||
| 55 | } else { | ||||||||||||
| 56 | 8 | $respond_wrapper->($res); | |||||||||||
| 57 | } | ||||||||||||
| 58 | 12 | ▶ | return if $done; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 59 | } | ||||||||||||
| 60 | 6 | }; | |||||||||||
| 61 | } | ||||||||||||
| 62 | |||||||||||||
| 63 | 2 | 1; | |||||||||||
| 64 | |||||||||||||
| 65 | __END__ | ||||||||||||