File Coverage

blib/lib/Plack/Middleware/BufferedStreaming.pm
Criterion Covered Total %
statement 39 39 100.0
branch 5 6 83.3
condition 1 3 33.3
subroutine 9 9 100.0
pod 1 1 100.0
total 55 58 94.8


line stmt bran cond sub pod time code
1             package Plack::Middleware::BufferedStreaming;
2 39     39   196 use strict;
  39         77  
  39         1133  
3 39     39   118 no warnings;
  39         115  
  39         2212  
4 39     39   193 use Carp;
  39         40  
  39         1934  
5 39     39   158 use Plack::Util;
  39         77  
  39         802  
6 39     39   156 use Plack::Util::Accessor qw(force);
  39         77  
  39         233  
7 39     39   117 use Scalar::Util qw(weaken);
  39         78  
  39         1642  
8 39     39   193 use parent qw(Plack::Middleware);
  39         39  
  39         196  
9              
10             sub call {
11 39     39 1 541 my ( $self, $env ) = @_;
12              
13 39         896 my $caller_supports_streaming = $env->{'psgi.streaming'};
14 39         310 $env->{'psgi.streaming'} = Plack::Util::TRUE;
15              
16 39         1451 my $res = $self->app->($env);
17 38 50 33     1577 return $res if $caller_supports_streaming && !$self->force;
18              
19 38 100       28524 if ( ref($res) eq 'CODE' ) {
20 4         29 my $ret;
21              
22             $res->(sub {
23 4     4   40 my $write = shift;
24              
25 4 100       46 if ( @$write == 2 ) {
26 2         4 my @body;
27              
28 2         11 $ret = [ @$write, \@body ];
29              
30             return Plack::Util::inline_object(
31 4         11 write => sub { push @body, $_[0] },
32             close => sub { },
33 2         20637 );
34             } else {
35 2         13 $ret = $write;
36 2         13 return;
37             }
38 4         63 });
39              
40 4         29 return $ret;
41             } else {
42 34         201 return $res;
43             }
44             }
45              
46             1;
47              
48             __END__