blib/lib/Unblock/HTTP3/Transaction.pm

filter: Statementstmt 95.5% 541 / 566 Branchbran 63.5% 254 / 400 Conditioncond 56.4% 70 / 124 MC/DCmcdc 22.2% 16 / 72 Subroutinesub 100% 86 / 86 Podpod 0.0% 0 / 35 totaltotal 75.3% 967 / 1283 CC 250 SCAR 20.5
CC
250
Cov
79%
response_body
22.1
_new
18.1
on_data
15.9
CRAP 7.8
« blib/lib/Unblock/HTTP3/Capsule/Parser.pm ↑ Summary blib/lib/Unblock/HTTP3/_Native.pm »
1 package Unblock::HTTP3::Transaction;
2  
3 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 25 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 25 ▶use Scalar::Util qw(blessed weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 25 ▶use Uniform::HTTP::Request 0.06 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 25 ▶use Uniform::HTTP::Response 0.06 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 25 ▶use Unblock::HTTP3 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 25 ▶use Unblock::HTTP3::_Native ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 25 our $VERSION = '0.14';
16  
17 25 my %TERMINAL = map { $_ => 1 } qw(complete cancelled error);
18 25 my $BUFFERED_BODY_RETAIN_BYTES = 16_384;
19  
20 6 ▶sub _priority_from_args {
Subroutine _priority_from_args: called CC=14 SCAR=27.1
21 6 my ($current, @args) = @_;
22 6 ▶ croak 'priority() requires named arguments' if @args % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 6 6
23  
24 my %priority = (
25 urgency => 3,
26 incremental => 0,
27 6 ▶ %{ $current || {} },
Condition50%1/2
$current || {}
l!l
60
MC/DC0%0/1
$current || {}
$current
Truth table50%1/2
A
A= $current
Aresult
11
00
28 );
29  
30 6 ▶ while (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 8 3 11
31 8 my $name = shift @args;
32 8 my $value = shift @args;
33  
34 8 ▶ croak "unknown priority option: $name"
Branch: 1 branch
BranchTrueFalseTotal
if $name ne "urgency" and $name ne "incremental" 1 7 8
Condition100%3/3
$name ne "urgency" and $name ne "incremental"
!ll&&!rl&&r
431
MC/DC100%2/2
$name ne "urgency" and $name ne "incremental"
$name ne "urgency" $name ne "incremental"
Truth table100%3/3
A and B
A= $name ne "urgency"B= $name ne "incremental"
ABresult
0X0
100
111
35 if $name ne 'urgency' && $name ne 'incremental';
36  
37 7 ▶ if ($name eq 'urgency') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "urgency") 4 3 7
38 4 ▶ croak 'priority urgency must be an integer from 0 through 7'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or ref $value or not "$value" =~ /\A[0-7]\z/ 1 3 4
Condition50%3/6
not defined $value or ref $value or not "$value" =~ /\A[0-7]\z/
l!l&&r!l&&!r
013
not defined $value or ref $value
l!l&&r!l&&!r
004
MC/DC33%1/3
not defined $value or ref $value or not "$value" =~ /\A[0-7]\z/
not defined $value ref $value not "$value" =~ /\A[0-7]\z/
Truth table50%2/4
not(A) or B or not(C)
A= not defined $valueB= ref $valueC= not "$value" =~ /\A[0-7]\z/
ABCresult
1XX1
01X1
0011
0000
39 if !defined($value)
40 || ref($value)
41 || "$value" !~ /\A[0-7]\z/;
42 3 $priority{urgency} = 0 + $value;
43 3 next;
44 }
45  
46 3 ▶ croak 'priority incremental must be 0 or 1'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or ref $value or not "$value" =~ /\A[01]\z/ 1 2 3
Condition50%3/6
not defined $value or ref $value or not "$value" =~ /\A[01]\z/
l!l&&r!l&&!r
012
not defined $value or ref $value
l!l&&r!l&&!r
003
MC/DC33%1/3
not defined $value or ref $value or not "$value" =~ /\A[01]\z/
not defined $value ref $value not "$value" =~ /\A[01]\z/
Truth table50%2/4
not(A) or B or not(C)
A= not defined $valueB= ref $valueC= not "$value" =~ /\A[01]\z/
ABCresult
1XX1
01X1
0011
0000
47 if !defined($value)
48 || ref($value)
49 || "$value" !~ /\A[01]\z/;
50 2 ▶ $priority{incremental} = $value ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 1 1 2
51 }
52  
53 3 return \%priority;
54 }
55  
56 3 ▶sub _priority_field {
Subroutine _priority_field: called CC=2 SCAR=6.9
57 3 my ($priority) = @_;
58 3 my $value = 'u=' . $priority->{urgency};
59 3 ▶ $value .= ', i' if $priority->{incremental};
Branch: 1 branch
BranchTrueFalseTotal
if $priority->{"incremental"} 1 2 3
60 3 return $value;
61 }
62  
63 106 ▶sub _parse_priority_field {
Subroutine _parse_priority_field: called CC=4 SCAR=13.9
64 106 my ($value) = @_;
65  
66 return {
67 106 ▶ urgency => 3,
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 102 4 106
68 incremental => 0,
69 } unless defined $value;
70  
71 4 my $parsed = eval {
72 4 Unblock::HTTP3::_Native->parse_priority($value);
73 };
74  
75 return {
76 4 ▶ urgency => 3,
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parsed 1 3 4
77 incremental => 0,
78 } unless defined $parsed;
79  
80 return {
81 3 ▶ urgency => 0 + $parsed->[0],
Branch: 1 branch
BranchTrueFalseTotal
$parsed->[1] ? : 3 0 3
82 incremental => $parsed->[1] ? 1 : 0,
83 };
84 }
85  
86 103 ▶sub _request_contract {
Subroutine _request_contract: called CC=4 SCAR=14.3
87 103 my ($request) = @_;
88 103 ▶ return unless blessed($request);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($request) 0 103 103
89  
90 103 for my $method (qw(
91 method target scheme authority protocol version
92 header_count header_name header_value
93 trailer_count trailer_name trailer_value
94 has_buffered_body body
95 )) {
96 1442 ▶ return unless $request->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $request->can($method) 0 1442 1442
97 }
98  
99 103 return 1;
100 }
101  
102 88 ▶sub _response_contract {
Subroutine _response_contract: called CC=4 SCAR=14.3
103 88 my ($response) = @_;
104 88 ▶ return unless blessed($response);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($response) 0 88 88
105  
106 88 for my $method (qw(
107 status version
108 header_count header_name header_value
109 trailer_count trailer_name trailer_value
110 has_buffered_body body
111 )) {
112 880 ▶ return unless $response->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $response->can($method) 0 880 880
113 }
114  
115 88 return 1;
116 }
117  
118 103 ▶sub _new {
Subroutine _new: called CC=14 SCAR=29.0
119 103 my ($class, %args) = @_;
120  
121 103 my $connection = delete $args{connection};
122 103 my $stream_id = delete $args{stream_id};
123 103 my $request = delete $args{request};
124 103 my $response = delete $args{response};
125 103 ▶ my $callbacks = delete($args{callbacks}) || {};
Condition100%2/2
delete $args{'callbacks'} || {}
l!l
7528
MC/DC100%1/1
delete $args{'callbacks'} || {}
delete $args{'callbacks'}
Truth table100%2/2
A
A= delete $args{'callbacks'}
Aresult
11
00
126 103 ▶ my $request_streaming = delete $args{request_streaming} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
delete $args{'request_streaming'} ? : 16 87 103
127 103 ▶ my $early_data = delete $args{early_data} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
delete $args{'early_data'} ? : 3 100 103
128  
129 103 ▶ croak 'Transaction requires a Unblock::HTTP3::Connection'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($connection) and $connection->isa("Unblock::HTTP3::Connection") 0 103 103
Condition33%1/3
builtin::blessed($connection) and $connection->isa("Unblock::HTTP3::Connection")
!ll&&!rl&&r
00103
MC/DC0%0/2
builtin::blessed($connection) and $connection->isa("Unblock::HTTP3::Connection")
builtin::blessed($connection) $connection->isa("Unblock::HTTP3::Connection")
Truth table33%1/3
A and B
A= builtin::blessed($connection)B= $connection->isa("Unblock::HTTP3::Connection")
ABresult
0X0
100
111
130 unless blessed($connection)
131 && $connection->isa('Unblock::HTTP3::Connection');
132 103 ▶ croak 'Transaction requires a non-negative stream ID'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stream_id and not ref $stream_id and $stream_id =~ /\A[0-9]+\z/ 0 103 103
Condition33%2/6
defined $stream_id and not ref $stream_id and $stream_id =~ /\A[0-9]+\z/
!ll&&!rl&&r
00103
defined $stream_id and not ref $stream_id
!ll&&!rl&&r
00103
MC/DC0%0/3
defined $stream_id and not ref $stream_id and $stream_id =~ /\A[0-9]+\z/
defined $stream_id not ref $stream_id $stream_id =~ /\A[0-9]+\z/
Truth table25%1/4
A and not(B) and C
A= defined $stream_idB= not ref $stream_idC= $stream_id =~ /\A[0-9]+\z/
ABCresult
0XX0
10X0
1100
1111
133 unless defined($stream_id)
134 && !ref($stream_id)
135 && $stream_id =~ /\A[0-9]+\z/;
136 103 ▶ croak 'Transaction requires the Uniform HTTP request contract'
Branch: 1 branch
BranchTrueFalseTotal
unless _request_contract($request) 0 103 103
137 unless _request_contract($request);
138 103 ▶ croak 'Transaction response must implement the Uniform HTTP response contract'
Branch: 1 branch
BranchTrueFalseTotal
if defined $response and not _response_contract($response) 0 103 103
Condition66%2/3
defined $response and not _response_contract($response)
!ll&&!rl&&r
47560
MC/DC0%0/2
defined $response and not _response_contract($response)
defined $response not _response_contract($response)
Truth table66%2/3
A and not(B)
A= defined $responseB= not _response_contract($response)
ABresult
0X0
100
111
139 if defined($response)
140 && !_response_contract($response);
141 103 ▶ croak 'Transaction callbacks must be a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $callbacks eq "HASH" 0 103 103
142 unless ref($callbacks) eq 'HASH';
143 103 ▶ croak 'unknown Transaction option: ' . join(', ', sort keys %args)
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 103 103
144 if %args;
145  
146 103 my $self = bless {
147 connection => $connection,
148 stream_id => 0 + $stream_id,
149 request => $request,
150 response => $response,
151 callbacks => { %$callbacks },
152 informational => [],
153 request_body => undef,
154 response_body => undef,
155 request_receive_mode => 'buffered',
156 response_receive_mode => 'buffered',
157 request_receive_options => {},
158 response_receive_options => {},
159 request_end_callback_called => 0,
160 request_streaming => $request_streaming,
161 early_data => $early_data,
162 response_streaming => 0,
163 request_buffered_body => '',
164 request_buffered_chunks => [],
165 request_buffered_bytes => 0,
166 request_buffered_seen => 0,
167 response_buffered_body => '',
168 response_buffered_chunks => [],
169 response_buffered_bytes => 0,
170 response_buffered_seen => 0,
171 response_output_started => 0,
172 capsule_stream => undef,
173 datagrams_enabled => 0,
174 datagram_queue => [],
175 datagram_callback => undef,
176 priority => _parse_priority_field(
177 $request->header('priority'),
178 ),
179 local_reset_code => undef,
180 remote_reset_code => undef,
181 local_stop_sending_code => undef,
182 remote_stop_sending_code => undef,
183 state => 'active',
184 error => undef,
185 }, $class;
186  
187 103 weaken($self->{connection});
188  
189 103 return $self;
190 }
191  
192 12 ▶sub early_data {
Subroutine early_data: called CC=3 SCAR=11.1
Pod undocumented
193 12 my ($self, @args) = @_;
194 12 ▶ croak 'early_data() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 12 12
195 12 ▶ return $self->{early_data} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'early_data'} ? : 4 8 12
196 }
197  
198 961 ▶sub stream_id {
Subroutine stream_id: called CC=2 SCAR=7.1
Pod undocumented
199 961 my ($self, @args) = @_;
200 961 ▶ croak 'stream_id() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 961 961
201 961 return $self->{stream_id};
202 }
203  
204 383 ▶sub request {
Subroutine request: called CC=2 SCAR=7.1
Pod undocumented
205 383 my ($self, @args) = @_;
206 383 ▶ croak 'request() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 383 383
207 383 return $self->{request};
208 }
209  
210 4 ▶sub protocol {
Subroutine protocol: called CC=2 SCAR=7.1
Pod undocumented
211 4 my ($self, @args) = @_;
212 4 ▶ croak 'protocol() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 4 4
213 4 return $self->{request}->protocol;
214 }
215  
216 28 ▶sub is_extended_connect {
Subroutine is_extended_connect: called CC=3 SCAR=11.1
Pod undocumented
217 28 my ($self, @args) = @_;
218 28 ▶ croak 'is_extended_connect() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 28 28
219 28 ▶ return defined($self->{request}->protocol) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'request'}->protocol ? : 27 1 28
220 }
221  
222 291 ▶sub response {
Subroutine response: called CC=2 SCAR=7.1
Pod undocumented
223 291 my ($self, @args) = @_;
224 291 ▶ croak 'response() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 291 291
225 291 return $self->{response};
226 }
227  
228 2 ▶sub local_reset_code {
Subroutine local_reset_code: called CC=2 SCAR=7.1
Pod undocumented
229 2 my ($self, @args) = @_;
230 2 ▶ croak 'local_reset_code() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 2 2
231 2 return $self->{local_reset_code};
232 }
233  
234 8 ▶sub remote_reset_code {
Subroutine remote_reset_code: called CC=2 SCAR=7.1
Pod undocumented
235 8 my ($self, @args) = @_;
236 8 ▶ croak 'remote_reset_code() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 8 8
237 8 return $self->{remote_reset_code};
238 }
239  
240 1 ▶sub local_stop_sending_code {
Subroutine local_stop_sending_code: called CC=2 SCAR=7.1
Pod undocumented
241 1 my ($self, @args) = @_;
242 1 ▶ croak 'local_stop_sending_code() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 1 1
243 1 return $self->{local_stop_sending_code};
244 }
245  
246 7 ▶sub remote_stop_sending_code {
Subroutine remote_stop_sending_code: called CC=2 SCAR=7.1
Pod undocumented
247 7 my ($self, @args) = @_;
248 7 ▶ croak 'remote_stop_sending_code() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 7 7
249 7 return $self->{remote_stop_sending_code};
250 }
251  
252 2 ▶sub is_aborted {
Subroutine is_aborted: called CC=6 SCAR=19.6
Pod undocumented
253 2 my ($self, @args) = @_;
254 2 ▶ croak 'is_aborted() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 2 2
255  
256 return defined($self->{local_reset_code})
257 || defined($self->{remote_reset_code})
258 || defined($self->{local_stop_sending_code})
259 || defined($self->{remote_stop_sending_code})
260 2 ▶ ? 1
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'local_reset_code'} || defined $self->{'remote_reset_code'} || defined $self->{'local_stop_sending_code'} || defined $self->{'remote_stop_sending_code'} ? : 2 0 2
Condition66%6/9
defined $self->{"local_reset_code"} or defined $self->{"remote_reset_code"} or defined $self->{"local_stop_sending_code"} or defined $self->{"remote_stop_sending_code"}
l!l&&r!l&&!r
110
defined $self->{"local_reset_code"} or defined $self->{"remote_reset_code"} or defined $self->{"local_stop_sending_code"}
l!l&&r!l&&!r
101
defined $self->{"local_reset_code"} or defined $self->{"remote_reset_code"}
l!l&&r!l&&!r
101
MC/DC0%0/4
defined $self->{"local_reset_code"} or defined $self->{"remote_reset_code"} or defined $self->{"local_stop_sending_code"} or defined $self->{"remote_stop_sending_code"}
defined $self->{"local_reset_code"} defined $self->{"remote_reset_code"} defined $self->{"local_stop_sending_code"} defined $self->{"remote_stop_sending_code"}
Truth table40%2/5
A or B or C or D
A= defined $self->{"local_reset_code"}B= defined $self->{"remote_reset_code"}C= defined $self->{"local_stop_sending_code"}D= defined $self->{"remote_stop_sending_code"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
261 : 0;
262 }
263  
264 9 ▶sub _mark_local_reset {
Subroutine _mark_local_reset: called CC=1 SCAR=0.0
265 9 my ($self, $code) = @_;
266 9 $self->{local_reset_code} = 0 + $code;
267 9 return $self;
268 }
269  
270 9 ▶sub _mark_remote_reset {
Subroutine _mark_remote_reset: called CC=1 SCAR=0.0
271 9 my ($self, $code) = @_;
272 9 $self->{remote_reset_code} = 0 + $code;
273 9 return $self;
274 }
275  
276 7 ▶sub _mark_local_stop_sending {
Subroutine _mark_local_stop_sending: called CC=1 SCAR=0.0
277 7 my ($self, $code) = @_;
278 7 $self->{local_stop_sending_code} = 0 + $code;
279 7 return $self;
280 }
281  
282 5 ▶sub _mark_remote_stop_sending {
Subroutine _mark_remote_stop_sending: called CC=1 SCAR=0.0
283 5 my ($self, $code) = @_;
284 5 $self->{remote_stop_sending_code} = 0 + $code;
285 5 return $self;
286 }
287  
288 11 ▶sub priority {
Subroutine priority: called CC=6 SCAR=18.6
Pod undocumented
289 11 my ($self, @args) = @_;
290  
291 11 my $connection = $self->{connection};
292  
293 11 ▶ if (!@args) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@args) 9 2 11
294 0 ▶ return { %{ $self->{priority} } }
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal or not defined $connection 0 9 9
Condition33%1/3
$self->is_terminal or not defined $connection
l!l&&r!l&&!r
009
MC/DC0%0/2
$self->is_terminal or not defined $connection
$self->is_terminal not defined $connection
Truth table33%1/3
A or not(B)
A= $self->is_terminalB= not defined $connection
ABresult
1X1
011
000
295 if $self->is_terminal || !defined($connection);
296  
297 9 my $priority = $connection->_transaction_priority($self);
298 9 $self->{priority} = { %$priority };
299  
300 9 return { %$priority };
301 }
302  
303 2 ▶ croak 'priority() cannot change a terminal Transaction'
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 2 2
304 if $self->is_terminal;
305  
306 2 ▶ $connection
Branch: 1 branch
BranchTrueFalseTotal
$connection or croak("priority(): Transaction no longer has a connection") 2 0 2
307 or croak 'priority(): Transaction no longer has a connection';
308  
309 2 my $current = $connection->_transaction_priority($self);
310 2 my $priority = _priority_from_args(
311 $current,
312 @args,
313 );
314  
315 2 $connection->_set_transaction_priority(
316 $self,
317 $priority,
318 );
319  
320 2 $self->{priority} = { %$priority };
321 2 return $self;
322 }
323  
324 4 ▶sub capsules {
Subroutine capsules: called CC=6 SCAR=20.8
Pod undocumented
325 4 my ($self, @args) = @_;
326  
327 4 ▶ if (my $stream = $self->{capsule_stream}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $stream = $self->{"capsule_stream"}) 0 4 4
328 0 ▶ croak 'capsules() options can only be supplied when the stream is created'
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 0 0
329 if @args;
330 0 return $stream;
331 }
332  
333 4 ▶ croak 'capsules() options must be key/value pairs'
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 4 4
334 if @args % 2;
335 4 ▶ croak 'capsules() cannot be used on a terminal Transaction'
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 4 4
336 if $self->is_terminal;
337 4 ▶ croak 'capsules() requires Extended CONNECT'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_extended_connect 0 4 4
338 unless $self->is_extended_connect;
339  
340 4 require Unblock::HTTP3::Capsule::Stream;
341  
342 4 my $stream = Unblock::HTTP3::Capsule::Stream->_new(
343 $self,
344 @args,
345 );
346  
347 3 $self->{capsule_stream} = $stream;
348 3 return $stream;
349 }
350  
351 5 ▶sub _enable_datagrams {
Subroutine _enable_datagrams: called CC=1 SCAR=0.0
352 5 my ($self) = @_;
353 5 $self->{datagrams_enabled} = 1;
354 5 return $self;
355 }
356  
357 28 ▶sub datagrams_enabled {
Subroutine datagrams_enabled: called CC=3 SCAR=11.1
Pod undocumented
358 28 my ($self, @args) = @_;
359 28 ▶ croak 'datagrams_enabled() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 28 28
360 28 ▶ return $self->{datagrams_enabled} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'datagrams_enabled'} ? : 26 2 28
361 }
362  
363 8 ▶sub send_datagram {
Subroutine send_datagram: called CC=4 SCAR=14.6
Pod undocumented
364 8 my ($self, $bytes) = @_;
365  
366 8 ▶ croak 'send_datagram(): Transaction is already terminal'
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 8 8
367 if $self->is_terminal;
368 croak 'send_datagram(): HTTP Datagrams are not enabled for this Transaction'
369 8 ▶ unless $self->{datagrams_enabled};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"datagrams_enabled"} 0 8 8
370  
371 my $connection = $self->{connection}
372 8 ▶ or croak 'send_datagram(): Transaction no longer has a connection';
Branch: 1 branch
BranchTrueFalseTotal
my $connection = $self->{"connection"} or croak("send_datagram(): Transaction no longer has a connection") 8 0 8
373  
374 8 return $connection->_send_transaction_datagram($self, $bytes);
375 }
376  
377 2 ▶sub max_datagram_payload_size {
Subroutine max_datagram_payload_size: called CC=5 SCAR=17.0
Pod undocumented
378 2 my ($self, @args) = @_;
379 2 ▶ croak 'max_datagram_payload_size() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 2 2
380 2 ▶ return 0 unless $self->{datagrams_enabled};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"datagrams_enabled"} 0 2 2
381 2 ▶ return 0 if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 2 2
382  
383 2 my $connection = $self->{connection};
384 2 ▶ return 0 unless defined $connection;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $connection 0 2 2
385  
386 2 return $connection->_transaction_datagram_payload_size($self);
387 }
388  
389 15 ▶sub next_datagram {
Subroutine next_datagram: called CC=4 SCAR=14.0
Pod undocumented
390 15 my ($self, @args) = @_;
391 15 ▶ croak 'next_datagram() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 15 15
392  
393 15 my $bytes = shift @{ $self->{datagram_queue} };
394 15 ▶ return unless defined $bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes 10 5 15
395  
396 5 my $connection = $self->{connection};
397 5 ▶ $connection->_datagram_dequeued(length($bytes))
Branch: 1 branch
BranchTrueFalseTotal
if defined $connection 5 0 5
398 if defined $connection;
399  
400 5 return $bytes;
401 }
402  
403 1 ▶sub on_datagram {
Subroutine on_datagram: called CC=5 SCAR=18.4
Pod undocumented
404 1 my ($self, $callback) = @_;
405  
406 1 ▶ croak 'on_datagram() callback must be a code reference or undef'
Branch: 1 branch
BranchTrueFalseTotal
if defined $callback and ref $callback ne "CODE" 0 1 1
Condition33%1/3
defined $callback and ref $callback ne "CODE"
!ll&&!rl&&r
010
MC/DC0%0/2
defined $callback and ref $callback ne "CODE"
defined $callback ref $callback ne "CODE"
Truth table33%1/3
A and B
A= defined $callbackB= ref $callback ne "CODE"
ABresult
0X0
100
111
407 if defined($callback) && ref($callback) ne 'CODE';
408  
409 1 $self->{datagram_callback} = $callback;
410  
411 1 ▶ if (defined $callback) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $callback) 1 0 1
412 1 ▶ while (defined(my $bytes = $self->next_datagram)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $bytes = $self->next_datagram)) 0 1 1
413 0 $callback->($self, $bytes);
414 }
415 }
416  
417 1 return $self;
418 }
419  
420 5 ▶sub _enqueue_datagram {
Subroutine _enqueue_datagram: called CC=1 SCAR=0.0
421 5 my ($self, $bytes) = @_;
422 5 push @{ $self->{datagram_queue} }, $bytes;
423 5 return;
424 }
425  
426 7 ▶sub _receive_datagram {
Subroutine _receive_datagram: called CC=3 SCAR=11.0
427 7 my ($self, $bytes) = @_;
428  
429 7 my $callback = $self->{datagram_callback};
430 7 ▶ if (defined $callback) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $callback) 1 6 7
431 1 $callback->($self, $bytes);
432 1 return;
433 }
434  
435 6 my $connection = $self->{connection};
436 6 ▶ return unless defined $connection;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $connection 0 6 6
437  
438 6 $connection->_buffer_transaction_datagram($self, $bytes);
439 6 return;
440 }
441  
442 82 ▶sub _discard_datagrams {
Subroutine _discard_datagrams: called CC=3 SCAR=11.0
443 82 my ($self) = @_;
444  
445 82 my $connection = $self->{connection};
446  
447 82 ▶ if (defined $connection) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $connection) 80 2 82
448 80 for my $bytes (@{ $self->{datagram_queue} }) {
449 0 $connection->_datagram_dequeued(length($bytes));
450 }
451 }
452  
453 82 $self->{datagram_queue} = [];
454 82 $self->{datagram_callback} = undef;
455 82 return;
456 }
457  
458 34 ▶sub state {
Subroutine state: called CC=2 SCAR=7.1
Pod undocumented
459 34 my ($self, @args) = @_;
460 34 ▶ croak 'state() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 34 34
461 34 return $self->{state};
462 }
463  
464 4 ▶sub error {
Subroutine error: called CC=2 SCAR=7.1
Pod undocumented
465 4 my ($self, @args) = @_;
466 4 ▶ croak 'error() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 4 4
467 4 return $self->{error};
468 }
469  
470 113 ▶sub is_complete {
Subroutine is_complete: called CC=3 SCAR=11.1
Pod undocumented
471 113 my ($self, @args) = @_;
472 113 ▶ croak 'is_complete() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 113 113
473 113 ▶ return $self->{state} eq 'complete' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'state'} eq 'complete' ? : 50 63 113
474 }
475  
476 3 ▶sub is_cancelled {
Subroutine is_cancelled: called CC=3 SCAR=11.7
Pod undocumented
477 3 my ($self, @args) = @_;
478 3 ▶ croak 'is_cancelled() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 3 3
479 3 ▶ return $self->{state} eq 'cancelled' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'state'} eq 'cancelled' ? : 3 0 3
480 }
481  
482 1 ▶sub is_error {
Subroutine is_error: called CC=3 SCAR=11.7
Pod undocumented
483 1 my ($self, @args) = @_;
484 1 ▶ croak 'is_error() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 1 1
485 1 ▶ return $self->{state} eq 'error' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'state'} eq 'error' ? : 1 0 1
486 }
487  
488 1803 ▶sub is_terminal {
Subroutine is_terminal: called CC=3 SCAR=11.1
Pod undocumented
489 1803 my ($self, @args) = @_;
490 1803 ▶ croak 'is_terminal() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 1803 1803
491 1803 ▶ return $TERMINAL{ $self->{state} } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$TERMINAL{$self->{'state'}} ? : 567 1236 1803
492 }
493  
494 4 ▶sub _set_callback {
Subroutine _set_callback: called CC=4 SCAR=15.9
495 4 my ($self, $name, $callback) = @_;
496  
497 4 ▶ croak "_set_callback(): callback must be a code reference or undef"
Branch: 1 branch
BranchTrueFalseTotal
if defined $callback and ref $callback ne "CODE" 0 4 4
Condition33%1/3
defined $callback and ref $callback ne "CODE"
!ll&&!rl&&r
040
MC/DC0%0/2
defined $callback and ref $callback ne "CODE"
defined $callback ref $callback ne "CODE"
Truth table33%1/3
A and B
A= defined $callbackB= ref $callback ne "CODE"
ABresult
0X0
100
111
498 if defined($callback) && ref($callback) ne 'CODE';
499  
500 4 ▶ if (defined $callback) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $callback) { } 4 0 4
501 4 $self->{callbacks}{$name} = $callback;
502 } else {
503 0 delete $self->{callbacks}{$name};
504 }
505  
506 4 return $self;
507 }
508  
509 9 ▶sub on_data {
Subroutine on_data: called CC=13 SCAR=27.7
Pod undocumented
510 9 my ($self, $cb) = @_;
511 9 ▶ croak 'on_data(): callback must be a coderef' unless ref($cb) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cb eq "CODE" 0 9 9
512 croak 'on_data(): receive body has already started or finished'
513 9 ▶ if $self->{receive_started} || $self->{receive_done} || $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"receive_started"} or $self->{"receive_done"} or $self->is_terminal 2 7 9
Condition66%4/6
$self->{"receive_started"} or $self->{"receive_done"} or $self->is_terminal
l!l&&r!l&&!r
207
$self->{"receive_started"} or $self->{"receive_done"}
l!l&&r!l&&!r
207
MC/DC33%1/3
$self->{"receive_started"} or $self->{"receive_done"} or $self->is_terminal
$self->{"receive_started"} $self->{"receive_done"} $self->is_terminal
Truth table50%2/4
A or B or C
A= $self->{"receive_started"}B= $self->{"receive_done"}C= $self->is_terminal
ABCresult
1XX1
01X1
0011
0000
514 croak 'on_data(): cannot be combined with on_body'
515 7 ▶ if $self->{callbacks}{on_body};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"callbacks"}{"on_body"} 0 7 7
516 7 ▶ croak 'on_data(): callback is already registered' if $self->{callbacks}{on_data};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"callbacks"}{"on_data"} 0 7 7
517 my $connection = $self->{connection}
518 7 ▶ or croak 'on_data(): HTTP/3 connection is gone';
Branch: 1 branch
BranchTrueFalseTotal
my $connection = $self->{"connection"} or croak("on_data(): HTTP/3 connection is gone") 7 0 7
519 7 ▶ my $kind = $connection->role eq 'server' ? 'request' : 'response';
Branch: 1 branch
BranchTrueFalseTotal
$connection->role eq 'server' ? : 5 2 7
520 7 my $reader = $self->{ $kind . '_body' };
521 croak 'on_data(): body reader already has an on_data callback'
522 if ($reader && $reader->{on_data})
523 7 ▶ || $self->{ $kind . '_receive_options' }{on_data};
Branch: 1 branch
BranchTrueFalseTotal
if $reader and $reader->{"on_data"} or $$self{$kind . '_receive_options'}{"on_data"} 0 7 7
Condition33%2/6
$reader and $reader->{"on_data"} or $$self{$kind . '_receive_options'}{"on_data"}
l!l&&r!l&&!r
007
$reader and $reader->{"on_data"}
!ll&&!rl&&r
700
MC/DC0%0/3
$reader and $reader->{"on_data"} or $$self{$kind . '_receive_options'}{"on_data"}
$reader $reader->{"on_data"} $$self{$kind . '_receive_options'}{"on_data"}
Truth table20%1/5
A and B or C
A= $readerB= $reader->{"on_data"}C= $$self{$kind . '_receive_options'}{"on_data"}
ABCresult
11X1
0X11
1011
0X00
1000
524 7 my $weak = $self;
525 7 weaken($weak);
526 5 ▶ my $deliver = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
527 5 my ($reader, $bytes) = @_;
528 5 ▶ my $tx = $weak or return;
Branch: 1 branch
BranchTrueFalseTotal
my $tx = $weak or return 5 0 5
529 5 my $result = $tx->_invoke('on_data', $bytes);
530 5 ▶ die $result unless $result eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $result eq 1 1 4 5
531 7 };
532 7 $self->{callbacks}{on_data} = $cb;
533 7 $self->{ $kind . '_receive_mode' } = 'stream';
534 7 ▶ if ($reader) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reader) { } 0 7 7
535 0 $reader->_configure(on_data => $deliver);
536 } else {
537 7 $self->{ $kind . '_receive_options' }{on_data} = $deliver;
538 }
539 7 return $self;
540 }
541  
542 19 ▶sub on_finish {
Subroutine on_finish: called CC=4 SCAR=14.0
Pod undocumented
543 19 my ($self, $cb) = @_;
544 19 ▶ croak 'on_finish(): callback must be a coderef' unless ref($cb) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cb eq "CODE" 0 19 19
545 19 ▶ croak 'on_finish(): Transaction is terminal' if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 4 15 19
546 15 ▶ croak 'on_finish(): callback is already registered' if $self->{callbacks}{on_finish};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"callbacks"}{"on_finish"} 0 15 15
547 15 $self->{callbacks}{on_finish} = $cb;
548 15 return $self;
549 }
550  
551 88 ▶sub _notify_finish {
Subroutine _notify_finish: called CC=4 SCAR=14.2
552 88 my ($self) = @_;
553 88 ▶ return unless $self->is_terminal && !$self->{finish_called};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_terminal and not $self->{"finish_called"} 0 88 88
Condition33%1/3
$self->is_terminal and not $self->{"finish_called"}
!ll&&!rl&&r
0088
MC/DC0%0/2
$self->is_terminal and not $self->{"finish_called"}
$self->is_terminal not $self->{"finish_called"}
Truth table33%1/3
A and not(B)
A= $self->is_terminalB= not $self->{"finish_called"}
ABresult
0X0
100
111
554 88 $self->{finish_pending} = 1;
555 88 ▶ return if $self->{callback_depth};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"callback_depth"} 6 82 88
556 82 $self->{finish_called} = 1;
557 82 delete $self->{finish_pending};
558 # Terminal observers cannot undo cleanup or recursively report an error.
559 82 $self->_invoke('on_finish');
560 82 return;
561 }
562  
563 250 ▶sub _invoke {
Subroutine _invoke: called CC=8 SCAR=20.8
564 250 my ($self, $name, @args) = @_;
565  
566 250 ▶ my $callback = $self->{callbacks}{$name} or return 1;
Branch: 1 branch
BranchTrueFalseTotal
my $callback = $self->{"callbacks"}{$name} or return 1 105 145 250
567  
568 105 $self->{callback_depth}++;
569 105 my $ok = eval {
570 105 $callback->($self, @args);
571 98 1;
572 };
573  
574 105 my $error = "$@";
575 105 $self->{callback_depth}--;
576 105 ▶ if (!$ok && !$self->is_terminal
Branch: 1 branch
BranchTrueFalseTotal
if (not $ok || $self->is_terminal and $name =~ /\Aon_(?:request|response|data|body|request_end|informational)\z/) 1 104 105
Condition83%5/6
not $ok || $self->is_terminal and $name =~ /\Aon_(?:request|response|data|body|request_end|informational)\z/
!ll&&!rl&&r
10401
$ok || $self->is_terminal
l!l&&r!l&&!r
9861
MC/DC66%2/3
not $ok || $self->is_terminal and $name =~ /\Aon_(?:request|response|data|body|request_end|informational)\z/
$ok $self->is_terminal $name =~ /\Aon_(?:request|response|data|body|request_end|informational)\z/
Truth table75%3/4
not(A || B) and C
A= $okB= $self->is_terminalC= $name =~ /\Aon_(?:request|response|data|body|request_end|informational)\z/
ABCresult
1XX0
01X0
0000
0011
577 && $name =~ /\Aon_(?:request|response|data|body|request_end|informational)\z/) {
578 1 my $connection = $self->{connection};
579 1 ▶ $connection->_reject_message_stream($self->stream_id, $error)
Branch: 1 branch
BranchTrueFalseTotal
if $connection 1 0 1
580 if $connection;
581 1 eval { $self->_mark_error($error) };
582 }
583 105 ▶ $self->_notify_finish if $self->{finish_pending};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"finish_pending"} 4 101 105
584 105 ▶ return $ok ? 1 : $error;
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 98 7 105
585 }
586  
587 1 ▶sub next_informational {
Subroutine next_informational: called CC=2 SCAR=7.0
Pod undocumented
588 1 my ($self, @args) = @_;
589  
590 1 ▶ croak 'next_informational() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 1 1
591 1 return shift @{ $self->{informational} };
592 }
593  
594 7 ▶sub send_informational {
Subroutine send_informational: called CC=12 SCAR=25.8
Pod undocumented
595 7 my ($self, @arg) = @_;
596  
597 7 my $response;
598 7 ▶ if (@arg && ref($arg[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (@arg and ref $arg[0]) { } 3 4 7
Condition66%2/3
@arg and ref $arg[0]
!ll&&!rl&&r
043
MC/DC50%1/2
@arg and ref $arg[0]
@arg ref $arg[0]
Truth table66%2/3
A and B
A= @argB= ref $arg[0]
ABresult
0X0
100
111
599 3 ▶ croak 'send_informational(): response object does not take options'
Branch: 1 branch
BranchTrueFalseTotal
unless @arg == 1 1 2 3
600 unless @arg == 1;
601 2 $response = $arg[0];
602 } else {
603 4 ▶ croak 'send_informational(): fields must be key/value pairs'
Branch: 1 branch
BranchTrueFalseTotal
if @arg % 2 1 3 4
604 if @arg % 2;
605 3 $response = Uniform::HTTP::Response->new(@arg);
606 }
607  
608 5 ▶ croak 'send_informational(): Transaction is already terminal'
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 5 5
609 if $self->is_terminal;
610 my $connection = $self->{connection}
611 5 ▶ or croak 'send_informational(): Transaction no longer has a connection';
Branch: 1 branch
BranchTrueFalseTotal
my $connection = $self->{"connection"} or croak("send_informational(): Transaction no longer has a connection") 5 0 5
612  
613 5 $connection->_assert_response_contract(
614 $response,
615 'send_informational()',
616 );
617 5 ▶ croak 'send_informational(): status must be 100 through 199, excluding 101'
Branch: 1 branch
BranchTrueFalseTotal
unless $response->status >= 100 and $response->status <= 199 and $response->status != 101 1 4 5
Condition50%3/6
$response->status >= 100 and $response->status <= 199 and $response->status != 101
!ll&&!rl&&r
014
$response->status >= 100 and $response->status <= 199
!ll&&!rl&&r
005
MC/DC33%1/3
$response->status >= 100 and $response->status <= 199 and $response->status != 101
$response->status >= 100 $response->status <= 199 $response->status != 101
Truth table50%2/4
A and B and C
A= $response->status >= 100B= $response->status <= 199C= $response->status != 101
ABCresult
0XX0
10X0
1100
1111
618 unless $response->status >= 100
619 && $response->status <= 199
620 && $response->status != 101;
621 4 ▶ croak 'send_informational(): informational responses cannot have a body'
Branch: 1 branch
BranchTrueFalseTotal
if $response->has_buffered_body 0 4 4
622 if $response->has_buffered_body;
623 4 ▶ croak 'send_informational(): informational responses cannot have trailers'
Branch: 1 branch
BranchTrueFalseTotal
if $response->has_trailers 0 4 4
624 if $response->has_trailers;
625  
626 4 $connection->_send_informational_response(
627 $self,
628 $response,
629 );
630  
631 4 return $self;
632 }
633  
634 2 ▶sub is_response_started {
Subroutine is_response_started: called CC=3 SCAR=11.7
Pod undocumented
635 2 my ($self, @args) = @_;
636 2 ▶ croak 'is_response_started() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 2 2
637 2 ▶ return $self->{response_output_started} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'response_output_started'} ? : 2 0 2
638 }
639  
640 70 ▶sub request_body {
Subroutine request_body: called CC=13 SCAR=26.7
Pod undocumented
641 70 my ($self, @args) = @_;
642  
643 70 ▶ if (my $body = $self->{request_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $body = $self->{"request_body"}) 40 30 70
644 40 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 1 39 40
645 1 ▶ croak 'request_body options must be key/value pairs'
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 1 1
646 if @args % 2;
647  
648 1 ▶ if ($body->can('_configure')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($body->can('_configure')) { } 1 0 1
649 1 $body->_configure(@args);
650 } else {
651 0 croak 'request_body options may only be supplied when the producer is created';
652 }
653 }
654  
655 40 return $body;
656 }
657  
658 30 ▶ croak 'request_body(): Transaction is already terminal'
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 30 30
659 if $self->is_terminal;
660  
661 my $connection = $self->{connection}
662 30 ▶ or croak 'request_body(): Transaction no longer has a connection';
Branch: 1 branch
BranchTrueFalseTotal
my $connection = $self->{"connection"} or croak("request_body(): Transaction no longer has a connection") 30 0 30
663  
664 30 ▶ if ($connection->role eq 'server') {
Branch: 1 branch
BranchTrueFalseTotal
if ($connection->role eq "server") 16 14 30
665 croak 'request_body(): request receive mode is buffered'
666 16 ▶ unless $self->{request_receive_mode} eq 'stream';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"request_receive_mode"} eq "stream" 0 16 16
667 16 ▶ croak 'request_body options must be key/value pairs'
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 16 16
668 if @args % 2;
669  
670 16 require Unblock::HTTP3::Body::Reader;
671  
672 my %option = (
673 16 ▶ %{ $self->{request_receive_options} || {} },
Condition50%1/2
$self->{'request_receive_options'} || {}
l!l
160
MC/DC0%0/1
$self->{'request_receive_options'} || {}
$self->{'request_receive_options'}
Truth table50%1/2
A
A= $self->{'request_receive_options'}
Aresult
11
00
674 @args,
675 );
676  
677 16 my $body = Unblock::HTTP3::Body::Reader->_new(
678 $self,
679 'request',
680 %option,
681 );
682  
683 16 $self->{request_body} = $body;
684 16 return $body;
685 }
686  
687 croak 'request_body(): Request is not configured for incremental body production'
688 14 ▶ unless $self->{request_streaming};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"request_streaming"} 0 14 14
689 14 ▶ croak 'request_body options must be key/value pairs'
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 14 14
690 if @args % 2;
691  
692 14 require Unblock::HTTP3::Body::Stream;
693  
694 14 my $body = Unblock::HTTP3::Body::Stream->_new(
695 $self,
696 'request',
697 @args,
698 );
699  
700 14 $self->{request_body} = $body;
701 14 return $body;
702 }
703  
704 82 ▶sub response_body {
Subroutine response_body: called CC=15 SCAR=30.9
Pod undocumented
705 82 my ($self, @args) = @_;
706  
707 82 ▶ if (my $body = $self->{response_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $body = $self->{"response_body"}) 58 24 82
708 58 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 0 58 58
709 0 ▶ croak 'response_body options must be key/value pairs'
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 0 0
710 if @args % 2;
711  
712 0 ▶ if ($body->can('_configure')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($body->can('_configure')) { } 0 0 0
713 0 $body->_configure(@args);
714 } else {
715 0 croak 'response_body options may only be supplied when the producer is created';
716 }
717 }
718  
719 58 return $body;
720 }
721  
722 24 ▶ croak 'response_body(): Transaction is already terminal'
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 24 24
723 if $self->is_terminal;
724  
725 my $connection = $self->{connection}
726 24 ▶ or croak 'response_body(): Transaction no longer has a connection';
Branch: 1 branch
BranchTrueFalseTotal
my $connection = $self->{"connection"} or croak("response_body(): Transaction no longer has a connection") 24 0 24
727  
728 24 ▶ if ($connection->role eq 'client') {
Branch: 1 branch
BranchTrueFalseTotal
if ($connection->role eq "client") 10 14 24
729 croak 'response_body(): response receive mode is buffered'
730 10 ▶ unless $self->{response_receive_mode} eq 'stream';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"response_receive_mode"} eq "stream" 0 10 10
731 10 ▶ croak 'response_body options must be key/value pairs'
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 10 10
732 if @args % 2;
733  
734 10 require Unblock::HTTP3::Body::Reader;
735  
736 my %option = (
737 10 ▶ %{ $self->{response_receive_options} || {} },
Condition50%1/2
$self->{'response_receive_options'} || {}
l!l
100
MC/DC0%0/1
$self->{'response_receive_options'} || {}
$self->{'response_receive_options'}
Truth table50%1/2
A
A= $self->{'response_receive_options'}
Aresult
11
00
738 @args,
739 );
740  
741 10 my $body = Unblock::HTTP3::Body::Reader->_new(
742 $self,
743 'response',
744 %option,
745 );
746  
747 10 $self->{response_body} = $body;
748 10 return $body;
749 }
750  
751 croak 'response_body(): response output has already started'
752 14 ▶ if $self->{response_output_started};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"response_output_started"} 0 14 14
753 14 ▶ croak 'response_body options must be key/value pairs'
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 14 14
754 if @args % 2;
755  
756 my $response = $self->{response}
757 14 ▶ or croak 'response_body(): Transaction has no Response';
Branch: 1 branch
BranchTrueFalseTotal
my $response = $self->{"response"} or croak("response_body(): Transaction has no Response") 14 0 14
758  
759 14 $connection->_assert_response_body_allowed(
760 $self,
761 $response,
762 'response_body()',
763 );
764  
765 10 $self->{response_streaming} = 1;
766 10 ▶ $response->mark_incomplete if $response->can('mark_incomplete');
Branch: 1 branch
BranchTrueFalseTotal
if $response->can("mark_incomplete") 10 0 10
767  
768 10 require Unblock::HTTP3::Body::Stream;
769  
770 10 my $body = Unblock::HTTP3::Body::Stream->_new(
771 $self,
772 'response',
773 @args,
774 );
775  
776 10 $self->{response_body} = $body;
777 10 return $body;
778 }
779  
780 35 ▶sub respond {
Subroutine respond: called CC=9 SCAR=22.2
Pod undocumented
781 35 my ($self, @arg) = @_;
782  
783 35 my ($response, %option);
784 35 ▶ if (@arg && ref($arg[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (@arg and ref $arg[0]) { } 26 9 35
Condition66%2/3
@arg and ref $arg[0]
!ll&&!rl&&r
0926
MC/DC50%1/2
@arg and ref $arg[0]
@arg ref $arg[0]
Truth table66%2/3
A and B
A= @argB= ref $arg[0]
ABresult
0X0
100
111
785 26 $response = shift @arg;
786 26 ▶ croak 'respond(): options must be key/value pairs' if @arg % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @arg % 2 0 26 26
787 26 %option = @arg;
788 } else {
789 9 ▶ croak 'respond(): fields must be key/value pairs' if @arg % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @arg % 2 1 8 9
790 8 my %field = @arg;
791 8 for my $name (qw(stream_body on_drain on_error)) {
792 24 ▶ $option{$name} = delete $field{$name} if exists $field{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $field{$name} 3 21 24
793 }
794 8 $response = Uniform::HTTP::Response->new(%field);
795 }
796  
797 34 ▶ croak 'respond(): Transaction is already terminal'
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 34 34
798 if $self->is_terminal;
799  
800 my $connection = $self->{connection}
801 34 ▶ or croak 'respond(): HTTP/3 connection is no longer available';
Branch: 1 branch
BranchTrueFalseTotal
my $connection = $self->{"connection"} or croak("respond(): HTTP/3 connection is no longer available") 34 0 34
802  
803 34 $connection->_respond_transaction(
804 $self,
805 $response,
806 %option,
807 );
808  
809 25 return $self;
810 }
811  
812 2 ▶sub write {
Subroutine write: called CC=3 SCAR=11.4
Pod undocumented
813 2 my ($self, $bytes) = @_;
814  
815 2 ▶ croak 'write(): Transaction is already terminal'
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 2 2
816 if $self->is_terminal;
817  
818 my $connection = $self->{connection}
819 2 ▶ or croak 'write(): HTTP/3 connection is no longer available';
Branch: 1 branch
BranchTrueFalseTotal
my $connection = $self->{"connection"} or croak("write(): HTTP/3 connection is no longer available") 2 0 2
820  
821 2 return $connection->_write_stream_body(
822 $self,
823 $bytes,
824 0,
825 'write',
826 );
827 }
828  
829 2 ▶sub end {
Subroutine end: called CC=5 SCAR=17.0
Pod undocumented
830 2 my ($self, @args) = @_;
831  
832 2 ▶ croak 'end(): accepts at most one final byte string'
Branch: 1 branch
BranchTrueFalseTotal
if @args > 1 0 2 2
833 if @args > 1;
834 2 ▶ croak 'end(): Transaction is already terminal'
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 2 2
835 if $self->is_terminal;
836  
837 my $connection = $self->{connection}
838 2 ▶ or croak 'end(): HTTP/3 connection is no longer available';
Branch: 1 branch
BranchTrueFalseTotal
my $connection = $self->{"connection"} or croak("end(): HTTP/3 connection is no longer available") 2 0 2
839  
840 2 ▶ my $bytes = @args ? $args[0] : '';
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 2 0 2
841 2 $connection->_write_stream_body(
842 $self,
843 $bytes,
844 1,
845 'end',
846 );
847  
848 2 return $self;
849 }
850  
851 23 ▶sub cancel {
Subroutine cancel: called CC=4 SCAR=14.3
Pod undocumented
852 23 my ($self) = @_;
853  
854 23 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 17 6 23
855  
856 6 my $connection = $self->{connection};
857 6 ▶ if (defined $connection) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $connection) 6 0 6
858 6 $connection->_cancel_transaction($self);
859 }
860  
861 6 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 6 0 6
862 0 return $self->_mark_cancelled;
863 }
864  
865 76 ▶sub _configure_receive_body {
Subroutine _configure_receive_body: called CC=6 SCAR=19.0
866 76 my ($self, $kind, $mode, $options) = @_;
867  
868 76 ▶ croak "unsupported HTTP body receive kind '$kind'"
Branch: 1 branch
BranchTrueFalseTotal
if $kind ne "request" and $kind ne "response" 0 76 76
Condition66%2/3
$kind ne "request" and $kind ne "response"
!ll&&!rl&&r
38380
MC/DC0%0/2
$kind ne "request" and $kind ne "response"
$kind ne "request" $kind ne "response"
Truth table66%2/3
A and B
A= $kind ne "request"B= $kind ne "response"
ABresult
0X0
100
111
869 if $kind ne 'request' && $kind ne 'response';
870 76 ▶ croak 'receive body mode must be buffered or stream'
Branch: 1 branch
BranchTrueFalseTotal
if $mode ne "buffered" and $mode ne "stream" 0 76 76
Condition66%2/3
$mode ne "buffered" and $mode ne "stream"
!ll&&!rl&&r
54220
MC/DC0%0/2
$mode ne "buffered" and $mode ne "stream"
$mode ne "buffered" $mode ne "stream"
Truth table66%2/3
A and B
A= $mode ne "buffered"B= $mode ne "stream"
ABresult
0X0
100
111
871 if $mode ne 'buffered' && $mode ne 'stream';
872 76 ▶ croak 'receive body options must be a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $options eq "HASH" 0 76 76
873 unless ref($options) eq 'HASH';
874  
875 76 $self->{ $kind . '_receive_mode' } = $mode;
876 76 $self->{ $kind . '_receive_options' } = { %$options };
877  
878 76 return $self;
879 }
880  
881 131 ▶sub _ensure_receive_reader {
Subroutine _ensure_receive_reader: called CC=3 SCAR=11.0
882 131 my ($self, $kind) = @_;
883  
884 131 ▶ return unless $self->{ $kind . '_receive_mode' } eq 'stream';
Branch: 1 branch
BranchTrueFalseTotal
unless $$self{$kind . '_receive_mode'} eq "stream" 19 112 131
885  
886 112 ▶ return $kind eq 'request'
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'request' ? : 48 64 112
887 ? $self->request_body
888 : $self->response_body;
889 }
890  
891 212 ▶sub _incoming_body_reader {
Subroutine _incoming_body_reader: called CC=2 SCAR=6.9
892 212 my ($self, $kind) = @_;
893  
894 212 ▶ return unless $self->{ $kind . '_receive_mode' } eq 'stream';
Branch: 1 branch
BranchTrueFalseTotal
unless $$self{$kind . '_receive_mode'} eq "stream" 124 88 212
895  
896 88 return $self->_ensure_receive_reader($kind);
897 }
898  
899 35 ▶sub _consume_received_body {
Subroutine _consume_received_body: called CC=2 SCAR=7.0
900 35 my ($self, $kind, $amount) = @_;
901  
902 my $connection = $self->{connection}
903 35 ▶ or croak 'received body lost its HTTP/3 connection';
Branch: 1 branch
BranchTrueFalseTotal
my $connection = $self->{"connection"} or croak("received body lost its HTTP/3 connection") 35 0 35
904  
905 35 $connection->_consume_received_body(
906 $self,
907 $kind,
908 $amount,
909 );
910  
911 35 return;
912 }
913  
914 # Complete may send FIN and drive native callbacks before the outbound
915 # Body::Stream marks itself finished. Recheck only once that flag is set.
916 # The Connection retains authority over terminal and callback-depth guards.
917 20 ▶sub _outgoing_body_complete {
Subroutine _outgoing_body_complete: called CC=3 SCAR=11.0
918 20 my ($self, $kind) = @_;
919 20 ▶ return if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 5 15 20
920  
921 15 ▶ my $connection = $self->{connection} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $connection = $self->{"connection"} or return 15 0 15
922 15 $connection->_maybe_complete_transaction($self->{stream_id});
923 15 return;
924 }
925  
926 20 ▶sub _received_body_complete {
Subroutine _received_body_complete: called CC=5 SCAR=19.6
927 20 my ($self, $kind) = @_;
928  
929 20 $self->{receive_done} = 1;
930 $self->_invoke_request_end
931 if $kind eq 'request'
932 20 ▶ && $self->{request_receive_mode} eq 'stream';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "request" and $self->{"request_receive_mode"} eq "stream" 10 10 20
Condition66%2/3
$kind eq "request" and $self->{"request_receive_mode"} eq "stream"
!ll&&!rl&&r
10010
MC/DC50%1/2
$kind eq "request" and $self->{"request_receive_mode"} eq "stream"
$kind eq "request" $self->{"request_receive_mode"} eq "stream"
Truth table66%2/3
A and B
A= $kind eq "request"B= $self->{"request_receive_mode"} eq "stream"
ABresult
0X0
100
111
933  
934 20 ▶ return if $self->{callback_depth};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"callback_depth"} 20 0 20
935 0 my $connection = $self->{connection};
936 $connection->_maybe_complete_transaction($self->{stream_id})
937 0 ▶ if defined $connection;
Branch: 1 branch
BranchTrueFalseTotal
if defined $connection 0 0 0
938  
939 0 return;
940 }
941  
942 1 ▶sub _capsule_protocol_error {
Subroutine _capsule_protocol_error: called CC=3 SCAR=11.6
943 1 my ($self, $error) = @_;
944  
945 1 ▶ return if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 1 1
946  
947 1 my $connection = $self->{connection};
948 1 ▶ if (defined $connection) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $connection) { } 1 0 1
949 1 $connection->_capsule_protocol_error(
950 $self,
951 $error,
952 );
953 } else {
954 0 $self->_mark_error($error);
955 }
956  
957 1 return;
958 }
959  
960 40 ▶sub _write_body {
Subroutine _write_body: called CC=10 SCAR=23.8
961 40 my ($self, $kind, $bytes, $final, $operation) = @_;
962  
963 40 ▶ croak "$operation(): Transaction is already terminal"
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 40 40
964 if $self->is_terminal;
965 40 ▶ croak "$operation(): unsupported HTTP body producer '$kind'"
Branch: 1 branch
BranchTrueFalseTotal
if $kind ne "request" and $kind ne "response" 0 40 40
Condition66%2/3
$kind ne "request" and $kind ne "response"
!ll&&!rl&&r
23170
MC/DC0%0/2
$kind ne "request" and $kind ne "response"
$kind ne "request" $kind ne "response"
Truth table66%2/3
A and B
A= $kind ne "request"B= $kind ne "response"
ABresult
0X0
100
111
966 if $kind ne 'request' && $kind ne 'response';
967  
968 my $message = $kind eq 'request'
969 ? $self->{request}
970 : ($self->{response}
971 40 ▶ or croak "$operation(): Transaction has no Response");
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'request' ? : 23 17 40
Condition50%1/2
$self->{"response"} or croak("$operation(): Transaction has no Response")
l!l
170
MC/DC0%0/1
$self->{"response"} or croak("$operation(): Transaction has no Response")
$self->{"response"}
Truth table50%1/2
A
A= $self->{"response"}
Aresult
11
00
972  
973 my $connection = $self->{connection}
974 40 ▶ or croak "$operation(): Transaction no longer has a connection";
Branch: 1 branch
BranchTrueFalseTotal
my $connection = $self->{"connection"} or croak("$operation(): Transaction no longer has a connection") 40 0 40
975  
976 40 my ($can_continue, $ok, $error);
977  
978 {
979 40 local $@;
980 40 $ok = eval {
981 40 $can_continue = $connection->_write_transaction_body(
982 $self,
983 $kind,
984 $bytes,
985 $final,
986 $operation,
987 );
988 40 1;
989 };
990 40 $error = $@;
991 }
992  
993 40 ▶ die $error unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 40 40
994  
995 40 ▶ $message->mark_complete
Branch: 1 branch
BranchTrueFalseTotal
if $final and $message->can("mark_complete") 20 20 40
Condition66%2/3
$final and $message->can("mark_complete")
!ll&&!rl&&r
20020
MC/DC50%1/2
$final and $message->can("mark_complete")
$final $message->can("mark_complete")
Truth table66%2/3
A and B
A= $finalB= $message->can("mark_complete")
ABresult
0X0
100
111
996 if $final && $message->can('mark_complete');
997 40 return $can_continue;
998 }
999  
1000 25 ▶sub _request_is_streaming {
Subroutine _request_is_streaming: called CC=2 SCAR=7.2
1001 25 my ($self) = @_;
1002 25 ▶ return $self->{request_streaming} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'request_streaming'} ? : 25 0 25
1003 }
1004  
1005 59 ▶sub _response_is_streaming {
Subroutine _response_is_streaming: called CC=2 SCAR=6.9
1006 59 my ($self) = @_;
1007 59 ▶ return $self->{response_streaming} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'response_streaming'} ? : 31 28 59
1008 }
1009  
1010 2 ▶sub _enable_response_streaming {
Subroutine _enable_response_streaming: called CC=2 SCAR=7.0
1011 2 my ($self) = @_;
1012 2 $self->{response_streaming} = 1;
1013 2 ▶ $self->{response}->mark_incomplete if defined $self->{response};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"response"} 2 0 2
1014 2 return $self;
1015 }
1016  
1017 40 ▶sub _buffered_body_bytes {
Subroutine _buffered_body_bytes: called CC=4 SCAR=14.1
1018 40 my ($self, $kind) = @_;
1019 40 ▶ croak "unsupported buffered body kind '$kind'"
Branch: 1 branch
BranchTrueFalseTotal
if $kind ne "request" and $kind ne "response" 0 40 40
Condition66%2/3
$kind ne "request" and $kind ne "response"
!ll&&!rl&&r
23170
MC/DC0%0/2
$kind ne "request" and $kind ne "response"
$kind ne "request" $kind ne "response"
Truth table66%2/3
A and B
A= $kind ne "request"B= $kind ne "response"
ABresult
0X0
100
111
1020 if $kind ne 'request' && $kind ne 'response';
1021  
1022 40 ▶ return 0 unless $self->{ $kind . '_buffered_seen' };
Branch: 1 branch
BranchTrueFalseTotal
unless $$self{$kind . '_buffered_seen'} 30 10 40
1023  
1024 return $self->{ $kind . '_buffered_bytes' }
1025 10 + length($self->{ $kind . '_buffered_body' });
1026 }
1027  
1028 33 ▶sub _append_buffered_body {
Subroutine _append_buffered_body: called CC=5 SCAR=16.9
1029 33 my ($self, $kind, $bytes) = @_;
1030 33 ▶ croak "unsupported buffered body kind '$kind'"
Branch: 1 branch
BranchTrueFalseTotal
if $kind ne "request" and $kind ne "response" 0 33 33
Condition66%2/3
$kind ne "request" and $kind ne "response"
!ll&&!rl&&r
14190
MC/DC0%0/2
$kind ne "request" and $kind ne "response"
$kind ne "request" $kind ne "response"
Truth table66%2/3
A and B
A= $kind ne "request"B= $kind ne "response"
ABresult
0X0
100
111
1031 if $kind ne 'request' && $kind ne 'response';
1032  
1033 33 $self->{ $kind . '_buffered_seen' } = 1;
1034  
1035 33 my $length = length($bytes);
1036  
1037 33 ▶ if ($length < $BUFFERED_BODY_RETAIN_BYTES) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length < $BUFFERED_BODY_RETAIN_BYTES) 29 4 33
1038 29 $self->{ $kind . '_buffered_body' } .= $bytes;
1039 29 return;
1040 }
1041  
1042 4 my $body_name = $kind . '_buffered_body';
1043 4 my $chunks = $self->{ $kind . '_buffered_chunks' };
1044 4 my $bytes_name = $kind . '_buffered_bytes';
1045  
1046 4 ▶ if (length($self->{$body_name})) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{$body_name}) 0 4 4
1047 0 my $tail = $self->{$body_name};
1048  
1049 0 push @$chunks, $tail;
1050 0 $self->{$bytes_name} += length($tail);
1051 0 $self->{$body_name} = '';
1052 }
1053  
1054 4 push @$chunks, $bytes;
1055 4 $self->{$bytes_name} += $length;
1056 4 return;
1057 }
1058  
1059 44 ▶sub _finish_received_message {
Subroutine _finish_received_message: called CC=12 SCAR=26.3
1060 44 my ($self, $kind) = @_;
1061 44 ▶ croak "unsupported received message kind '$kind'"
Branch: 1 branch
BranchTrueFalseTotal
if $kind ne "request" and $kind ne "response" 0 44 44
Condition66%2/3
$kind ne "request" and $kind ne "response"
!ll&&!rl&&r
22220
MC/DC0%0/2
$kind ne "request" and $kind ne "response"
$kind ne "request" $kind ne "response"
Truth table66%2/3
A and B
A= $kind ne "request"B= $kind ne "response"
ABresult
0X0
100
111
1062 if $kind ne 'request' && $kind ne 'response';
1063  
1064 my $message = $kind eq 'request'
1065 ? $self->{request}
1066 44 ▶ : $self->{response};
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'request' ? : 22 22 44
1067  
1068 44 ▶ return unless defined $message;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $message 0 44 44
1069  
1070 44 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($$self{$kind . '_receive_mode'} eq 'buffered') { } 44 0 44
1071 $self->{ $kind . '_receive_mode' } eq 'buffered'
1072 ) {
1073 44 my $body_name = $kind . '_buffered_body';
1074 44 my $chunks = $self->{ $kind . '_buffered_chunks' };
1075 44 my $body;
1076  
1077 44 ▶ if (@$chunks) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$chunks) { } 1 43 44
1078 push @$chunks, $self->{$body_name}
1079 1 ▶ if length($self->{$body_name});
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{$body_name} 0 1 1
1080  
1081 1 ▶ $body = @$chunks == 1
Branch: 1 branch
BranchTrueFalseTotal
@$chunks == 1 ? : 0 1 1
1082 ? $chunks->[0]
1083 : join('', @$chunks);
1084 } else {
1085 43 $body = $self->{$body_name};
1086 }
1087  
1088 44 $self->{$body_name} = '';
1089 44 $self->{ $kind . '_buffered_chunks' } = [];
1090 44 $self->{ $kind . '_buffered_bytes' } = 0;
1091 44 $self->{ $kind . '_buffered_seen' } = 0;
1092  
1093 44 ▶ $message->body($body) if $message->body_is_mutable;
Branch: 1 branch
BranchTrueFalseTotal
if $message->body_is_mutable 44 0 44
1094 } else {
1095 0 $self->{ $kind . '_buffered_body' } = '';
1096 0 $self->{ $kind . '_buffered_chunks' } = [];
1097 0 $self->{ $kind . '_buffered_bytes' } = 0;
1098 0 $self->{ $kind . '_buffered_seen' } = 0;
1099 }
1100  
1101 44 $message->freeze_trailers;
1102 44 $message->freeze;
1103 44 $message->mark_complete;
1104  
1105 44 $self->{receive_done} = 1;
1106 $self->_invoke_request_end
1107 if $kind eq 'request'
1108 44 ▶ && $self->{request_receive_mode} eq 'buffered';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "request" and $self->{"request_receive_mode"} eq "buffered" 22 22 44
Condition66%2/3
$kind eq "request" and $self->{"request_receive_mode"} eq "buffered"
!ll&&!rl&&r
22022
MC/DC50%1/2
$kind eq "request" and $self->{"request_receive_mode"} eq "buffered"
$kind eq "request" $self->{"request_receive_mode"} eq "buffered"
Truth table66%2/3
A and B
A= $kind eq "request"B= $self->{"request_receive_mode"} eq "buffered"
ABresult
0X0
100
111
1109  
1110 44 return;
1111 }
1112  
1113 32 ▶sub _invoke_request_end {
Subroutine _invoke_request_end: called CC=4 SCAR=15.0
1114 32 my ($self) = @_;
1115  
1116 32 ▶ return if $self->is_terminal || $self->{request_end_callback_called};
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal or $self->{"request_end_callback_called"} 0 32 32
Condition33%1/3
$self->is_terminal or $self->{"request_end_callback_called"}
l!l&&r!l&&!r
0032
MC/DC0%0/2
$self->is_terminal or $self->{"request_end_callback_called"}
$self->is_terminal $self->{"request_end_callback_called"}
Truth table33%1/3
A or B
A= $self->is_terminalB= $self->{"request_end_callback_called"}
ABresult
1X1
011
000
1117 32 $self->{request_end_callback_called} = 1;
1118  
1119 my $result = $self->_invoke(
1120 'on_request_end',
1121 $self->{request},
1122 32 );
1123 32 ▶ die $result unless $result eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $result eq 1 0 32 32
1124  
1125 32 return;
1126 }
1127  
1128 82 ▶sub _discard_received_body_buffers {
Subroutine _discard_received_body_buffers: called CC=2 SCAR=6.9
1129 82 my ($self) = @_;
1130  
1131 82 for my $kind (qw(request response)) {
1132 164 $self->{ $kind . '_buffered_body' } = '';
1133 164 $self->{ $kind . '_buffered_chunks' } = [];
1134 164 $self->{ $kind . '_buffered_bytes' } = 0;
1135 164 $self->{ $kind . '_buffered_seen' } = 0;
1136 }
1137  
1138 82 return;
1139 }
1140  
1141 443 ▶sub _request_body_object {
Subroutine _request_body_object: called CC=1 SCAR=0.0
1142 443 my ($self) = @_;
1143 443 return $self->{request_body};
1144 }
1145  
1146 431 ▶sub _response_body_object {
Subroutine _response_body_object: called CC=1 SCAR=0.0
1147 431 my ($self) = @_;
1148 431 return $self->{response_body};
1149 }
1150  
1151 30 ▶sub _mark_response_started {
Subroutine _mark_response_started: called CC=1 SCAR=0.0
1152 30 my ($self) = @_;
1153 30 $self->{response_output_started} = 1;
1154 30 return $self;
1155 }
1156  
1157 2 ▶sub _push_informational {
Subroutine _push_informational: called CC=2 SCAR=7.0
1158 2 my ($self, $response) = @_;
1159  
1160 2 ▶ croak 'informational response must implement the Uniform HTTP response contract'
Branch: 1 branch
BranchTrueFalseTotal
unless _response_contract($response) 0 2 2
1161 unless _response_contract($response);
1162  
1163 2 push @{ $self->{informational} }, $response;
1164 2 return $response;
1165 }
1166  
1167 30 ▶sub _set_response {
Subroutine _set_response: called CC=4 SCAR=14.5
1168 30 my ($self, $response) = @_;
1169  
1170 30 ▶ croak 'cannot attach a response to a terminal Transaction'
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 30 30
1171 if $self->is_terminal;
1172 croak 'Transaction already has a response'
1173 30 ▶ if defined $self->{response};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"response"} 0 30 30
1174 30 ▶ croak 'Transaction response must implement the Uniform HTTP response contract'
Branch: 1 branch
BranchTrueFalseTotal
unless _response_contract($response) 0 30 30
1175 unless _response_contract($response);
1176  
1177 30 $self->{response} = $response;
1178 30 return $response;
1179 }
1180  
1181 # Commit the terminal state before body cancellation callbacks can re-enter.
1182 # Always release both bodies and notify observers even when a callback throws.
1183 82 ▶sub _terminal_cleanup {
Subroutine _terminal_cleanup: called CC=6 SCAR=18.4
1184 82 my ($self) = @_;
1185 82 my $error = '';
1186 82 for my $body ($self->{request_body}, $self->{response_body}) {
1187 164 ▶ next unless $body && !$body->is_complete;
Branch: 1 branch
BranchTrueFalseTotal
unless $body and not $body->is_complete 150 14 164
Condition100%3/3
$body and not $body->is_complete
!ll&&!rl&&r
1163414
MC/DC100%2/2
$body and not $body->is_complete
$body not $body->is_complete
Truth table100%3/3
A and not(B)
A= $bodyB= not $body->is_complete
ABresult
0X0
100
111
1188 14 ▶ eval { $body->_cancel; 1 } or $error ||= "$@";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $body->_cancel; 1 } } or $error ||= "$@" 14 0 14
Condition0%0/3
$error ||= "$@"
l!l&&r!l&&!r
000
MC/DC0%0/2
$error ||= "$@"
$error "$@"
Truth table0%0/3
A ||= B
A= $errorB= "$@"
ABresult
1X1
011
000
1189 }
1190 82 $self->_discard_datagrams;
1191 82 $self->_discard_received_body_buffers;
1192 82 return $error;
1193 }
1194  
1195 56 ▶sub _mark_complete {
Subroutine _mark_complete: called CC=4 SCAR=14.0
1196 56 my ($self) = @_;
1197 56 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 56 56
1198 56 $self->{state} = 'complete';
1199 56 my $error = $self->_terminal_cleanup;
1200 56 my $result = $self->_invoke('on_complete');
1201 56 $self->_notify_finish;
1202 56 ▶ die $error if length $error;
Branch: 1 branch
BranchTrueFalseTotal
if length $error 0 56 56
1203 56 ▶ die $result unless $result eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $result eq 1 1 55 56
1204 55 return $self;
1205 }
1206  
1207 17 ▶sub _mark_cancelled {
Subroutine _mark_cancelled: called CC=3 SCAR=11.2
1208 17 my ($self) = @_;
1209 17 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 17 17
1210 17 $self->{state} = 'cancelled';
1211 17 my $error = $self->_terminal_cleanup;
1212 17 $self->_notify_finish;
1213 17 ▶ die $error if length $error;
Branch: 1 branch
BranchTrueFalseTotal
if length $error 0 17 17
1214 17 return $self;
1215 }
1216  
1217 9 ▶sub _mark_error {
Subroutine _mark_error: called CC=5 SCAR=16.3
1218 9 my ($self, $error, $error_code) = @_;
1219 9 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 9 9
1220 9 $self->{state} = 'error';
1221 9 ▶ $self->{error} = defined($error) ? "$error" : 'HTTP/3 transaction failed';
Branch: 1 branch
BranchTrueFalseTotal
defined $error ? : 9 0 9
1222 9 my $cleanup_error = $self->_terminal_cleanup;
1223 9 my $result = $self->_invoke('on_error', $self->{error}, $error_code);
1224 9 $self->_notify_finish;
1225 9 ▶ die $cleanup_error if length $cleanup_error;
Branch: 1 branch
BranchTrueFalseTotal
if length $cleanup_error 0 9 9
1226 9 ▶ die $result unless $result eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $result eq 1 2 7 9
1227 7 return $self;
1228 }
1229  
1230 25 1;
1231  
1232 __END__
« blib/lib/Unblock/HTTP3/Capsule/Parser.pm ↑ Summary blib/lib/Unblock/HTTP3/_Native.pm »