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   287 use strict;
  41         80  
  41         2277  
3 41     41   280 use warnings;
  41         80  
  41         2921  
4 41     41   356 use parent qw( Plack::Middleware );
  41         81  
  41         293  
5              
6 41     41   4500 use Plack::Util;
  41         44  
  41         19229  
7              
8             sub call {
9 709     709 1 1458 my $self = shift;
10 709         10978 my $res = $self->app->(@_);
11              
12             return $self->response_cb($res, sub {
13 672     672   7771 my $res = shift;
14 672         7831 my $h = Plack::Util::headers($res->[1]);
15 672 100 66     3931 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         3676 $h->push('Content-Length' => $content_length);
20             }
21 672         33748 });
22             }
23              
24             1;
25              
26             __END__