File Coverage

blib/lib/Plack/Middleware/ContentLength.pm
Criterion Covered Total %
statement 19 19 100.0
branch 2 2 100.0
condition 5 6 83.3
subroutine 6 6 100.0
pod 1 1 100.0
total 33 34 97.0


line stmt bran cond sub pod time code
1             package Plack::Middleware::ContentLength;
2 41     41   246 use strict;
  41         80  
  41         1478  
3 41     41   165 use warnings;
  41         82  
  41         1181  
4 41     41   201 use parent qw( Plack::Middleware );
  41         82  
  41         207  
5              
6 41     41   2737 use Plack::Util;
  41         81  
  41         9612  
7              
8             sub call {
9 709     709 1 2088 my $self = shift;
10 709         9443 my $res = $self->app->(@_);
11              
12             return $self->response_cb($res, sub {
13 672     672   1959 my $res = shift;
14 672         8818 my $h = Plack::Util::headers($res->[1]);
15 672 100 66     3799 if (!Plack::Util::status_with_no_entity_body($res->[0]) &&
      100        
16             !$h->exists('Content-Length') &&
17             !$h->exists('Transfer-Encoding') &&
18             defined(my $content_length = Plack::Util::content_length($res->[2]))) {
19 586         4466 $h->push('Content-Length' => $content_length);
20             }
21 672         35030 });
22             }
23              
24             1;
25              
26             __END__