blib/lib/Catalyst/Seal/Exceptions.pm

filter: Statementstmt 85.3% 76 / 89 Branchbran 53.1% 17 / 32 Conditioncond 21.4% 3 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 68.6% 105 / 153 CC 23 SCAR 29.3
CC
23
Cov
71%
_prepare
32.0
_handle_request
7.9
__ANON__
2.0
CRAP 18.7
« blib/lib/Catalyst/Seal/Middleware.pm ↑ Summary blib/lib/Catalyst/Seal/Prepare.pm »
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
BranchTrueFalseTotal
if ($class->debug) 0 369 369
21 0 ▶ my $secs = time - $Catalyst::START || 1;
Condition0%0/2
time - $Catalyst::START || 1
l!l
00
MC/DC0%0/1
time - $Catalyst::START || 1
time - $Catalyst::START
Truth table0%0/2
A
A= time - $Catalyst::START
Aresult
11
00
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
BranchTrueFalseTotal
unless ($ok) 3 366 369
34 3 my $error = $@;
35 3 ▶ if ( $class->_handle_http_exception($error) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->_handle_http_exception($error)) 1 2 3
36 1 ▶ $error->can('rethrow') ? $error->rethrow : Carp::croak $error;
Branch: 1 branch
BranchTrueFalseTotal
$error->can('rethrow') ? : 0 1 1
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
BranchTrueFalseTotal
if (my $coderef = $class->log->can("_flush")) 368 0 368
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
BranchTrueFalseTotal
unless $class->context_class 0 367 367
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
54  
55 367 my $uploadtmp = $class->config->{uploadtmp};
56 367 ▶ my $c = $class->context_class->new({ $uploadtmp ? (_uploadtmp => $uploadtmp) : ()});
Branch: 1 branch
BranchTrueFalseTotal
$uploadtmp ? : 0 367 367
57  
58 367 $c->response->_context($c);
59  
60 367 ▶ if ($c->use_stats
Branch: 1 branch
BranchTrueFalseTotal
if ($c->use_stats or not $Catalyst::Seal::Construct::LAZY_STATS{ref $c or $c}) 0 367 367
Condition33%2/6
$c->use_stats or not $Catalyst::Seal::Construct::LAZY_STATS{ref $c or $c}
l!l&&r!l&&!r
00367
ref $c || $c
l!l&&r!l&&!r
36700
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}
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= ref $cB= $c
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if ($c->debug or $c->config->{"enable_catalyst_header"}) 0 367 367
Condition33%1/3
$c->debug or $c->config->{"enable_catalyst_header"}
l!l&&r!l&&!r
00367
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"}
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if (my $prepare = $c->engine->can('prepare')) { } 0 367 367
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
BranchTrueFalseTotal
unless (ref($c)->config->{"parse_on_demand"}) 366 0 366
84 366 $c->prepare_body;
85 }
86 }
87 366 $c->prepare_action;
88 366 1;
89 };
90  
91 367 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 1 366 367
92 1 my $error = $@;
93 1 ▶ if ( $c->_handle_http_exception($error) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->_handle_http_exception($error)) { } 0 1 1
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
BranchTrueFalseTotal
if $c->log->can("_flush") 0 0 0
99 0 ▶ $error->can('rethrow') ? $error->rethrow : Carp::croak $error;
Branch: 1 branch
BranchTrueFalseTotal
$error->can('rethrow') ? : 0 0 0
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
BranchTrueFalseTotal
if $DONE++ 0 12 12
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__
« blib/lib/Catalyst/Seal/Middleware.pm ↑ Summary blib/lib/Catalyst/Seal/Prepare.pm »