| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
1
|
|
|
1
|
|
49978
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
32
|
|
|
2
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
45
|
|
|
3
|
|
|
|
|
|
|
package Plack::Middleware::LogErrors; |
|
4
|
|
|
|
|
|
|
# git description: v0.001-13-g28c86df |
|
5
|
|
|
|
|
|
|
$Plack::Middleware::LogErrors::VERSION = '0.002'; |
|
6
|
|
|
|
|
|
|
# ABSTRACT: Map psgi.errors to psgix.logger or other logger |
|
7
|
|
|
|
|
|
|
# KEYWORDS: plack middleware errors logging environment I/O handle |
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
4
|
use parent 'Plack::Middleware'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
6
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
10710
|
use Plack::Util::Accessor 'logger'; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
5
|
|
|
12
|
1
|
|
|
1
|
|
53
|
use Scalar::Util 'reftype'; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
364
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub prepare_app |
|
15
|
|
|
|
|
|
|
{ |
|
16
|
4
|
|
|
4
|
1
|
10246
|
my $self = shift; |
|
17
|
4
|
100
|
100
|
|
|
16
|
die "'logger' is not a coderef!" |
|
18
|
|
|
|
|
|
|
if $self->logger and not __isa_coderef($self->logger); |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub call |
|
22
|
|
|
|
|
|
|
{ |
|
23
|
3
|
|
|
3
|
1
|
18156
|
my ($self, $env) = @_; |
|
24
|
|
|
|
|
|
|
|
|
25
|
3
|
|
100
|
|
|
10
|
my $logger = $self->logger || $env->{'psgix.logger'}; |
|
26
|
|
|
|
|
|
|
|
|
27
|
3
|
100
|
|
|
|
40
|
die 'no psgix.logger in $env; cannot map psgi.errors to it!' |
|
28
|
|
|
|
|
|
|
if not $logger; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# convert to something that matches the psgi.errors specs |
|
31
|
2
|
|
|
|
|
13
|
$env->{'psgi.errors'} = Plack::Middleware::LogErrors::LogHandle->new($logger); |
|
32
|
|
|
|
|
|
|
|
|
33
|
2
|
|
|
|
|
11
|
return $self->app->($env); |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub __isa_coderef |
|
37
|
|
|
|
|
|
|
{ |
|
38
|
2
|
100
|
50
|
2
|
|
123
|
ref $_[0] eq 'CODE' |
|
|
|
|
66
|
|
|
|
|
|
39
|
|
|
|
|
|
|
or (reftype($_[0]) || '') eq 'CODE' |
|
40
|
|
|
|
|
|
|
or overload::Method($_[0], '&{}') |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
package Plack::Middleware::LogErrors::LogHandle; |
|
44
|
|
|
|
|
|
|
# git description: v0.001-13-g28c86df |
|
45
|
|
|
|
|
|
|
$Plack::Middleware::LogErrors::LogHandle::VERSION = '0.002'; |
|
46
|
|
|
|
|
|
|
# ABSTRACT: convert psgix.logger-like logger into an IO::Handle-like object |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub new |
|
49
|
|
|
|
|
|
|
{ |
|
50
|
2
|
|
|
2
|
|
4
|
my ($class, $logger) = @_; |
|
51
|
2
|
|
|
|
|
8
|
return bless { logger => $logger }, $class; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub print |
|
55
|
|
|
|
|
|
|
{ |
|
56
|
2
|
|
|
2
|
|
33
|
my ($self, $message) = @_; |
|
57
|
2
|
|
|
|
|
10
|
$self->{logger}->({ |
|
58
|
|
|
|
|
|
|
level => 'error', |
|
59
|
|
|
|
|
|
|
message => $message, |
|
60
|
|
|
|
|
|
|
}); |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |