File Coverage

blib/lib/Plack/Middleware/Runtime.pm
Criterion Covered Total %
statement 23 23 100.0
branch n/a
condition 1 2 50.0
subroutine 7 7 100.0
pod 1 1 100.0
total 32 33 96.9


line stmt bran cond sub pod time code
1             package Plack::Middleware::Runtime;
2 2     2   16 use strict;
  2         4  
  2         101  
3 2     2   13 use parent qw(Plack::Middleware);
  2         3  
  2         12  
4 2     2   132 use Plack::Util;
  2         3  
  2         52  
5 2     2   10 use Plack::Util::Accessor qw(header_name);
  2         3  
  2         13  
6 2     2   1107 use Time::HiRes;
  2         2978  
  2         8  
7              
8             sub call {
9 5     5 1 12 my($self, $env) = @_;
10              
11 5         22 my $start = [ Time::HiRes::gettimeofday ];
12 5         32 my $res = $self->app->($env);
13 5   50     1000360 my $header = $self->header_name || 'X-Runtime';
14              
15             $self->response_cb($res, sub {
16 5     5   13 my $res = shift;
17 5         24 my $req_time = sprintf '%.6f', Time::HiRes::tv_interval($start);
18 5         171 Plack::Util::header_set($res->[1], $header, $req_time);
19 5         108 });
20             }
21              
22             1;
23              
24             __END__