| 1 | package Catalyst::Seal::Exceptions; | ||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 369 | ▶ | sub _handle_request { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_request: called CC=7 SCAR=20.7
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 369 | my ( $class, @arguments ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 369 | my $status = -1; | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 369 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | 369 | ▶ | if ($class->debug) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | my $secs = time - $Catalyst::START || 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
time - $Catalyst::START || 1
MC/DC0%0/1
time - $Catalyst::START || 1
time - $Catalyst::START
Truth table0%0/2
A
A= time - $Catalyst::START
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | my $av = sprintf '%.3f', $Catalyst::COUNT / $secs; | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | my $time = localtime time; | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | $class->log->info("*** Request $Catalyst::COUNT ($av/s) [$$] [$time] ***"); | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 369 | my $c = $class->prepare(@arguments); | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | 366 | $c->dispatch; | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | 366 | $status = $c->finalize; | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | 366 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 369 | ▶ | unless ($ok) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | my $error = $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 3 | ▶ | if ( $class->_handle_http_exception($error) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | ▶ | $error->can('rethrow') ? $error->rethrow : Carp::croak $error; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | chomp(my $message = $error); | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | 2 | $class->log->error(qq/Caught exception in engine "$message"/); | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 368 | $Catalyst::COUNT++; | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 368 | ▶ | if (my $coderef = $class->log->can('_flush')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 368 | $class->log->$coderef(); | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 368 | return $status; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 367 | ▶ | sub _prepare { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_prepare: called CC=16 SCAR=34.7
| |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 367 | my ( $class, @arguments ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 367 | ▶ | $class->context_class( ref $class || $class ) unless $class->context_class; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table0%0/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 367 | my $uploadtmp = $class->config->{uploadtmp}; | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | 367 | ▶ | my $c = $class->context_class->new({ $uploadtmp ? (_uploadtmp => $uploadtmp) : ()}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 367 | $c->response->_context($c); | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 367 | ▶ | if ($c->use_stats | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$c->use_stats or not $Catalyst::Seal::Construct::LAZY_STATS{ref $c or $c}
ref $c || $c
MC/DC0%0/2
$c->use_stats or not $Catalyst::Seal::Construct::LAZY_STATS{ref $c or $c}
$c->use_stats
not $Catalyst::Seal::Construct::LAZY_STATS{ref $c or $c}
MC/DC0%0/2
ref $c || $c
ref $c
$c
Truth table33%1/3
A or not(B)
A= $c->use_statsB= not $Catalyst::Seal::Construct::LAZY_STATS{ref $c or $c}
Truth table33%1/3
A || B
A= ref $cB= $c
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | || !$Catalyst::Seal::Construct::LAZY_STATS{ ref($c) || $c }) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $c->stats($class->stats_class->new)->enable($c->use_stats); | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 367 | ▶ | if ( $c->debug || $c->config->{enable_catalyst_header} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$c->debug or $c->config->{"enable_catalyst_header"}
MC/DC0%0/2
$c->debug or $c->config->{"enable_catalyst_header"}
$c->debug
$c->config->{"enable_catalyst_header"}
Truth table33%1/3
A or B
A= $c->debugB= $c->config->{"enable_catalyst_header"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $c->res->headers->header( 'X-Catalyst' => $Catalyst::VERSION ); | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 367 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | 367 | ▶ | if ( my $prepare = $c->engine->can('prepare') ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $c->engine->$prepare( $c, @arguments ); | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 367 | $c->prepare_request(@arguments); | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 367 | $c->prepare_connection; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | 367 | $c->prepare_query_parameters; | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | 366 | $c->prepare_headers; | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | 366 | $c->prepare_cookies; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 366 | $c->prepare_path; | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 366 | $c->prepare_read; | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 366 | ▶ | unless ( ref($c)->config->{parse_on_demand} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 366 | $c->prepare_body; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 366 | $c->prepare_action; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | 366 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 367 | ▶ | unless ($ok) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | my $error = $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | ▶ | if ( $c->_handle_http_exception($error) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | foreach my $err (@{$c->error}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | $c->log->error($err); | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $c->clear_errors; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | $c->log->_flush if $c->log->can('_flush'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | $error->can('rethrow') ? $error->rethrow : Carp::croak $error; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | $c->response->status(400); | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | $c->response->content_type('text/plain'); | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | $c->response->body('Bad Request'); | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | $c->finalize; | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | die $error; | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 366 | $c->log_request; | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | 366 | $c->{stash} = $c->stash; | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | 366 | Scalar::Util::weaken($c->{stash}); | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 366 | return $c; | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 19 | my $DONE = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 12 | ▶ | Catalyst::Seal::register_step('exceptions' => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 12 | ▶ | return if $DONE++; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 12 | Catalyst::Seal::Guard::replace('Catalyst::handle_request' => \&_handle_request); | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | 12 | Catalyst::Seal::Guard::replace('Catalyst::prepare' => \&_prepare); | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | 12 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | 19 | }); | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 19 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||