line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::AccessLog::Timed; |
2
|
2
|
|
|
2
|
|
577
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
61
|
|
3
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
57
|
|
4
|
2
|
|
|
2
|
|
10
|
use parent qw( Plack::Middleware::AccessLog ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
37
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
665
|
use Time::HiRes; |
|
2
|
|
|
|
|
1495
|
|
|
2
|
|
|
|
|
12
|
|
7
|
2
|
|
|
2
|
|
244
|
use Plack::Util; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
979
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub call { |
10
|
12
|
|
|
12
|
1
|
26
|
my $self = shift; |
11
|
12
|
|
|
|
|
26
|
my($env) = @_; |
12
|
|
|
|
|
|
|
|
13
|
12
|
|
|
|
|
46
|
my $time = [Time::HiRes::gettimeofday]; |
14
|
12
|
|
|
|
|
26
|
my $length = 0; |
15
|
12
|
|
50
|
0
|
|
47
|
my $logger = $self->logger || sub { $env->{'psgi.errors'}->print(@_) }; |
|
0
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
12
|
|
|
|
|
38
|
my $res = $self->app->($env); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
return $self->response_cb($res, sub { |
20
|
12
|
|
|
12
|
|
20
|
my $res = shift; |
21
|
12
|
|
|
|
|
31
|
my($status, $header, $body) = @$res; |
22
|
|
|
|
|
|
|
|
23
|
12
|
100
|
|
|
|
40
|
if (!defined $body) { |
24
|
3
|
|
|
|
|
6
|
my $length; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
return sub { |
27
|
6
|
|
|
|
|
11
|
my $line = shift; |
28
|
|
|
|
|
|
|
|
29
|
6
|
100
|
|
|
|
15
|
$length += length $line if defined $line; |
30
|
|
|
|
|
|
|
|
31
|
6
|
100
|
|
|
|
13
|
unless( defined $line ) { |
32
|
3
|
|
|
|
|
9
|
my $now = [Time::HiRes::gettimeofday]; |
33
|
3
|
|
|
|
|
10
|
$logger->( $self->log_line($status, $header, $env, { time => scalar Time::HiRes::tv_interval($time, $now) * 1_000_000, content_length => $length }) ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
6
|
|
|
|
|
491
|
return $line; |
37
|
3
|
|
|
|
|
13
|
}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
9
|
50
|
|
|
|
91
|
my $getline = ref $body eq 'ARRAY' ? sub { shift @$body } : sub { $body->getline }; |
|
17
|
|
|
|
|
34
|
|
|
0
|
|
|
|
|
0
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $timer_body = Plack::Util::inline_object( |
43
|
|
|
|
|
|
|
getline => sub { |
44
|
17
|
|
|
|
|
31
|
my $line = $getline->(); |
45
|
17
|
100
|
|
|
|
62
|
$length += length $line if defined $line; |
46
|
17
|
|
|
|
|
72
|
return $line; |
47
|
|
|
|
|
|
|
}, |
48
|
|
|
|
|
|
|
close => sub { |
49
|
9
|
50
|
|
|
|
29
|
$body->close if ref $body ne 'ARRAY'; |
50
|
|
|
|
|
|
|
|
51
|
9
|
|
|
|
|
38
|
my $now = [Time::HiRes::gettimeofday]; |
52
|
9
|
|
|
|
|
44
|
$logger->( $self->log_line($status, $header, $env, { time => scalar Time::HiRes::tv_interval($time, $now) * 1_000_000, content_length => $length }) ); |
53
|
|
|
|
|
|
|
}, |
54
|
9
|
|
|
|
|
103
|
); |
55
|
|
|
|
|
|
|
|
56
|
9
|
|
|
|
|
40
|
@$res = ($status, $header, $timer_body); |
57
|
12
|
|
|
|
|
141
|
}); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |