blib/lib/Plack/Handler/Gazelle.pm

filter: Statementstmt 67.1% 135 / 201 Branchbran 36.2% 37 / 102 Conditioncond 47.3% 18 / 38 MC/DCmcdc 9.0% 2 / 22 Subroutinesub 84.3% 27 / 32 Podpod 0.0% 0 / 3 totaltotal 55.0% 219 / 398 CC 68 SCAR 41.3
CC
68
Cov
56%
__ANON__
148.0
new
82.5
_handle_response
24.1
CRAP 62.2
↑ Summary builder/MyBuilder.pm »
1 package Plack::Handler::Gazelle;
2  
3 44 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 44 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 44 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 44 ▶use Plack::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 44 ▶use Stream::Buffered;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 44 ▶use POSIX qw(EINTR EAGAIN EWOULDBLOCK);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 44 ▶use Socket qw(IPPROTO_TCP TCP_NODELAY);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 44 ▶use Parallel::Prefork;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 44 ▶use Server::Starter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 44 ▶use Guard;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 44 our $VERSION = "0.51";
16  
17 44 ▶use XSLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 44 XSLoader::load(__PACKAGE__, $VERSION);
19  
20 44 ▶use constant MAX_REQUEST_SIZE => 131072;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 44 ▶use constant CHUNKSIZE => 64 * 1024;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 44 ▶use constant MAX_CHUNK_LINE => 4096;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 44 my $null_io = do { open my $io, "<", \""; $io };
25 44 my $bad_response = [ 400, [ 'Content-Type' => 'text/plain', 'Connection' => 'close' ], [ 'Bad Request' ] ];
26  
27 43 ▶sub new {
Subroutine new: called CC=22 SCAR=44.1
Pod undocumented
28 43 my($class, %args) = @_;
29  
30 # setup before instantiation
31 43 ▶ if ($args{listen_sock}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'listen_sock'}) { } 0 43 43
elsif (defined $ENV{'SERVER_STARTER_PORT'}) { } 0 43 43
32 0 $args{host} = $args{listen_sock}->sockhost;
33 0 $args{port} = $args{listen_sock}->sockport;
34 }
35 elsif (defined $ENV{SERVER_STARTER_PORT}) {
36 0 my ($hostport, $fd) = %{Server::Starter::server_ports()};
37 0 ▶ if ($hostport =~ /(.*):(\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hostport =~ /(.*):(\d+)/) { } 0 0 0
38 0 $args{host} = $1;
39 0 $args{port} = $2;
40 } else {
41 0 $args{port} = $hostport;
42 }
43 0 ▶ $args{listen_sock} = IO::Socket::INET->new(
Branch: 1 branch
BranchTrueFalseTotal
$args{"listen_sock"} = "IO::Socket::INET"->new("Proto", "tcp") or die "failed to create socket:$!" 0 0 0
44 Proto => 'tcp',
45 ) or die "failed to create socket:$!";
46 0 ▶ $args{listen_sock}->fdopen($fd, 'w')
Branch: 1 branch
BranchTrueFalseTotal
$args{"listen_sock"}->fdopen($fd, "w") or die "failed to bind to listening socket:$!" 0 0 0
47 or die "failed to bind to listening socket:$!";
48 }
49  
50 43 my $max_workers = 10;
51 43 for (qw(max_workers workers)) {
52 $max_workers = delete $args{$_}
53 86 ▶ if defined $args{$_};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{$_} 5 81 86
54 }
55  
56 43 ▶ if ($args{child_exit}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"child_exit"}) 2 41 43
57 2 ▶ $args{child_exit} = eval $args{child_exit} unless ref($args{child_exit});
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args{"child_exit"} 2 0 2
58 2 ▶ die "child_exit is defined but not a code block" if ref($args{child_exit}) ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $args{"child_exit"} ne "CODE" 0 2 2
59 }
60  
61 my $self = bless {
62 server_software => $args{server_software} || $class,
63 41 ▶ server_ready => $args{server_ready} || sub {},
Subroutine __ANON__: called CC=1 SCAR=0.0
64 listen_sock => $args{listen_sock},
65 host => $args{host} || 0,
66 port => $args{port} || 8080,
67 timeout => $args{timeout} || 300,
68 max_workers => $max_workers,
69 21 ▶ child_exit => $args{child_exit} || sub {},
Subroutine __ANON__: called CC=1 SCAR=0.0
70 min_reqs_per_child => (
71 defined $args{min_reqs_per_child}
72 ? $args{min_reqs_per_child} : undef,
73 ),
74 max_reqs_per_child => (
75 $args{max_reqs_per_child} || $args{max_requests} || 1000,
76 ),
77 spawn_interval => $args{spawn_interval} || 0,
78 err_respawn_interval => (
79 defined $args{err_respawn_interval}
80 ? $args{err_respawn_interval} : undef,
81 43 ▶ ),
Branch: 2 branches
BranchTrueFalseTotal
defined $args{'min_reqs_per_child'} ? : 0 43 43
defined $args{'err_respawn_interval'} ? : 0 43 43
Condition54%12/22
$args{'server_software'} || $class
l!l&&r!l&&!r
0430
$args{'server_ready'} || sub { }
l!l&&r!l&&!r
2410
$args{'host'} || 0
l!l
349
$args{'port'} || 8080
l!l
430
$args{'timeout'} || 300
l!l
043
$args{'child_exit'} || sub { }
l!l&&r!l&&!r
2410
$args{'max_reqs_per_child'} || $args{'max_requests'} || 1000
l!l
043
$args{"max_reqs_per_child"} or $args{"max_requests"}
l!l&&r!l&&!r
0043
$args{'spawn_interval'} || 0
l!l
043
MC/DC0%0/2
$args{'server_software'} || $class
$args{'server_software'} $class
MC/DC0%0/2
$args{'server_ready'} || sub { }
$args{'server_ready'} sub { }
MC/DC100%1/1
$args{'host'} || 0
$args{'host'}
MC/DC0%0/1
$args{'port'} || 8080
$args{'port'}
MC/DC0%0/1
$args{'timeout'} || 300
$args{'timeout'}
MC/DC0%0/2
$args{'child_exit'} || sub { }
$args{'child_exit'} sub { }
MC/DC0%0/2
$args{'max_reqs_per_child'} || $args{'max_requests'} || 1000
$args{"max_reqs_per_child"} $args{"max_requests"}
MC/DC0%0/1
$args{'spawn_interval'} || 0
$args{'spawn_interval'}
Truth table33%1/3
A || B
A= $args{'server_software'}B= $class
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= $args{'server_ready'}B= sub { }
ABresult
1X1
011
000
Truth table100%2/2
A
A= $args{'host'}
Aresult
11
00
Truth table50%1/2
A
A= $args{'port'}
Aresult
11
00
Truth table50%1/2
A
A= $args{'timeout'}
Aresult
11
00
Truth table66%2/3
A || B
A= $args{'child_exit'}B= sub { }
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= $args{"max_reqs_per_child"}B= $args{"max_requests"}
ABresult
1X1
011
000
Truth table50%1/2
A
A= $args{'spawn_interval'}
Aresult
11
00
82 }, $class;
83  
84 43 $self;
85 }
86  
87 43 ▶sub setup_listener {
Subroutine setup_listener: called CC=5 SCAR=18.1
Pod undocumented
88 43 my $self = shift;
89 $self->{listen_sock} ||= IO::Socket::INET->new(
90 Listen => SOMAXCONN,
91 LocalPort => $self->{port},
92 LocalAddr => $self->{host},
93 43 ▶ Proto => 'tcp',
Branch: 1 branch
BranchTrueFalseTotal
$self->{"listen_sock"} ||= "IO::Socket::INET"->new("Listen", 4096, "LocalPort", $self->{"port"}, "LocalAddr", $self->{"host"}, "Proto", "tcp", "ReuseAddr", 1) or die qq[failed to listen to port $self->{"port"}:$!] 43 0 43
Condition33%1/3
$self->{"listen_sock"} ||= "IO::Socket::INET"->new("Listen", 4096, "LocalPort", $self->{"port"}, "LocalAddr", $self->{"host"}, "Proto", "tcp", "ReuseAddr", 1)
l!l&&r!l&&!r
0430
MC/DC0%0/2
$self->{"listen_sock"} ||= "IO::Socket::INET"->new("Listen", 4096, "LocalPort", $self->{"port"}, "LocalAddr", $self->{"host"}, "Proto", "tcp", "ReuseAddr", 1)
$self->{"listen_sock"} "IO::Socket::INET"->new("Listen", 4096, "LocalPort", $self->{"port"}, "LocalAddr", $self->{"host"}, "Proto", "tcp", "ReuseAddr", 1)
Truth table33%1/3
A ||= B
A= $self->{"listen_sock"}B= "IO::Socket::INET"->new("Listen", 4096, "LocalPort", $self->{"port"}, "LocalAddr", $self->{"host"}, "Proto", "tcp", "ReuseAddr", 1)
ABresult
1X1
011
000
94 ReuseAddr => 1,
95 ) or die "failed to listen to port $self->{port}:$!";
96  
97 43 my $family = Socket::sockaddr_family(getsockname($self->{listen_sock}));
98 43 $self->{_listen_sock_is_tcp} = $family != AF_UNIX;
99  
100 # set defer accept
101 43 ▶ if ($^O eq 'linux' && $self->{_listen_sock_is_tcp}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "linux" and $self->{"_listen_sock_is_tcp"}) 43 0 43
Condition33%1/3
$^O eq "linux" and $self->{"_listen_sock_is_tcp"}
!ll&&!rl&&r
0043
MC/DC0%0/2
$^O eq "linux" and $self->{"_listen_sock_is_tcp"}
$^O eq "linux" $self->{"_listen_sock_is_tcp"}
Truth table33%1/3
A and B
A= $^O eq "linux"B= $self->{"_listen_sock_is_tcp"}
ABresult
0X0
100
111
102 43 setsockopt($self->{listen_sock}, IPPROTO_TCP, 9, 1);
103 }
104 43 $self->{server_ready}->($self);
105 }
106  
107  
108 43 ▶sub run {
Subroutine run: called CC=5 SCAR=20.5
Pod undocumented
109 43 my($self, $app) = @_;
110 43 $self->setup_listener();
111 # use Parallel::Prefork
112 my %pm_args = (
113 max_workers => $self->{max_workers},
114 43 trap_signals => {
115 HUP => 'TERM',
116 },
117 );
118 43 ▶ if (defined $self->{spawn_interval}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"spawn_interval"}) 43 0 43
119 43 $pm_args{trap_signals}{USR1} = [ 'TERM', $self->{spawn_interval} ];
120 43 $pm_args{spawn_interval} = $self->{spawn_interval};
121 }
122 43 ▶ if (defined $self->{err_respawn_interval}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"err_respawn_interval"}) 0 43 43
123 0 $pm_args{err_respawn_interval} = $self->{err_respawn_interval};
124 }
125 43 my $pm = Parallel::Prefork->new(\%pm_args);
126  
127 20 ▶ local $SIG{TERM} = sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
128 #tell the socket we're done reading (stops new connections, existing will continue)
129 $self->{listen_sock}->shutdown(0)
130 20 ▶ if not defined $ENV{SERVER_STARTER_PORT};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ENV{"SERVER_STARTER_PORT"} 20 0 20
131  
132 20 $pm->signal_received('TERM');
133 20 $pm->signal_all_children('TERM');
134 43 };
135 43 ▶ while ($pm->signal_received !~ /^(TERM|USR1)$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pm->signal_received =~ /^(TERM|USR1)$/) 43 20 63
136 23 ▶ $pm->start(sub{
Subroutine __ANON__: called CC=27 SCAR=50.0
137 23 srand((rand() * 2 ** 30) ^ $$ ^ time);
138  
139 my $max_reqs_per_child = $self->_calc_minmax_per_child(
140 $self->{max_reqs_per_child},
141 $self->{min_reqs_per_child}
142 23 );
143  
144 23 my $proc_req_count = 0;
145 23 $self->{term_received} = 0;
146 4 ▶ local $SIG{TERM} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
147 4 $self->{term_received}++;
148 23 };
149 23 local $SIG{PIPE} = 'IGNORE';
150 PROC_LOOP:
151 23 ▶ while ( $proc_req_count < $max_reqs_per_child) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proc_req_count < $max_reqs_per_child) 43502 0 43502
152 43502 ▶ if ( $self->{term_received} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"term_received"}) 4 43498 43502
153 4 $self->{child_exit}->($self, $app);
154 4 exit 0;
155 }
156 43498 ▶ if ( my ($conn, $buf, $env) = accept_psgi(
Branch: 1 branch
BranchTrueFalseTotal
if (() = accept_psgi(fileno $self->{"listen_sock"}, $self->{"timeout"}, $self->{"_listen_sock_is_tcp"}, $self->{"host"} || 0, $self->{"port"} || 0)) 27 43471 43498
Condition75%3/4
$self->{'host'} || 0
l!l
2043478
$self->{'port'} || 0
l!l
434980
MC/DC100%1/1
$self->{'host'} || 0
$self->{'host'}
MC/DC0%0/1
$self->{'port'} || 0
$self->{'port'}
Truth table100%2/2
A
A= $self->{'host'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'port'}
Aresult
11
00
157 fileno($self->{listen_sock}), $self->{timeout}, $self->{_listen_sock_is_tcp},
158 $self->{host} || 0, $self->{port} || 0
159 ) ) {
160 27 ▶ my $guard = guard { close_client($conn) };
Subroutine __ANON__: called CC=1 SCAR=0.0
161 27 ++$proc_req_count;
162  
163 27 my $res = $bad_response;
164 44 ▶ my $chunked = do { no warnings; lc delete $env->{HTTP_TRANSFER_ENCODING} eq 'chunked' };
Subroutine BEGIN: called CC=1 SCAR=0.0
165 # RFC 7230 ยง3.3.3: Transfer-Encoding takes precedence over
166 # Content-Length. Requests carrying both are rejected upstream
167 # in the XS layer; this ordering is defence-in-depth.
168 27 ▶ if ( $chunked ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($chunked) { } 0 27 27
elsif (my $cl = $env->{'CONTENT_LENGTH'}) { } 1 26 27
169 0 my $buffer = Stream::Buffered->new;
170 0 my $chunk_buffer = '';
171 0 my $length = 0;
172 0 my $chunk_left = 0;
173 0 DECHUNK: while(1) {
174 0 my $chunk = "";
175 0 ▶ if ( length $buf ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $buf) { } 0 0 0
176 0 $chunk = $buf;
177 0 $buf = '';
178 }
179 else {
180 read_timeout(
181 $conn, \$chunk, 16384, 0, $self->{timeout})
182 0 ▶ or next PROC_LOOP;
Branch: 1 branch
BranchTrueFalseTotal
read_timeout($conn, \$chunk, 16384, 0, $self->{"timeout"}) or next PROC_LOOP 0 0 0
183 }
184  
185 0 $chunk_buffer .= $chunk;
186 0 while (1) {
187 0 ▶ if ($chunk_left > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk_left > 2) 0 0 0
188 0 my $n = $chunk_left - 2;
189 0 ▶ $n = length $chunk_buffer if length $chunk_buffer < $n;
Branch: 1 branch
BranchTrueFalseTotal
if length $chunk_buffer < $n 0 0 0
190 0 ▶ last unless $n;
Branch: 1 branch
BranchTrueFalseTotal
unless $n 0 0 0
191 0 $buffer->print(substr $chunk_buffer, 0, $n, '');
192 0 $length += $n;
193 0 $chunk_left -= $n;
194 0 next;
195 }
196 0 ▶ if ($chunk_left) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk_left) 0 0 0
197 0 ▶ last if length $chunk_buffer < 2;
Branch: 1 branch
BranchTrueFalseTotal
if length $chunk_buffer < 2 0 0 0
198 0 $chunk_buffer =~ s/^\015\012//;
199 0 $chunk_left = 0;
200 }
201 # atomic hex run: an unmatchable size line fails in linear time
202 0 ▶ $chunk_buffer =~ s/^((?>([0-9a-fA-F]+))[^\012]*\015\012)//
Branch: 1 branch
BranchTrueFalseTotal
$chunk_buffer =~ s/^((?>([0-9a-fA-F]+))[^\012]*\015\012)// or last 0 0 0
203 or last;
204 0 ▶ next PROC_LOOP if length $1 > MAX_CHUNK_LINE;
Branch: 1 branch
BranchTrueFalseTotal
if length $1 > 4096 0 0 0
205 0 my $chunk_len = hex $2;
206 0 ▶ last DECHUNK if $chunk_len == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $chunk_len == 0 0 0 0
207 0 $chunk_left = $chunk_len + 2;
208 }
209 0 ▶ next PROC_LOOP if !$chunk_left && length $chunk_buffer > MAX_CHUNK_LINE;
Branch: 1 branch
BranchTrueFalseTotal
if not $chunk_left and length $chunk_buffer > 4096 0 0 0
Condition0%0/3
not $chunk_left and length $chunk_buffer > 4096
!ll&&!rl&&r
000
MC/DC0%0/2
not $chunk_left and length $chunk_buffer > 4096
not $chunk_left length $chunk_buffer > 4096
Truth table0%0/3
not(A) and B
A= not $chunk_leftB= length $chunk_buffer > 4096
ABresult
0X0
100
111
210 }
211 0 $env->{CONTENT_LENGTH} = $length;
212 0 $env->{'psgi.input'} = $buffer->rewind;
213 } elsif (my $cl = $env->{CONTENT_LENGTH}) {
214 1 my $buffer = Stream::Buffered->new($cl);
215 1 ▶ while ($cl > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cl > 0) 1 1 2
216 1 my $chunk = "";
217 1 ▶ if (length $buf) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $buf) { } 1 0 1
218 1 $chunk = $buf;
219 1 $buf = '';
220 } else {
221 read_timeout(
222 $conn, \$chunk, $cl, 0, $self->{timeout})
223 0 ▶ or next PROC_LOOP;
Branch: 1 branch
BranchTrueFalseTotal
read_timeout($conn, \$chunk, $cl, 0, $self->{"timeout"}) or next PROC_LOOP 0 0 0
224 }
225 1 $buffer->print($chunk);
226 1 $cl -= length $chunk;
227 }
228 1 $env->{'psgi.input'} = $buffer->rewind;
229 } else {
230 26 $env->{'psgi.input'} = $null_io;
231 }
232 0 ▶ $env->{'psgix.informational'} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
233 0 my ($status,$headers) = @_;
234 0 write_informational_response($conn, $self->{timeout}, $status, $headers);
235 27 };
236 27 $res = Plack::Util::run_app $app, $env;
237 26 ▶ my $use_chunked = $env->{"SERVER_PROTOCOL"} eq 'HTTP/1.1' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$env->{'SERVER_PROTOCOL'} eq 'HTTP/1.1' ? : 18 8 26
238 26 ▶ if (ref $res eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $res eq 'ARRAY') { } 26 0 26
elsif (ref $res eq 'CODE') { } 0 0 0
239 26 $self->_handle_response($res, $conn, $use_chunked);
240 } elsif (ref $res eq 'CODE') {
241 0 ▶ $res->(sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
242 0 $self->_handle_response($_[0], $conn, $use_chunked);
243 0 });
244 } else {
245 0 die "Bad response $res";
246 }
247 26 ▶ if ($env->{'psgix.harakiri.commit'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($env->{"psgix.harakiri.commit"}) 18 8 26
248 18 $self->{child_exit}->($self, $app);
249 18 exit 0;
250 }
251 }
252 }
253 43 });
254 }
255 20 ▶ while ($pm->wait_all_children(1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pm->wait_all_children(1)) 17 20 37
256 17 $pm->signal_all_children('TERM');
257 }
258 }
259  
260 23 ▶sub _calc_minmax_per_child {
Subroutine _calc_minmax_per_child: called CC=2 SCAR=7.4
261 23 my $self = shift;
262 23 my ($max,$min) = @_;
263 23 ▶ if (defined $min) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $min) { } 0 23 23
264 0 return $max - int(($max - $min + 1) * rand);
265 } else {
266 23 return $max;
267 }
268 }
269  
270 26 ▶sub _handle_response {
Subroutine _handle_response: called CC=6 SCAR=31.8
271 26 my($self, $res, $conn, $use_chunked) = @_;
272 26 my $status_code = $res->[0];
273 26 my $headers = $res->[1];
274 26 my $body = $res->[2];
275  
276 26 ▶ if (defined $body && ref $body eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $body and ref $body eq "ARRAY") 26 0 26
Condition33%1/3
defined $body and ref $body eq "ARRAY"
!ll&&!rl&&r
0026
MC/DC0%0/2
defined $body and ref $body eq "ARRAY"
defined $body ref $body eq "ARRAY"
Truth table33%1/3
A and B
A= defined $bodyB= ref $body eq "ARRAY"
ABresult
0X0
100
111
277 26 write_psgi_response($conn, $self->{timeout}, $status_code, $headers , $body, $use_chunked);
278 26 return;
279 }
280  
281 0 ▶ write_psgi_response_header($conn, $self->{timeout}, $status_code, $headers, [], $use_chunked) or return;
Branch: 1 branch
BranchTrueFalseTotal
write_psgi_response_header($conn, $self->{"timeout"}, $status_code, $headers, scalar [], $use_chunked) or return 0 0 0
282  
283 0 ▶ if (defined $body) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $body) { } 0 0 0
284 0 my $failed;
285 Plack::Util::foreach(
286 $body,
287 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
288 0 ▶ return if $failed;
Branch: 1 branch
BranchTrueFalseTotal
if $failed 0 0 0
289 0 my $ret;
290 0 ▶ if ( $use_chunked ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_chunked) { } 0 0 0
291 0 $ret = write_chunk($conn, $_[0], 0, $self->{timeout});
292 }
293 else {
294 0 $ret = write_all($conn, $_[0], 0, $self->{timeout});
295 }
296 0 ▶ $failed = 1 if ! defined $ret;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ret 0 0 0
297 },
298 0 );
299 0 ▶ write_all($conn, "0\015\012\015\012", 0, $self->{timeout}) if $use_chunked;
Branch: 1 branch
BranchTrueFalseTotal
if $use_chunked 0 0 0
300 } else {
301 return Plack::Util::inline_object
302 0 ▶ write => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
303 0 ▶ if ( $use_chunked ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_chunked) { } 0 0 0
304 0 write_chunk($conn, $_[0], 0, $self->{timeout});
305 }
306 else {
307 0 write_all($conn, $_[0], 0, $self->{timeout});
308 }
309 },
310 0 ▶ close => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
311 0 ▶ write_all($conn, "0\015\012\015\012", 0, $self->{timeout}) if $use_chunked;
Branch: 1 branch
BranchTrueFalseTotal
if $use_chunked 0 0 0
312 0 };
313 }
314 }
315  
316 44 1;
↑ Summary builder/MyBuilder.pm »