| 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
Condition50%1/2
$ENV{'PLACK_ENV'} || ''
MC/DC0%0/1
$ENV{'PLACK_ENV'} || ''
$ENV{'PLACK_ENV'}
Truth table50%1/2
A
A= $ENV{'PLACK_ENV'}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
builtin::blessed($e) and $e->can("as_psgi")
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")
| |||||||||||||||||||||||||||||
| 50 | 0 | return $e->as_psgi; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | 6 | ▶ | if (blessed $e && $e->can('code')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($e) and $e->can("code")
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")
| |||||||||||||||||||||||||||||
| 53 | 5 | $code = $e->code; | |||||||||||||||||||||||||||
| 54 | 5 | ▶ | $message = | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 55 | $e->can('as_string') ? $e->as_string : | ||||||||||||||||||||||||||||
| 56 | overload::Method($e, '""') ? "$e" : undef; | ||||||||||||||||||||||||||||
| 57 | } else { | ||||||||||||||||||||||||||||
| 58 | 1 | ▶ | if ($self->rethrow) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 68 | 0 | die $e; # rethrow | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 6 | ▶ | $message ||= HTTP::Status::status_message($code); | ||||||||||||||||||||||||||
|
Condition66%2/3
$message ||= &HTTP::Status::status_message($code)
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)
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$code =~ /^3/ and my $loc = eval {
do {
$e->location
}
}
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
}
}
| |||||||||||||||||||||||||||||
| 79 | 1 | push(@headers, Location => $loc); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 6 | return [ $code, \@headers, [ $message ] ]; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 2 | 1; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | __END__ | ||||||||||||||||||||||||||||