« blib/lib/Plack/Middleware/BufferedStreaming.pm
↑ Summary
blib/lib/Plack/Middleware/SimpleLogger.pm »
| 1 | package Plack::Middleware::AccessLog::Timed; | ||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use parent qw( Plack::Middleware::AccessLog ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 2 | ▶ | use Time::HiRes; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 2 | ▶ | use Plack::Util; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 12 | ▶ | sub call { | ||||||||||||||||||
|
Subroutine
call: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 10 | 12 | my $self = shift; | |||||||||||||||||||
| 11 | 12 | my($env) = @_; | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 12 | my $time = [Time::HiRes::gettimeofday]; | |||||||||||||||||||
| 14 | 12 | my $length = 0; | |||||||||||||||||||
| 15 | 0 | ▶ | my $logger = $self->logger || sub { $env->{'psgi.errors'}->print(@_) }; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.0
Condition33%1/3
$self->logger || sub {
$env->{'psgi.errors'}->print(@_);
}
MC/DC0%0/2
$self->logger || sub {
$env->{'psgi.errors'}->print(@_);
}
$self->logger
sub {
$env->{'psgi.errors'}->print(@_);
}
Truth table33%1/3
A || B
A= $self->loggerB= sub {
$env->{'psgi.errors'}->print(@_);
}
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 12 | my $res = $self->app->($env); | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 12 | ▶ | return $self->response_cb($res, sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 20 | 12 | my $res = shift; | |||||||||||||||||||
| 21 | 12 | my($status, $header, $body) = @$res; | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 12 | ▶ | if (!defined $body) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | 3 | my $length; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 6 | ▶ | return sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 27 | 6 | my $line = shift; | |||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 6 | ▶ | $length += length $line if defined $line; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 6 | ▶ | unless( defined $line ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | 3 | my $now = [Time::HiRes::gettimeofday]; | |||||||||||||||||||
| 33 | 3 | $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 | return $line; | |||||||||||||||||||
| 37 | 3 | }; | |||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 0 | ▶ | my $getline = ref $body eq 'ARRAY' ? sub { shift @$body } : sub { $body->getline }; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.6
Subroutine
__ANON__: not called CC=1 SCAR=0.6
Branch: 1 branch
| |||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | my $timer_body = Plack::Util::inline_object( | ||||||||||||||||||||
| 43 | 17 | ▶ | getline => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 44 | 17 | my $line = $getline->(); | |||||||||||||||||||
| 45 | 17 | ▶ | $length += length $line if defined $line; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | 17 | return $line; | |||||||||||||||||||
| 47 | }, | ||||||||||||||||||||
| 48 | 9 | ▶ | close => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||
| 49 | 9 | ▶ | $body->close if ref $body ne 'ARRAY'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 9 | my $now = [Time::HiRes::gettimeofday]; | |||||||||||||||||||
| 52 | 9 | $logger->( $self->log_line($status, $header, $env, { time => scalar Time::HiRes::tv_interval($time, $now) * 1_000_000, content_length => $length }) ); | |||||||||||||||||||
| 53 | }, | ||||||||||||||||||||
| 54 | 9 | ); | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 9 | @$res = ($status, $header, $timer_body); | |||||||||||||||||||
| 57 | 12 | }); | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 2 | 1; | |||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | __END__ | ||||||||||||||||||||