blib/lib/Plack/Middleware/HTTPExceptions.pm

filter: Statementstmt 91.5% 54 / 59 Branchbran 70.0% 14 / 20 Conditioncond 64.2% 9 / 14 MC/DCmcdc 22.2% 2 / 9 Subroutinesub 100% 16 / 16 Podpod 66.6% 2 / 3 totaltotal 80.1% 97 / 121 CC 16 SCAR 18.6
CC
16
Cov
83%
transform_error
14.1
prepare_app
3.3
__ANON__
2.3
CRAP 6.4
« blib/lib/Plack/Middleware/ErrorDocument.pm ↑ Summary blib/lib/Plack/App/File.pm »
1 package Plack::Middleware::HTTPExceptions;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use parent qw(Plack::Middleware);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Plack::Util::Accessor qw(rethrow);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use HTTP::Status ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶sub prepare_app {
Subroutine prepare_app: called CC=3 SCAR=12.0
Pod documented
12 2 my $self = shift;
13 2 ▶ $self->rethrow(1) if ($ENV{PLACK_ENV} || '') eq 'development';
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"PLACK_ENV"} || "") eq "development" 0 2 2
Condition50%1/2
$ENV{'PLACK_ENV'} || ''
l!l
02
MC/DC0%0/1
$ENV{'PLACK_ENV'} || ''
$ENV{'PLACK_ENV'}
Truth table50%1/2
A
A= $ENV{'PLACK_ENV'}
Aresult
11
00
14 }
15  
16 7 ▶sub call {
Subroutine call: called CC=2 SCAR=7.0
Pod documented
17 7 my($self, $env) = @_;
18  
19 7 ▶ my $res = try {
Subroutine __ANON__: called CC=1 SCAR=0.0
20 7 $self->app->($env);
21 4 ▶ } catch {
Subroutine __ANON__: called CC=1 SCAR=0.0
22 4 $self->transform_error($_, $env);
23 7 };
24  
25 7 ▶ return $res if ref $res eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $res eq "ARRAY" 4 3 7
26  
27 3 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.2
28 3 my $respond = shift;
29  
30 3 my $writer;
31 3 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
32 3 ▶ $res->(sub { return $writer = $respond->(@_) });
Subroutine __ANON__: called CC=1 SCAR=0.0
33 2 ▶ } catch {
Subroutine __ANON__: called CC=2 SCAR=8.4
34 2 ▶ if ($writer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($writer) { } 0 2 2
35 0 Carp::cluck $_;
36 0 $writer->close;
37 } else {
38 2 my $res = $self->transform_error($_, $env);
39 2 $respond->($res);
40 }
41 3 };
42 3 };
43 }
44  
45 6 ▶sub transform_error {
Subroutine transform_error: called CC=12 SCAR=26.5
Pod undocumented
46 6 my($self, $e, $env) = @_;
47  
48 6 my($code, $message);
49 6 ▶ if (blessed $e && $e->can('as_psgi')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($e) and $e->can("as_psgi")) 0 6 6
Condition66%2/3
builtin::blessed($e) and $e->can("as_psgi")
!ll&&!rl&&r
150
MC/DC0%0/2
builtin::blessed($e) and $e->can("as_psgi")
builtin::blessed($e) $e->can("as_psgi")
Truth table66%2/3
A and B
A= builtin::blessed($e)B= $e->can("as_psgi")
ABresult
0X0
100
111
50 0 return $e->as_psgi;
51 }
52 6 ▶ if (blessed $e && $e->can('code')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($e) and $e->can('code')) { } 5 1 6
Condition66%2/3
builtin::blessed($e) and $e->can("code")
!ll&&!rl&&r
105
MC/DC50%1/2
builtin::blessed($e) and $e->can("code")
builtin::blessed($e) $e->can("code")
Truth table66%2/3
A and B
A= builtin::blessed($e)B= $e->can("code")
ABresult
0X0
100
111
53 5 $code = $e->code;
54 5 ▶ $message =
Branch: 2 branches
BranchTrueFalseTotal
$e->can('as_string') ? : 2 3 5
overload::Method($e, '""') ? : 0 3 3
55 $e->can('as_string') ? $e->as_string :
56 overload::Method($e, '""') ? "$e" : undef;
57 } else {
58 1 ▶ if ($self->rethrow) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->rethrow) { } 0 1 1
59 0 die $e;
60 }
61 else {
62 1 $code = 500;
63 1 $env->{'psgi.errors'}->print($e);
64 }
65 }
66  
67 6 ▶ if ($code !~ /^[3-5]\d\d$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($code =~ /^[3-5]\d\d$/) 0 6 6
68 0 die $e; # rethrow
69 }
70  
71 6 ▶ $message ||= HTTP::Status::status_message($code);
Condition66%2/3
$message ||= &HTTP::Status::status_message($code)
l!l&&r!l&&!r
240
MC/DC0%0/2
$message ||= &HTTP::Status::status_message($code)
$message &HTTP::Status::status_message($code)
Truth table66%2/3
A ||= B
A= $messageB= &HTTP::Status::status_message($code)
ABresult
1X1
011
000
72  
73 6 my @headers = (
74 'Content-Type' => 'text/plain',
75 'Content-Length' => length($message),
76 );
77  
78 6 ▶ if ($code =~ /^3/ && (my $loc = eval { $e->location })) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code =~ /^3/ and my $loc = eval { do { $e->location } }) 1 5 6
Condition66%2/3
$code =~ /^3/ and my $loc = eval { do { $e->location } }
!ll&&!rl&&r
501
MC/DC50%1/2
$code =~ /^3/ and my $loc = eval { do { $e->location } }
$code =~ /^3/ my $loc = eval { do { $e->location } }
Truth table66%2/3
A and B
A= $code =~ /^3/B= my $loc = eval { do { $e->location } }
ABresult
0X0
100
111
79 1 push(@headers, Location => $loc);
80 }
81  
82 6 return [ $code, \@headers, [ $message ] ];
83 }
84  
85 2 1;
86  
87 __END__
« blib/lib/Plack/Middleware/ErrorDocument.pm ↑ Summary blib/lib/Plack/App/File.pm »