blib/lib/HTTP/Server/PSGI.pm

filter: Statementstmt 85.4% 170 / 199 Branchbran 55.2% 42 / 76 Conditioncond 50.0% 16 / 32 MC/DCmcdc 26.3% 5 / 19 Subroutinesub 90.7% 39 / 43 Podpod 0.0% 0 / 10 totaltotal 71.7% 272 / 379 CC 52 SCAR 22.9
CC
52
Cov
74%
prepare_socket_class
45.2
handle_connection
18.0
new
8.2
CRAP 9.9
« blib/lib/Plack/App/WrapCGI.pm ↑ Summary blib/lib/Plack/Loader/Restarter.pm »
1 package HTTP::Server::PSGI;
2 41 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 41 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 41 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 41 ▶use Plack;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 41 ▶use Plack::HTTPParser qw( parse_http_request );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 41 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 41 ▶use HTTP::Date;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 41 ▶use HTTP::Status;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 41 ▶use List::Util qw(max sum);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 41 ▶use Plack::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 41 ▶use Stream::Buffered;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 41 ▶use Plack::Middleware::ContentLength;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 41 ▶use POSIX qw(EINTR);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 41 ▶use Socket qw(IPPROTO_TCP);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 41 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 41 ▶use Time::HiRes qw(time);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 41 ▶use constant TCP_NODELAY => try { Socket::TCP_NODELAY };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
22  
23 41 my $alarm_interval;
24 41 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.6
25 41 ▶ if ($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 41 41
26 0 $alarm_interval = 1;
27 } else {
28 41 Time::HiRes->import('alarm');
29 41 $alarm_interval = 0.1;
30 }
31 }
32  
33 41 ▶use constant MAX_REQUEST_SIZE => 131072;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 41 ▶use constant CHUNKSIZE => 64 * 1024;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 41 ▶use constant MSWin32 => $^O eq 'MSWin32';
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 39 ▶sub new {
Subroutine new: called CC=7 SCAR=21.1
Pod undocumented
38 39 my($class, %args) = @_;
39  
40 my $self = bless {
41 ($args{listen_sock} ? (
42 listen_sock => $args{listen_sock},
43 host => $args{listen_sock}->sockhost,
44 port => $args{listen_sock}->sockport,
45 ):(
46 host => $args{host} || 0,
47 port => $args{port} || 8080,
48 )),
49 timeout => $args{timeout} || 300,
50 server_software => $args{server_software} || $class,
51 37 ▶ server_ready => $args{server_ready} || sub {},
Subroutine __ANON__: called CC=1 SCAR=0.0
52 ssl => $args{ssl},
53 ipv6 => $args{ipv6},
54 ssl_key_file => $args{ssl_key_file},
55 ssl_cert_file => $args{ssl_cert_file},
56 39 ▶ }, $class;
Branch: 1 branch
BranchTrueFalseTotal
$args{'listen_sock'} ? : 0 39 39
Condition66%8/12
$args{"host"} or 0
l!l
372
$args{"port"} or 8080
l!l
372
$args{'timeout'} || 300
l!l
237
$args{'server_software'} || $class
l!l&&r!l&&!r
0390
$args{'server_ready'} || sub { }
l!l&&r!l&&!r
0390
MC/DC100%1/1
$args{"host"} or 0
$args{"host"}
MC/DC100%1/1
$args{"port"} or 8080
$args{"port"}
MC/DC100%1/1
$args{'timeout'} || 300
$args{'timeout'}
MC/DC0%0/2
$args{'server_software'} || $class
$args{'server_software'} $class
MC/DC0%0/2
$args{'server_ready'} || sub { }
$args{'server_ready'} sub { }
Truth table100%2/2
A
A= $args{"host"}
Aresult
11
00
Truth table100%2/2
A
A= $args{"port"}
Aresult
11
00
Truth table100%2/2
A
A= $args{'timeout'}
Aresult
11
00
Truth table33%1/3
A || B
A= $args{'server_software'}B= $class
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $args{'server_ready'}B= sub { }
ABresult
1X1
011
000
57  
58 39 $self;
59 }
60  
61 37 ▶sub run {
Subroutine run: called CC=1 SCAR=0.0
Pod undocumented
62 37 my($self, $app) = @_;
63 37 $self->setup_listener();
64 37 $self->accept_loop($app);
65 }
66  
67 37 ▶sub prepare_socket_class {
Subroutine prepare_socket_class: called CC=9 SCAR=38.1
Pod undocumented
68 37 my($self, $args) = @_;
69  
70 37 ▶ if ($self->{ssl} && $self->{ipv6}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ssl"} and $self->{"ipv6"}) 0 37 37
Condition33%1/3
$self->{"ssl"} and $self->{"ipv6"}
!ll&&!rl&&r
3700
MC/DC0%0/2
$self->{"ssl"} and $self->{"ipv6"}
$self->{"ssl"} $self->{"ipv6"}
Truth table33%1/3
A and B
A= $self->{"ssl"}B= $self->{"ipv6"}
ABresult
0X0
100
111
71 0 Carp::croak("SSL and IPv6 are not supported at the same time (yet). Choose one.");
72 }
73  
74 37 ▶ if ($self->{ssl}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'ssl'}) { } 0 37 37
elsif ($self->{'ipv6'}) { } 0 37 37
75 0 ▶ eval { require IO::Socket::SSL; 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require IO::Socket::SSL; 1 } } or Carp::croak("SSL suport requires IO::Socket::SSL") 0 0 0
76 or Carp::croak("SSL suport requires IO::Socket::SSL");
77 0 $args->{SSL_key_file} = $self->{ssl_key_file};
78 0 $args->{SSL_cert_file} = $self->{ssl_cert_file};
79 0 return "IO::Socket::SSL";
80 } elsif ($self->{ipv6}) {
81 0 ▶ eval { require IO::Socket::IP; 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require IO::Socket::IP; 1 } } or Carp::croak("IPv6 support requires IO::Socket::IP") 0 0 0
82 or Carp::croak("IPv6 support requires IO::Socket::IP");
83 0 ▶ $self->{host} ||= '::';
Condition0%0/2
$self->{"host"} ||= "::"
l!l
00
MC/DC0%0/1
$self->{"host"} ||= "::"
$self->{"host"}
Truth table0%0/2
A
A= $self->{"host"}
Aresult
11
00
84 0 ▶ $args->{LocalAddr} ||= '::';
Condition0%0/2
$args->{"LocalAddr"} ||= "::"
l!l
00
MC/DC0%0/1
$args->{"LocalAddr"} ||= "::"
$args->{"LocalAddr"}
Truth table0%0/2
A
A= $args->{"LocalAddr"}
Aresult
11
00
85 0 return "IO::Socket::IP";
86 }
87  
88 37 return "IO::Socket::INET";
89 }
90  
91 37 ▶sub setup_listener {
Subroutine setup_listener: called CC=4 SCAR=15.0
Pod undocumented
92 37 my $self = shift;
93  
94 37 ▶ $self->{listen_sock} ||= do {
Condition33%1/3
$self->{"listen_sock"} ||= do { my(%args) = ("Listen", 4096, "LocalPort", $self->{"port"}, "LocalAddr", $self->{"host"}, "Proto", "tcp", "ReuseAddr", 1); my $class = $self->prepare_socket_class(\%args); $class->new(%args) or die qq[failed to listen to port $self->{"port"}: $!] }
l!l&&r!l&&!r
0370
MC/DC0%0/2
$self->{"listen_sock"} ||= do { my(%args) = ("Listen", 4096, "LocalPort", $self->{"port"}, "LocalAddr", $self->{"host"}, "Proto", "tcp", "ReuseAddr", 1); my $class = $self->prepare_socket_class(\%args); $class->new(%args) or die qq[failed to listen to port $self->{"port"}: $!] }
$self->{"listen_sock"} do { my(%args) = ("Listen", 4096, "LocalPort", $self->{"port"}, "LocalAddr", $self->{"host"}, "Proto", "tcp", "ReuseAddr", 1); my $class = $self->prepare_socket_class(\%args); $class->new(%args) or die qq[failed to listen to port $self->{"port"}: $!] }
Truth table33%1/3
A ||= B
A= $self->{"listen_sock"}B= do { my(%args) = ("Listen", 4096, "LocalPort", $self->{"port"}, "LocalAddr", $self->{"host"}, "Proto", "tcp", "ReuseAddr", 1); my $class = $self->prepare_socket_class(\%args); $class->new(%args) or die qq[failed to listen to port $self->{"port"}: $!] }
ABresult
1X1
011
000
95 my %args = (
96 Listen => SOMAXCONN,
97 LocalPort => $self->{port},
98 LocalAddr => $self->{host},
99 37 Proto => 'tcp',
100 ReuseAddr => 1,
101 );
102  
103 37 my $class = $self->prepare_socket_class(\%args);
104 37 ▶ $class->new(%args)
Condition50%1/2
$class->new(%args) || die("failed to listen to port $self->{'port'}: $!")
l!l
370
MC/DC0%0/1
$class->new(%args) || die("failed to listen to port $self->{'port'}: $!")
$class->new(%args)
Truth table50%1/2
A
A= $class->new(%args)
Aresult
11
00
105 or die "failed to listen to port $self->{port}: $!";
106 };
107  
108 37 ▶ $self->{server_ready}->({ %$self, proto => $self->{ssl} ? 'https' : 'http' });
Branch: 1 branch
BranchTrueFalseTotal
$self->{'ssl'} ? : 0 37 37
109 }
110  
111 37 ▶sub accept_loop {
Subroutine accept_loop: called CC=6 SCAR=18.7
Pod undocumented
112 37 my($self, $app) = @_;
113  
114 37 $app = Plack::Middleware::ContentLength->wrap($app);
115  
116 37 while (1) {
117 740 local $SIG{PIPE} = 'IGNORE';
118 740 ▶ if (my $conn = $self->{listen_sock}->accept) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $conn = $self->{"listen_sock"}->accept) 740 0 740
119 740 if (defined TCP_NODELAY) {
120 740 ▶ $conn->setsockopt(IPPROTO_TCP, TCP_NODELAY, 1)
Branch: 1 branch
BranchTrueFalseTotal
$conn->setsockopt(6, 1, 1) or die "setsockopt(TCP_NODELAY) failed:$!" 740 0 740
121 or die "setsockopt(TCP_NODELAY) failed:$!";
122 }
123 my $env = {
124 SERVER_PORT => $self->{port},
125 SERVER_NAME => $self->{host},
126 SCRIPT_NAME => '',
127 REMOTE_ADDR => $conn->peerhost,
128 REMOTE_PORT => $conn->peerport || 0,
129 'psgi.version' => [ 1, 1 ],
130 'psgi.errors' => *STDERR,
131 740 ▶ 'psgi.url_scheme' => $self->{ssl} ? 'https' : 'http',
Branch: 1 branch
BranchTrueFalseTotal
$self->{'ssl'} ? : 0 740 740
Condition50%1/2
$conn->peerport || 0
l!l
7400
MC/DC0%0/1
$conn->peerport || 0
$conn->peerport
Truth table50%1/2
A
A= $conn->peerport
Aresult
11
00
132 'psgi.run_once' => Plack::Util::FALSE,
133 'psgi.multithread' => Plack::Util::FALSE,
134 'psgi.multiprocess' => Plack::Util::FALSE,
135 'psgi.streaming' => Plack::Util::TRUE,
136 'psgi.nonblocking' => Plack::Util::FALSE,
137 'psgix.harakiri' => Plack::Util::TRUE,
138 'psgix.input.buffered' => Plack::Util::TRUE,
139 'psgix.io' => $conn,
140 };
141  
142 740 $self->handle_connection($env, $conn, $app);
143 703 $conn->close;
144 703 ▶ last if $env->{'psgix.harakiri.commit'};
Branch: 1 branch
BranchTrueFalseTotal
if $env->{"psgix.harakiri.commit"} 0 703 703
145 }
146 }
147 }
148  
149 765 ▶sub handle_connection {
Subroutine handle_connection: called CC=16 SCAR=28.9
Pod undocumented
150 765 my($self, $env, $conn, $app) = @_;
151  
152 765 my $buf = '';
153 765 my $res = [ 400, [ 'Content-Type' => 'text/plain' ], [ 'Bad Request' ] ];
154  
155 765 while (1) {
156 my $rlen = $self->read_timeout(
157 $conn, \$buf, MAX_REQUEST_SIZE - length($buf), length($buf),
158 $self->{timeout},
159 765 ▶ ) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $rlen = $self->read_timeout($conn, \$buf, 131072 - length($buf), length $buf, $self->{"timeout"}) or return 728 37 765
160 728 my $reqlen = parse_http_request($buf, $env);
161 728 ▶ if ($reqlen >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reqlen >= 0) 728 0 728
162 728 $buf = substr $buf, $reqlen;
163 728 ▶ if (defined $env->{HTTP_TRANSFER_ENCODING}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $env->{"HTTP_TRANSFER_ENCODING"}) 6 722 728
164 # request bodies with Transfer-Encoding are not supported
165 6 $res = [ 501, [ 'Content-Type' => 'text/plain' ], [ 'Not Implemented' ] ];
166 6 last;
167 }
168 722 ▶ if (defined $env->{CONTENT_LENGTH} && $env->{CONTENT_LENGTH} !~ /\A[0-9]{1,18}\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $env->{"CONTENT_LENGTH"} and not $env->{"CONTENT_LENGTH"} =~ /\A[0-9]{1,18}\z/) 9 713 722
Condition100%3/3
defined $env->{"CONTENT_LENGTH"} and not $env->{"CONTENT_LENGTH"} =~ /\A[0-9]{1,18}\z/
!ll&&!rl&&r
5971169
MC/DC100%2/2
defined $env->{"CONTENT_LENGTH"} and not $env->{"CONTENT_LENGTH"} =~ /\A[0-9]{1,18}\z/
defined $env->{"CONTENT_LENGTH"} not $env->{"CONTENT_LENGTH"} =~ /\A[0-9]{1,18}\z/
Truth table100%3/3
A and not(B)
A= defined $env->{"CONTENT_LENGTH"}B= not $env->{"CONTENT_LENGTH"} =~ /\A[0-9]{1,18}\z/
ABresult
0X0
100
111
169 # malformed, duplicate or too long (more than 18 digits) Content-Length
170 9 last;
171 }
172 713 ▶ if (my $cl = $env->{CONTENT_LENGTH}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cl = $env->{'CONTENT_LENGTH'}) { } 81 632 713
173 81 my $buffer = Stream::Buffered->new($cl);
174 81 ▶ while ($cl > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cl > 0) 123 79 202
175 123 my $chunk;
176 123 ▶ if (length $buf) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $buf) { } 11 112 123
177 # $cl may be beyond UV_MAX, which substr() can't take
178 11 ▶ $chunk = substr $buf, 0, ($cl < length $buf ? $cl : length $buf), '';
Branch: 1 branch
BranchTrueFalseTotal
$cl < length $buf ? : 1 10 11
179 } else {
180 $self->read_timeout($conn, \$chunk, $cl < CHUNKSIZE ? $cl : CHUNKSIZE, 0, $self->{timeout})
181 112 ▶ or return;
Branch: 2 branches
BranchTrueFalseTotal
$self->read_timeout($conn, \$chunk, $cl < 65536 ? $cl : 65536, 0, $self->{"timeout"}) or return 110 2 112
$cl < 65536 ? : 73 39 112
182 }
183 121 $buffer->print($chunk);
184 121 $cl -= length $chunk;
185 }
186 79 $env->{'psgi.input'} = $buffer->rewind;
187 } else {
188 632 open my $input, "<", \"";
189 632 $env->{'psgi.input'} = $input;
190 }
191  
192 711 $res = Plack::Util::run_app $app, $env;
193 674 last;
194 }
195 0 ▶ if ($reqlen == -2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($reqlen == -2) { } 0 0 0
elsif ($reqlen == -1) { } 0 0 0
196 # request is incomplete, do nothing
197 } elsif ($reqlen == -1) {
198 # error, close conn
199 0 last;
200 }
201 }
202  
203 689 ▶ if (ref $res eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $res eq 'ARRAY') { } 689 0 689
elsif (ref $res eq 'CODE') { } 0 0 0
204 689 $self->_handle_response($res, $conn);
205 } elsif (ref $res eq 'CODE') {
206 0 ▶ $res->(sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
207 0 $self->_handle_response($_[0], $conn);
208 0 });
209 } else {
210 0 die "Bad response $res";
211 }
212  
213 689 return;
214 }
215  
216 689 ▶sub _handle_response {
Subroutine _handle_response: called CC=5 SCAR=17.5
217 689 my($self, $res, $conn) = @_;
218  
219 689 my @lines = (
220 689 "Date: @{[HTTP::Date::time2str()]}\015\012",
221 "Server: $self->{server_software}\015\012",
222 );
223  
224 1510 ▶ Plack::Util::header_iter($res->[1], sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
225 1510 my ($k, $v) = @_;
226 1510 push @lines, "$k: $v\015\012";
227 689 });
228  
229 689 unshift @lines, "HTTP/1.0 $res->[0] @{[ HTTP::Status::status_message($res->[0]) ]}\015\012";
230 689 push @lines, "\015\012";
231  
232 $self->write_all($conn, join('', @lines), $self->{timeout})
233 689 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->write_all($conn, join("", @lines), $self->{"timeout"}) or return 689 0 689
234  
235 689 ▶ if (defined $res->[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $res->[2]) { } 689 0 689
236 689 my $err;
237 my $done;
238 {
239 689 local $@;
240 689 eval {
241 Plack::Util::foreach(
242 $res->[2],
243 744 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
244 $self->write_all($conn, $_[0], $self->{timeout})
245 744 ▶ or die "failed to send all data\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->write_all($conn, $_[0], $self->{"timeout"}) or die "failed to send all data\n" 744 0 744
246 },
247 689 );
248 689 $done = 1;
249 };
250 689 $err = $@;
251 };
252 689 ▶ unless ($done) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($done) 0 689 689
253 0 ▶ if ($err =~ /^failed to send all data\n/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err =~ /^failed to send all data\n/) { } 0 0 0
254 0 return;
255 } else {
256 0 die $err;
257 }
258 }
259 } else {
260 return Plack::Util::inline_object
261 0 ▶ write => sub { $self->write_all($conn, $_[0], $self->{timeout}) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
262 0 ▶ close => sub { };
Subroutine __ANON__: not called CC=1 SCAR=6.9
263 }
264 }
265  
266 # returns 1 if socket is ready, undef on timeout
267 2310 ▶sub do_timeout {
Subroutine do_timeout: called CC=5 SCAR=17.8
Pod undocumented
268 2310 my ($self, $cb, $timeout) = @_;
269 2310 ▶ local $SIG{ALRM} = sub {};
Subroutine __ANON__: not called CC=1 SCAR=0.0
270 2310 my $wait_until = time + $timeout;
271 2310 alarm($timeout);
272 2310 my $ret;
273 2310 while (1) {
274 2310 ▶ if ($ret = $cb->()) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ret = &$cb()) { } 2271 39 2310
elsif (not !defined($ret) && $! == 4) { } 39 0 39
275 2271 last;
276 ▶ } elsif (! (! defined($ret) && $! == EINTR)) {
Condition33%1/3
!defined($ret) && $! == 4
!ll&&!rl&&r
3900
MC/DC0%0/2
!defined($ret) && $! == 4
!defined($ret) $! == 4
Truth table33%1/3
not(A) && B
A= !defined($ret)B= $! == 4
ABresult
0X0
100
111
277 39 undef $ret;
278 39 last;
279 }
280 # got EINTR
281 0 my $left = $wait_until - time;
282 0 ▶ last if $left <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $left <= 0 0 0 0
283 0 alarm($left + $alarm_interval);
284 }
285 2310 alarm(0);
286 2310 $ret;
287 }
288  
289 # returns (positive) number of bytes read, or undef if the socket is to be closed
290 877 ▶sub read_timeout {
Subroutine read_timeout: called CC=1 SCAR=0.0
Pod undocumented
291 877 my ($self, $sock, $buf, $len, $off, $timeout) = @_;
292 877 ▶ $self->do_timeout(sub { $sock->sysread($$buf, $len, $off) }, $timeout);
Subroutine __ANON__: called CC=1 SCAR=0.0
293 }
294  
295 # returns (positive) number of bytes written, or undef if the socket is to be closed
296 1433 ▶sub write_timeout {
Subroutine write_timeout: called CC=1 SCAR=0.0
Pod undocumented
297 1433 my ($self, $sock, $buf, $len, $off, $timeout) = @_;
298 1433 ▶ $self->do_timeout(sub { $sock->syswrite($buf, $len, $off) }, $timeout);
Subroutine __ANON__: called CC=1 SCAR=0.0
299 }
300  
301 # writes all data in buf and returns number of bytes written or undef if failed
302 1433 ▶sub write_all {
Subroutine write_all: called CC=4 SCAR=14.0
Pod undocumented
303 1433 my ($self, $sock, $buf, $timeout) = @_;
304 1433 ▶ return 0 unless defined $buf;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $buf 0 1433 1433
305 1433 _encode($buf);
306 1433 my $off = 0;
307 1433 ▶ while (my $len = length($buf) - $off) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $len = length($buf) - $off) 1433 1433 2866
308 1433 ▶ my $ret = $self->write_timeout($sock, $buf, $len, $off, $timeout)
Branch: 1 branch
BranchTrueFalseTotal
my $ret = $self->write_timeout($sock, $buf, $len, $off, $timeout) or return 1433 0 1433
309 or return;
310 1433 $off += $ret;
311 }
312 1433 return length $buf;
313 }
314  
315 # syswrite() will crash when given wide characters
316 1433 ▶sub _encode {
Subroutine _encode: called CC=2 SCAR=10.5
317 1433 ▶ if ($_[0] =~ /[^\x00-\xff]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /[^\x00-\xff]/) 0 1433 1433
318 0 Carp::carp("Wide character outside byte range in response. Encoding data as UTF-8");
319 0 utf8::encode($_[0]);
320 }
321 }
322  
323 41 1;
324  
325 __END__
« blib/lib/Plack/App/WrapCGI.pm ↑ Summary blib/lib/Plack/Loader/Restarter.pm »