blib/lib/Plack/Middleware/LogErrors.pm

filter: Statementstmt 100% 29 / 29 Branchbran 100% 6 / 6 Conditioncond 81.8% 9 / 11 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 93.7% 60 / 64 CC 8 SCAR 9.0
CC
8
Cov
96%
__isa_coderef
4.2
prepare_app
3.0
call
3.0
CRAP 2.5
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Plack::Middleware::LogErrors; # git description: v0.002-21-g414ec0a
4 # vim: set ts=8 sts=4 sw=4 tw=115 et :
5 # ABSTRACT: Map psgi.errors to psgix.logger or other logger
6 # KEYWORDS: plack middleware errors logging environment I/O handle
7  
8 1 our $VERSION = '0.003';
9  
10 1 ▶use parent 'Plack::Middleware';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Plack::Util::Accessor 'logger';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 sub prepare_app
16 4 ▶{
Subroutine prepare_app: called CC=3 SCAR=11.0
Pod documented
17 4 my $self = shift;
18 4 ▶ die "'logger' is not a coderef!"
Branch: 1 branch
BranchTrueFalseTotal
if $self->logger and not __isa_coderef($self->logger) 1 3 4
Condition100%3/3
$self->logger and not __isa_coderef($self->logger)
!ll&&!rl&&r
211
MC/DC100%2/2
$self->logger and not __isa_coderef($self->logger)
$self->logger not __isa_coderef($self->logger)
Truth table100%3/3
A and not(B)
A= $self->loggerB= not __isa_coderef($self->logger)
ABresult
0X0
100
111
19 if $self->logger and not __isa_coderef($self->logger);
20 }
21  
22 sub call
23 3 ▶{
Subroutine call: called CC=3 SCAR=11.0
Pod documented
24 3 my ($self, $env) = @_;
25  
26 3 ▶ my $logger = $self->logger || $env->{'psgix.logger'};
Condition100%3/3
$self->logger || $env->{'psgix.logger'}
l!l&&r!l&&!r
111
MC/DC100%2/2
$self->logger || $env->{'psgix.logger'}
$self->logger $env->{'psgix.logger'}
Truth table100%3/3
A || B
A= $self->loggerB= $env->{'psgix.logger'}
ABresult
1X1
011
000
27  
28 3 ▶ die 'no psgix.logger in $env; cannot map psgi.errors to it!'
Branch: 1 branch
BranchTrueFalseTotal
unless $logger 1 2 3
29 if not $logger;
30  
31 # convert to something that matches the psgi.errors specs
32 2 $env->{'psgi.errors'} = Plack::Middleware::LogErrors::LogHandle->new($logger);
33  
34 2 return $self->app->($env);
35 }
36  
37 sub __isa_coderef
38 2 ▶{
Subroutine __isa_coderef: called CC=4 SCAR=14.5
39 2 ▶ ref $_[0] eq 'CODE'
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq "CODE" or (builtin::reftype($_[0]) || "") eq "CODE" or overload::Method($_[0], "&{}") 1 1 2
Condition60%3/5
ref $_[0] eq "CODE" or (builtin::reftype($_[0]) || "") eq "CODE"
l!l&&r!l&&!r
101
builtin::reftype($_[0]) || ''
l!l
10
MC/DC0%0/2
ref $_[0] eq "CODE" or (builtin::reftype($_[0]) || "") eq "CODE"
ref $_[0] eq "CODE" builtin::reftype($_[0])
Truth table66%2/3
A or B
A= ref $_[0] eq "CODE"B= builtin::reftype($_[0])
ABresult
1X1
011
000
40 or (Scalar::Util::reftype($_[0]) || '') eq 'CODE'
41 or overload::Method($_[0], '&{}')
42 }
43  
44 package # hide from PAUSE
45 Plack::Middleware::LogErrors::LogHandle;
46 # ABSTRACT: convert psgix.logger-like logger into an IO::Handle-like object
47  
48 sub new
49 2 ▶{
Subroutine new: called CC=1 SCAR=0.0
50 2 my ($class, $logger) = @_;
51 2 return bless { logger => $logger }, $class;
52 }
53  
54 sub print
55 2 ▶{
Subroutine print: called CC=1 SCAR=0.0
56 2 my ($self, $message) = @_;
57 2 $self->{logger}->({
58 level => 'error',
59 message => $message,
60 });
61 }
62  
63 1 1;
64  
65 __END__
↑ Summary