blib/lib/Unblock/HTTP1/_Engine.pm

filter: Statementstmt 86.2% 220 / 255 Branchbran 64.1% 118 / 184 Conditioncond 44.3% 35 / 79 MC/DCmcdc 29.1% 14 / 48 Subroutinesub 77.7% 28 / 36 Podpod 0.0% 0 / 11 totaltotal 67.7% 415 / 613 CC 123 SCAR 28.4
CC
123
Cov
72%
_input_borrowed
51.6
close
30.0
_init_engine
24.0
CRAP 17.1
« blib/lib/Unblock/HTTP1/Server.pm ↑ Summary blib/lib/Unblock/HTTP1/Transaction.pm »
1 package Unblock::HTTP1::_Engine;
2  
3 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 30 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 30 ▶use utf8 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 30 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 119 ▶sub _init_engine {
Subroutine _init_engine: called CC=22 SCAR=31.8
10 119 my ($self, %option) = @_;
11 119 my $transport = delete $option{transport};
12 119 ▶ if (defined $transport) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $transport) 18 101 119
13 18 ▶ croak 'new(): transport must be an object' unless ref $transport;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $transport 0 18 18
14 18 for my $method (qw(unblock_send unblock_finish unblock_abort)) {
15 54 ▶ croak "new(): transport must implement $method()"
Branch: 1 branch
BranchTrueFalseTotal
unless $transport->can($method) 0 54 54
16 unless $transport->can($method);
17 }
18 }
19 119 my %known = map { $_ => 1 } qw(
20 max_head_size
21 max_headers
22 max_chunk_extension_size
23 high_water
24 low_water
25 );
26 119 for my $key (sort keys %option) {
27 11 ▶ croak "new(): unknown option '$key'" unless $known{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $known{$key} 1 10 11
28 }
29 118 ▶ $self->{max_head_size} = exists $option{max_head_size} ? $option{max_head_size} : 65_536;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'max_head_size'} ? : 3 115 118
30 118 ▶ $self->{max_headers} = exists $option{max_headers} ? $option{max_headers} : 100;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'max_headers'} ? : 1 117 118
31 $self->{max_chunk_extension_size} = exists $option{max_chunk_extension_size}
32 118 ▶ ? $option{max_chunk_extension_size} : 16_384;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'max_chunk_extension_size'} ? : 2 116 118
33 118 ▶ $self->{high_water} = exists $option{high_water} ? $option{high_water} : 65_536;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'high_water'} ? : 2 116 118
34 118 ▶ $self->{low_water} = exists $option{low_water} ? $option{low_water} : 32_768;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'low_water'} ? : 2 116 118
35 118 for my $key (qw(max_head_size max_headers max_chunk_extension_size high_water low_water)) {
36 croak "new(): $key must be a non-negative integer"
37 590 ▶ unless defined($self->{$key}) && !ref($self->{$key}) && $self->{$key} =~ /\A[0-9]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$key} and not ref $self->{$key} and $self->{$key} =~ /\A[0-9]+\z/ 0 590 590
Condition33%2/6
defined $self->{$key} and not ref $self->{$key} and $self->{$key} =~ /\A[0-9]+\z/
!ll&&!rl&&r
00590
defined $self->{$key} and not ref $self->{$key}
!ll&&!rl&&r
00590
MC/DC0%0/3
defined $self->{$key} and not ref $self->{$key} and $self->{$key} =~ /\A[0-9]+\z/
defined $self->{$key} not ref $self->{$key} $self->{$key} =~ /\A[0-9]+\z/
Truth table25%1/4
A and not(B) and C
A= defined $self->{$key}B= not ref $self->{$key}C= $self->{$key} =~ /\A[0-9]+\z/
ABCresult
0XX0
10X0
1100
1111
38 }
39 118 ▶ croak 'new(): max_head_size must be positive' unless $self->{max_head_size} > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"max_head_size"} > 0 0 118 118
40 croak 'new(): max_headers must be between 1 and 256'
41 118 ▶ unless $self->{max_headers} >= 1 && $self->{max_headers} <= 256;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"max_headers"} >= 1 and $self->{"max_headers"} <= 256 0 118 118
Condition33%1/3
$self->{"max_headers"} >= 1 and $self->{"max_headers"} <= 256
!ll&&!rl&&r
00118
MC/DC0%0/2
$self->{"max_headers"} >= 1 and $self->{"max_headers"} <= 256
$self->{"max_headers"} >= 1 $self->{"max_headers"} <= 256
Truth table33%1/3
A and B
A= $self->{"max_headers"} >= 1B= $self->{"max_headers"} <= 256
ABresult
0X0
100
111
42 croak 'new(): low_water must not exceed high_water'
43 118 ▶ if $self->{low_water} > $self->{high_water};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"low_water"} > $self->{"high_water"} 0 118 118
44 118 $self->{transport} = $transport;
45 118 ▶ weaken($self->{transport}) if defined $transport;
Branch: 1 branch
BranchTrueFalseTotal
if defined $transport 18 100 118
46 118 ▶ $self->{transport_attached} = defined($transport) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $transport ? : 18 100 118
47 118 $self->{transport_blocked} = 0;
48 118 $self->{transport_syncing} = 0;
49 118 $self->{transport_finished} = 0;
50 118 $self->{transport_aborted} = 0;
51 118 $self->{switch_notice} = undef;
52 118 $self->{input} = '';
53 118 $self->{output} = '';
54 118 $self->{closed} = 0;
55 118 $self->{switched} = 0;
56 118 $self->{remainder} = '';
57 118 $self->{driving} = 0;
58 118 $self->{eof} = 0;
59 118 return $self;
60 }
61  
62 31 ▶sub is_closed { $_[0]{closed} ? 1 : 0 }
Subroutine is_closed: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'closed'} ? : 25 6 31
63 13 ▶sub is_switched { $_[0]{switched} ? 1 : 0 }
Subroutine is_switched: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'switched'} ? : 8 5 13
64 0 ▶sub want_read { !$_[0]{closed} && !$_[0]{switched} && !$_[0]{eof} ? 1 : 0 }
Subroutine want_read: not called CC=4 SCAR=30.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
!($_[0]{'closed'} || $_[0]{'switched'} || $_[0]{'eof'}) ? : 0 0 0
Condition0%0/6
$_[0]{'closed'} || $_[0]{'switched'} || $_[0]{'eof'}
l!l&&r!l&&!r
000
$_[0]{"closed"} or $_[0]{"switched"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$_[0]{'closed'} || $_[0]{'switched'} || $_[0]{'eof'}
$_[0]{"closed"} $_[0]{"switched"} $_[0]{'eof'}
Truth table0%0/4
A or B || C
A= $_[0]{"closed"}B= $_[0]{"switched"}C= $_[0]{'eof'}
ABCresult
1XX1
01X1
0011
0000
65 2 ▶sub want_write { length($_[0]{output}) ? 1 : 0 }
Subroutine want_write: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
length $_[0]{'output'} ? : 0 2 2
66  
67 456 ▶sub input {
Subroutine input: called CC=11 SCAR=25.2
Pod undocumented
68 456 my ($self, $bytes) = @_;
69 456 ▶ croak 'input(): bytes must be a scalar' if ref($bytes);
Branch: 1 branch
BranchTrueFalseTotal
if ref $bytes 0 456 456
70 456 ▶ $bytes = '' unless defined $bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes 0 456 456
71 456 my $copy = "$bytes";
72 456 ▶ croak 'input(): bytes must be a byte string' unless utf8::downgrade($copy, 1);
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::downgrade($copy, 1) 0 456 456
73 456 ▶ return 0 unless length $copy;
Branch: 1 branch
BranchTrueFalseTotal
unless length $copy 0 456 456
74 croak 'input(): cannot be called recursively from an engine callback or host send'
75 456 ▶ if $self->{driving} || $self->{transport_syncing};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"driving"} or $self->{"transport_syncing"} 3 453 456
Condition100%3/3
$self->{"driving"} or $self->{"transport_syncing"}
l!l&&r!l&&!r
21453
MC/DC100%2/2
$self->{"driving"} or $self->{"transport_syncing"}
$self->{"driving"} $self->{"transport_syncing"}
Truth table100%3/3
A or B
A= $self->{"driving"}B= $self->{"transport_syncing"}
ABresult
1X1
011
000
76 453 ▶ croak 'input(): read side is already at EOF' if $self->{eof};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"eof"} 0 453 453
77 453 ▶ if ($self->{switched}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"switched"}) 0 453 453
78 0 $self->{remainder} .= $copy;
79 0 return length $copy;
80 }
81 453 ▶ croak 'input(): connection is closed' if $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} 0 453 453
82 453 $self->{input} .= $copy;
83 {
84 453 local $self->{driving} = 1;
85 453 $self->_drive;
86 }
87 453 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 14 439 453
88 453 return length $copy;
89 }
90  
91 10 ▶sub _input_borrowed {
Subroutine _input_borrowed: called CC=17 SCAR=39.4
92 10 my ($self, $window, $length, $head, $message) = @_;
93 croak '_input_borrowed(): cannot be called recursively from an engine callback or host send'
94 10 ▶ if $self->{driving} || $self->{transport_syncing};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"driving"} or $self->{"transport_syncing"} 0 10 10
Condition33%1/3
$self->{"driving"} or $self->{"transport_syncing"}
l!l&&r!l&&!r
0010
MC/DC0%0/2
$self->{"driving"} or $self->{"transport_syncing"}
$self->{"driving"} $self->{"transport_syncing"}
Truth table33%1/3
A or B
A= $self->{"driving"}B= $self->{"transport_syncing"}
ABresult
1X1
011
000
95 10 ▶ return (4, 0, 0) if $self->{switched};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"switched"} 0 10 10
96 10 ▶ return (3, 0, 0) if $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} 0 10 10
97 10 ▶ if (length $self->{input}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"input"}) 0 10 10
98 0 ▶ croak '_input_borrowed(): buffered fallback requires a native input window'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $window and $window->isa("Unblock::HTTP1::_Native::BorrowedWindow") 0 0 0
Condition0%0/3
ref $window and $window->isa("Unblock::HTTP1::_Native::BorrowedWindow")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $window and $window->isa("Unblock::HTTP1::_Native::BorrowedWindow")
ref $window $window->isa("Unblock::HTTP1::_Native::BorrowedWindow")
Truth table0%0/3
A and B
A= ref $windowB= $window->isa("Unblock::HTTP1::_Native::BorrowedWindow")
ABresult
0X0
100
111
99 unless ref($window)
100 && $window->isa('Unblock::HTTP1::_Native::BorrowedWindow');
101 0 $self->{input} .= $window->slice(0, $length);
102 {
103 0 local $self->{driving} = 1;
104 0 $self->_drive;
105 }
106 0 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 0 0 0
107  
108 0 ▶ my $status = $self->{closed} ? 3 : $self->{switched} ? 4 : 0;
Branch: 2 branches
BranchTrueFalseTotal
$self->{'closed'} ? : 0 0 0
$self->{'switched'} ? : 0 0 0
109 0 return ($status, $length, $self->_borrowed_native_head_ready);
110 }
111  
112 10 my ($status, $consumed, $head_ready);
113 {
114 10 local $self->{borrowed_input} = $window;
115 10 local $self->{borrowed_length} = $length;
116 10 local $self->{borrowed_offset} = 0;
117 10 local $self->{borrowed_head} = $head;
118 10 local $self->{borrowed_message} = $message;
119 10 local $self->{driving} = 1;
120 10 $self->_drive;
121  
122 10 my $remaining = $self->_input_length;
123 10 ▶ if ($self->{closed}) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->{'closed'}) { } 0 10 10
elsif ($self->{'switched'}) { } 3 7 10
elsif ($remaining and $self->_borrowed_should_buffer_tail) { } 0 7 7
elsif ($remaining) { } 0 7 7
124 0 $status = 3;
125 } elsif ($self->{switched}) {
126 3 $status = 4;
127 ▶ } elsif ($remaining && $self->_borrowed_should_buffer_tail) {
Condition33%1/3
$remaining and $self->_borrowed_should_buffer_tail
!ll&&!rl&&r
700
MC/DC0%0/2
$remaining and $self->_borrowed_should_buffer_tail
$remaining $self->_borrowed_should_buffer_tail
Truth table33%1/3
A and B
A= $remainingB= $self->_borrowed_should_buffer_tail
ABresult
0X0
100
111
128 0 $self->{input} .= $self->_input_take($remaining);
129 0 $status = 0;
130 } elsif ($remaining) {
131 0 $status = 1;
132 } else {
133 7 $status = 0;
134 }
135 10 $consumed = $self->{borrowed_offset};
136 10 $head_ready = $self->_borrowed_native_head_ready;
137 }
138 10 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 2 8 10
139 10 return ($status, $consumed, $head_ready);
140 }
141  
142 0 ▶sub _borrowed_input_eof {
Subroutine _borrowed_input_eof: not called CC=3 SCAR=24.8
143 0 my ($self) = @_;
144 0 $self->input_eof;
145 0 ▶ return 4 if $self->{switched};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"switched"} 0 0 0
146 0 ▶ return 3 if $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} 0 0 0
147 0 return 0;
148 }
149  
150 775 ▶sub _input_length {
Subroutine _input_length: called CC=2 SCAR=6.9
151 775 my ($self) = @_;
152 775 ▶ if (exists $self->{borrowed_input}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"borrowed_input"}) 29 746 775
153 29 return $self->{borrowed_length} - $self->{borrowed_offset};
154 }
155 746 return length $self->{input};
156 }
157  
158 478 ▶sub _input_window {
Subroutine _input_window: called CC=2 SCAR=6.9
159 478 my ($self) = @_;
160 return ($self->{borrowed_input}, $self->{borrowed_offset})
161 478 ▶ if exists $self->{borrowed_input};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"borrowed_input"} 3 475 478
162 475 return ($self->{input}, 0);
163 }
164  
165 34 ▶sub _input_take {
Subroutine _input_take: called CC=3 SCAR=11.0
166 34 my ($self, $length) = @_;
167 34 ▶ return '' unless $length;
Branch: 1 branch
BranchTrueFalseTotal
unless $length 0 34 34
168 34 ▶ if (exists $self->{borrowed_input}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"borrowed_input"}) 5 29 34
169 5 my $offset = $self->{borrowed_offset};
170 5 my $bytes = $self->{borrowed_input}->slice($offset, $length);
171 5 $self->{borrowed_offset} += $length;
172 5 return $bytes;
173 }
174 29 return substr($self->{input}, 0, $length, '');
175 }
176  
177 169 ▶sub _input_discard {
Subroutine _input_discard: called CC=3 SCAR=11.0
178 169 my ($self, $length) = @_;
179 169 ▶ return unless $length;
Branch: 1 branch
BranchTrueFalseTotal
unless $length 0 169 169
180 169 ▶ if (exists $self->{borrowed_input}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"borrowed_input"}) 10 159 169
181 10 $self->{borrowed_offset} += $length;
182 10 return;
183 }
184 159 substr($self->{input}, 0, $length, '');
185 159 return;
186 }
187  
188 3 ▶sub _input_clear {
Subroutine _input_clear: called CC=2 SCAR=7.4
189 3 my ($self) = @_;
190 3 ▶ if (exists $self->{borrowed_input}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'borrowed_input'}) { } 0 3 3
191 0 $self->{borrowed_offset} = $self->{borrowed_length};
192 } else {
193 3 $self->{input} = '';
194 }
195 3 return;
196 }
197  
198 2 ▶sub _input_remaining {
Subroutine _input_remaining: called CC=2 SCAR=7.6
199 2 my ($self) = @_;
200 2 ▶ if (exists $self->{borrowed_input}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"borrowed_input"}) 0 2 2
201 return $self->{borrowed_input}->slice(
202 0 $self->{borrowed_offset}, $self->_input_length,
203 );
204 }
205 2 return $self->{input};
206 }
207  
208 0 ▶sub _borrowed_should_buffer_tail { 0 }
Subroutine _borrowed_should_buffer_tail: not called CC=1 SCAR=6.9
209 0 ▶sub _borrowed_native_head_ready { 0 }
Subroutine _borrowed_native_head_ready: not called CC=1 SCAR=6.9
210  
211 7 ▶sub input_eof {
Subroutine input_eof: called CC=5 SCAR=16.3
Pod undocumented
212 7 my ($self) = @_;
213 7 ▶ return $self if $self->{eof};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"eof"} 1 6 7
214 croak 'input_eof(): cannot be called recursively from an engine callback or host send'
215 6 ▶ if $self->{driving} || $self->{transport_syncing};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"driving"} or $self->{"transport_syncing"} 0 6 6
Condition33%1/3
$self->{"driving"} or $self->{"transport_syncing"}
l!l&&r!l&&!r
006
MC/DC0%0/2
$self->{"driving"} or $self->{"transport_syncing"}
$self->{"driving"} $self->{"transport_syncing"}
Truth table33%1/3
A or B
A= $self->{"driving"}B= $self->{"transport_syncing"}
ABresult
1X1
011
000
216 6 $self->{eof} = 1;
217 {
218 6 local $self->{driving} = 1;
219 6 $self->_on_eof;
220 }
221 6 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 1 5 6
222 6 return $self;
223 }
224  
225 111 ▶sub output {
Subroutine output: called CC=9 SCAR=29.0
Pod undocumented
226 111 my ($self, $max) = @_;
227 croak 'output(): manual output is unavailable with an attached transport'
228 111 ▶ if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 1 110 111
229 110 ▶ croak 'output(): cannot be called recursively from an engine callback' if $self->{driving};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"driving"} 0 110 110
230 110 ▶ return '' unless length $self->{output};
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"output"} 7 103 110
231 103 my $take = length $self->{output};
232 103 ▶ if (defined $max) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max) 0 103 103
233 0 ▶ croak 'output(): maximum must be a positive integer'
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $max and $max =~ /\A[0-9]+\z/ and $max > 0 0 0 0
Condition0%0/6
not ref $max and $max =~ /\A[0-9]+\z/ and $max > 0
!ll&&!rl&&r
000
not ref $max and $max =~ /\A[0-9]+\z/
!ll&&!rl&&r
000
MC/DC0%0/3
not ref $max and $max =~ /\A[0-9]+\z/ and $max > 0
not ref $max $max =~ /\A[0-9]+\z/ $max > 0
Truth table0%0/4
not(A) and B and C
A= not ref $maxB= $max =~ /\A[0-9]+\z/C= $max > 0
ABCresult
0XX0
10X0
1100
1111
234 unless !ref($max) && $max =~ /\A[0-9]+\z/ && $max > 0;
235 0 ▶ $take = $max if $max < $take;
Branch: 1 branch
BranchTrueFalseTotal
if $max < $take 0 0 0
236 }
237 103 my $bytes = substr($self->{output}, 0, $take, '');
238 103 $self->_after_output;
239 103 return $bytes;
240 }
241  
242 9 ▶sub take_remainder {
Subroutine take_remainder: called CC=2 SCAR=7.0
Pod undocumented
243 9 my ($self) = @_;
244 croak 'take_remainder(): HTTP/1 connection has not switched protocols'
245 9 ▶ unless $self->{switched};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"switched"} 0 9 9
246 9 my $bytes = $self->{remainder};
247 9 $self->{remainder} = '';
248 9 return $bytes;
249 }
250  
251 0 ▶sub close {
Subroutine close: not called CC=5 SCAR=34.0
Pod undocumented
252 0 my ($self, $error) = @_;
253 0 ▶ return $self if $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} 0 0 0
254 0 $self->{closed} = 1;
255 0 ▶ $self->_fail_all(defined($error) && length($error) ? "$error" : 'HTTP/1 connection closed');
Branch: 1 branch
BranchTrueFalseTotal
defined $error && length $error ? : 0 0 0
Condition0%0/3
defined $error and length $error
!ll&&!rl&&r
000
MC/DC0%0/2
defined $error and length $error
defined $error length $error
Truth table0%0/3
A and B
A= defined $errorB= length $error
ABresult
0X0
100
111
256 0 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 0 0 0
257 0 return $self;
258 }
259  
260 149 ▶sub _queue_output {
Subroutine _queue_output: called CC=6 SCAR=18.0
261 149 my ($self, $bytes) = @_;
262 149 ▶ return unless defined $bytes && length $bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes and length $bytes 5 144 149
Condition66%2/3
defined $bytes and length $bytes
!ll&&!rl&&r
05144
MC/DC50%1/2
defined $bytes and length $bytes
defined $bytes length $bytes
Truth table66%2/3
A and B
A= defined $bytesB= length $bytes
ABresult
0X0
100
111
263 croak '_queue_output(): host send callback must not re-enter the engine'
264 144 ▶ if $self->{transport_syncing};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_syncing"} 0 144 144
265 144 $self->{output} .= $bytes;
266 144 ▶ $self->_transport_sync if $self->{transport_attached} && !$self->{driving};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} and not $self->{"driving"} 11 133 144
Condition100%3/3
$self->{"transport_attached"} and not $self->{"driving"}
!ll&&!rl&&r
1211211
MC/DC100%2/2
$self->{"transport_attached"} and not $self->{"driving"}
$self->{"transport_attached"} not $self->{"driving"}
Truth table100%3/3
A and not(B)
A= $self->{"transport_attached"}B= not $self->{"driving"}
ABresult
0X0
100
111
267 144 return;
268 }
269  
270 # Only a whole-buffer acceptance transfers ownership to the host. A false
271 # return indicates congestion, not rejection. The host later resumes us.
272 56 ▶sub _transport_sync {
Subroutine _transport_sync: called CC=21 SCAR=30.8
273 56 my ($self) = @_;
274 56 ▶ return unless $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"transport_attached"} 0 56 56
275 56 ▶ return if $self->{transport_syncing} || $self->{driving};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_syncing"} or $self->{"driving"} 13 43 56
Condition66%2/3
$self->{"transport_syncing"} or $self->{"driving"}
l!l&&r!l&&!r
01343
MC/DC50%1/2
$self->{"transport_syncing"} or $self->{"driving"}
$self->{"transport_syncing"} $self->{"driving"}
Truth table66%2/3
A or B
A= $self->{"transport_syncing"}B= $self->{"driving"}
ABresult
1X1
011
000
276 43 ▶ return if $self->{transport_aborted} || $self->{transport_finished};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_aborted"} or $self->{"transport_finished"} 2 41 43
Condition66%2/3
$self->{"transport_aborted"} or $self->{"transport_finished"}
l!l&&r!l&&!r
0241
MC/DC50%1/2
$self->{"transport_aborted"} or $self->{"transport_finished"}
$self->{"transport_aborted"} $self->{"transport_finished"}
Truth table66%2/3
A or B
A= $self->{"transport_aborted"}B= $self->{"transport_finished"}
ABresult
1X1
011
000
277 41 my $host = $self->{transport};
278 41 ▶ return $self->transport_error('HTTP/1 transport was destroyed') unless $host;
Branch: 1 branch
BranchTrueFalseTotal
unless $host 1 40 41
279  
280 {
281 40 local $self->{transport_syncing} = 1;
282 40 ▶ while (!$self->{transport_blocked} && length $self->{output}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"transport_blocked"} and length $self->{"output"}) 21 38 59
Condition100%3/3
not $self->{"transport_blocked"} and length $self->{"output"}
!ll&&!rl&&r
112721
MC/DC100%2/2
not $self->{"transport_blocked"} and length $self->{"output"}
not $self->{"transport_blocked"} length $self->{"output"}
Truth table100%3/3
not(A) and B
A= not $self->{"transport_blocked"}B= length $self->{"output"}
ABresult
0X0
100
111
283 # No producer may re-enter during host send. Move this complete
284 # buffer out once; a thrown send aborts rather than retransmits.
285 21 my $bytes = $self->{output};
286 21 $self->{output} = '';
287 21 my ($accepted, $ready);
288 21 $accepted = eval { $ready = $host->unblock_send($bytes); 1 };
289 21 ▶ if (!$accepted) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($accepted) 2 19 21
290 2 ▶ my $error = "$@" || 'unblock_send() failed';
Condition50%1/2
"$@" || 'unblock_send() failed'
l!l
20
MC/DC0%0/1
"$@" || 'unblock_send() failed'
"$@"
Truth table50%1/2
A
A= "$@"
Aresult
11
00
291 2 $self->_transport_abort($error);
292 2 return;
293 }
294 19 ▶ $self->{transport_blocked} = 1 if defined($ready) && !$ready;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ready and not $ready 4 15 19
Condition66%2/3
defined $ready and not $ready
!ll&&!rl&&r
1504
MC/DC50%1/2
defined $ready and not $ready
defined $ready not $ready
Truth table66%2/3
A and not(B)
A= defined $readyB= not $ready
ABresult
0X0
100
111
295 }
296 }
297  
298 38 ▶ if (!length($self->{output}) && $self->{switch_notice}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not length $self->{"output"} and $self->{"switch_notice"}) 3 35 38
Condition100%3/3
not length $self->{"output"} and $self->{"switch_notice"}
!ll&&!rl&&r
7283
MC/DC100%2/2
not length $self->{"output"} and $self->{"switch_notice"}
not length $self->{"output"} $self->{"switch_notice"}
Truth table100%3/3
not(A) and B
A= not length $self->{"output"}B= $self->{"switch_notice"}
ABresult
0X0
100
111
299 3 my $notice = delete $self->{switch_notice};
300 3 $self->_deliver_switch_notice(@$notice);
301 }
302 38 ▶ return if $self->{transport_aborted};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_aborted"} 1 37 38
303 37 ▶ if ($self->{closed} && !length($self->{output}) && !$self->{switched}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"closed"} and not length $self->{"output"} and not $self->{"switched"}) 3 34 37
Condition83%5/6
$self->{"closed"} and not length $self->{"output"} and not $self->{"switched"}
!ll&&!rl&&r
3403
$self->{"closed"} and not length $self->{"output"}
!ll&&!rl&&r
3223
MC/DC66%2/3
$self->{"closed"} and not length $self->{"output"} and not $self->{"switched"}
$self->{"closed"} not length $self->{"output"} not $self->{"switched"}
Truth table75%3/4
A and not(B) and not(C)
A= $self->{"closed"}B= not length $self->{"output"}C= not $self->{"switched"}
ABCresult
0XX0
10X0
1100
1111
304 3 $self->{transport_finished} = 1;
305 3 my $ok = eval { $host->unblock_finish(); 1 };
306 3 ▶ $self->_transport_abort("$@" || 'unblock_finish() failed') unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 3 3
Condition0%0/2
"$@" || 'unblock_finish() failed'
l!l
00
MC/DC0%0/1
"$@" || 'unblock_finish() failed'
"$@"
Truth table0%0/2
A
A= "$@"
Aresult
11
00
307 }
308 37 return;
309 }
310  
311 4 ▶sub _transport_abort {
Subroutine _transport_abort: called CC=3 SCAR=11.0
312 4 my ($self, $reason) = @_;
313 4 ▶ return if $self->{transport_aborted};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_aborted"} 0 4 4
314 4 $self->{transport_aborted} = 1;
315 4 $self->{output} = '';
316 4 $self->{closed} = 1;
317 4 $self->{switch_notice} = undef;
318 4 $self->_fail_all($reason);
319 4 ▶ if (my $host = $self->{transport}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $host = $self->{"transport"}) 3 1 4
320 3 eval { $host->unblock_abort($reason) };
321 }
322 4 return;
323 }
324  
325 1 ▶sub transport_error {
Subroutine transport_error: called CC=3 SCAR=12.0
Pod undocumented
326 1 my ($self, $reason) = @_;
327 1 ▶ $reason = 'transport error' unless defined($reason) && length($reason);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $reason and length $reason 0 1 1
Condition33%1/3
defined $reason and length $reason
!ll&&!rl&&r
001
MC/DC0%0/2
defined $reason and length $reason
defined $reason length $reason
Truth table33%1/3
A and B
A= defined $reasonB= length $reason
ABresult
0X0
100
111
328 1 $self->_transport_abort("$reason");
329 1 return $self;
330 }
331  
332 3 ▶sub resume_output {
Subroutine resume_output: called CC=9 SCAR=25.4
Pod undocumented
333 3 my ($self) = @_;
334 3 ▶ croak 'resume_output(): no attached transport' unless $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"transport_attached"} 0 3 3
335 croak 'resume_output(): cannot be called recursively from host send'
336 3 ▶ if $self->{transport_syncing};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_syncing"} 0 3 3
337 3 ▶ return $self if $self->{transport_finished} || $self->{transport_aborted};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_finished"} or $self->{"transport_aborted"} 0 3 3
Condition33%1/3
$self->{"transport_finished"} or $self->{"transport_aborted"}
l!l&&r!l&&!r
003
MC/DC0%0/2
$self->{"transport_finished"} or $self->{"transport_aborted"}
$self->{"transport_finished"} $self->{"transport_aborted"}
Truth table33%1/3
A or B
A= $self->{"transport_finished"}B= $self->{"transport_aborted"}
ABresult
1X1
011
000
338 3 $self->{transport_blocked} = 0;
339 3 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 3 0 3
340 3 ▶ if (!$self->{transport_blocked} && length($self->{output}) <= $self->{low_water}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"transport_blocked"} and length $self->{"output"} <= $self->{"low_water"}) 3 0 3
Condition33%1/3
not $self->{"transport_blocked"} and length $self->{"output"} <= $self->{"low_water"}
!ll&&!rl&&r
003
MC/DC0%0/2
not $self->{"transport_blocked"} and length $self->{"output"} <= $self->{"low_water"}
not $self->{"transport_blocked"} length $self->{"output"} <= $self->{"low_water"}
Truth table33%1/3
not(A) and B
A= not $self->{"transport_blocked"}B= length $self->{"output"} <= $self->{"low_water"}
ABresult
0X0
100
111
341 3 $self->_maybe_drain;
342 3 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 3 0 3
343 }
344 3 return $self;
345 }
346  
347 0 ▶sub _deliver_switch_notice { return }
Subroutine _deliver_switch_notice: not called CC=1 SCAR=6.9
348  
349 12 ▶sub _mark_switched {
Subroutine _mark_switched: called CC=3 SCAR=11.0
350 12 my ($self) = @_;
351 12 ▶ return if $self->{switched};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"switched"} 0 12 12
352 12 $self->{switched} = 1;
353 12 ▶ if (!exists $self->{borrowed_input}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"borrowed_input"}) 9 3 12
354 9 $self->{remainder} .= $self->{input};
355 9 $self->{input} = '';
356 }
357 12 return;
358 }
359  
360 103 ▶sub _after_output {
Subroutine _after_output: called CC=2 SCAR=7.1
361 103 my ($self) = @_;
362 103 ▶ $self->_maybe_drain if length($self->{output}) <= $self->{low_water};
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"output"} <= $self->{"low_water"} 103 0 103
363 103 return;
364 }
365  
366 15 ▶sub _stream_ok {
Subroutine _stream_ok: called CC=3 SCAR=11.0
367 15 my ($self) = @_;
368 15 ▶ return 0 if $self->{transport_blocked};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_blocked"} 1 14 15
369 14 ▶ return length($self->{output}) < $self->{high_water} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
length $self->{'output'} < $self->{'high_water'} ? : 12 2 14
370 }
371  
372 0 ▶sub _maybe_drain { return }
Subroutine _maybe_drain: not called CC=1 SCAR=6.9
373 0 ▶sub _fail_all { return }
Subroutine _fail_all: not called CC=1 SCAR=6.9
374  
375 30 1;
« blib/lib/Unblock/HTTP1/Server.pm ↑ Summary blib/lib/Unblock/HTTP1/Transaction.pm »