blib/lib/Unblock/HTTP3/Transaction.pm

filter: Statementstmt 95.5% 536 / 561 Branchbran 63.3% 251 / 396 Conditioncond 56.0% 70 / 125 MC/DCmcdc 21.9% 16 / 73 Subroutinesub 100% 85 / 85 Podpod 0.0% 0 / 35 totaltotal 75.1% 958 / 1275 CC 248 SCAR 20.6
CC
248
Cov
79%
response_body
22.1
_new
18.1
on_data
15.9
CRAP 7.9
« blib/lib/Unblock/HTTP3/Capsule/Parser.pm ↑ Summary blib/lib/Unblock/HTTP3/_Native.pm »
1 package Unblock::HTTP3::Transaction;
2  
3 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 24 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 24 ▶use Scalar::Util qw(blessed weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 24 ▶use Uniform::HTTP::Request 0.06 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 24 ▶use Uniform::HTTP::Response 0.06 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 24 ▶use Unblock::HTTP3 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 24 ▶use Unblock::HTTP3::_Native ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 24 our $VERSION = '0.13';
16  
17 24 my %TERMINAL = map { $_ => 1 } qw(complete cancelled error);
18 24 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 104 ▶sub _parse_priority_field {
Subroutine _parse_priority_field: called CC=4 SCAR=13.9
64 104 my ($value) = @_;
65  
66 return {
67 104 ▶ urgency => 3,
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 100 4 104
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 101 ▶sub _request_contract {
Subroutine _request_contract: called CC=4 SCAR=14.3
87 101 my ($request) = @_;
88 101 ▶ return unless blessed($request);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($request) 0 101 101
89  
90 101 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 1414 ▶ return unless $request->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $request->can($method) 0 1414 1414
97 }
98  
99 101 return 1;
100 }
101  
102 86 ▶sub _response_contract {
Subroutine _response_contract: called CC=4 SCAR=14.3
103 86 my ($response) = @_;
104 86 ▶ return unless blessed($response);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($response) 0 86 86
105  
106 86 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 860 ▶ return unless $response->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $response->can($method) 0 860 860
113 }
114  
115 86 return 1;
116 }
117  
118 101 ▶sub _new {
Subroutine _new: called CC=14 SCAR=29.0
119 101 my ($class, %args) = @_;
120  
121 101 my $connection = delete $args{connection};
122 101 my $stream_id = delete $args{stream_id};
123 101 my $request = delete $args{request};
124 101 my $response = delete $args{response};
125 101 ▶ my $callbacks = delete($args{callbacks}) || {};
Condition100%2/2
delete $args{'callbacks'} || {}
l!l
7328
MC/DC100%1/1
delete $args{'callbacks'} || {}
delete $args{'callbacks'}
Truth table100%2/2
A
A= delete $args{'callbacks'}
Aresult
11
00
126 101 ▶ my $request_streaming = delete $args{request_streaming} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
delete $args{'request_streaming'} ? : 15 86 101
127 101 ▶ my $early_data = delete $args{early_data} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
delete $args{'early_data'} ? : 3 98 101
128  
129 101 ▶ croak 'Transaction requires a Unblock::HTTP3::Connection'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($connection) and $connection->isa("Unblock::HTTP3::Connection") 0 101 101
Condition33%1/3
builtin::blessed($connection) and $connection->isa("Unblock::HTTP3::Connection")
!ll&&!rl&&r
00101
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 101 ▶ 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 101 101
Condition33%2/6
defined $stream_id and not ref $stream_id and $stream_id =~ /\A[0-9]+\z/
!ll&&!rl&&r
00101
defined $stream_id and not ref $stream_id
!ll&&!rl&&r
00101
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 101 ▶ croak 'Transaction requires the Uniform HTTP request contract'
Branch: 1 branch
BranchTrueFalseTotal
unless _request_contract($request) 0 101 101
137 unless _request_contract($request);
138 101 ▶ croak 'Transaction response must implement the Uniform HTTP response contract'
Branch: 1 branch
BranchTrueFalseTotal
if defined $response and not _response_contract($response) 0 101 101
Condition66%2/3
defined $response and not _response_contract($response)
!ll&&!rl&&r
46550
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 101 ▶ croak 'Transaction callbacks must be a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $callbacks eq "HASH" 0 101 101
142 unless ref($callbacks) eq 'HASH';
143 101 ▶ croak 'unknown Transaction option: ' . join(', ', sort keys %args)
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 101 101
144 if %args;
145  
146 101 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 101 weaken($self->{connection});
188  
189 101 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 925 ▶sub stream_id {
Subroutine stream_id: called CC=2 SCAR=7.1
Pod undocumented
199 925 my ($self, @args) = @_;
200 925 ▶ croak 'stream_id() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 925 925
201 925 return $self->{stream_id};
202 }
203  
204 363 ▶sub request {
Subroutine request: called CC=2 SCAR=7.1
Pod undocumented
205 363 my ($self, @args) = @_;
206 363 ▶ croak 'request() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 363 363
207 363 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 260 ▶sub response {
Subroutine response: called CC=2 SCAR=7.1
Pod undocumented
223 260 my ($self, @args) = @_;
224 260 ▶ croak 'response() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 260 260
225 260 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 9 ▶sub remote_reset_code {
Subroutine remote_reset_code: called CC=2 SCAR=7.1
Pod undocumented
235 9 my ($self, @args) = @_;
236 9 ▶ croak 'remote_reset_code() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 9 9
237 9 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 4 ▶sub _mark_remote_stop_sending {
Subroutine _mark_remote_stop_sending: called CC=1 SCAR=0.0
283 4 my ($self, $code) = @_;
284 4 $self->{remote_stop_sending_code} = 0 + $code;
285 4 return $self;
286 }
287  
288 10 ▶sub priority {
Subroutine priority: called CC=6 SCAR=18.6
Pod undocumented
289 10 my ($self, @args) = @_;
290  
291 10 my $connection = $self->{connection};
292  
293 10 ▶ if (!@args) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@args) 8 2 10
294 8 ▶ return { %{ $self->{priority} } }
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal or not defined $connection 0 8 8
Condition33%1/3
$self->is_terminal or not defined $connection
l!l&&r!l&&!r
008
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 8 my $priority = $connection->_transaction_priority($self);
298 8 $self->{priority} = { %$priority };
299  
300 8 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 79 ▶sub _discard_datagrams {
Subroutine _discard_datagrams: called CC=3 SCAR=11.0
443 79 my ($self) = @_;
444  
445 79 my $connection = $self->{connection};
446  
447 79 ▶ if (defined $connection) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $connection) 77 2 79
448 77 for my $bytes (@{ $self->{datagram_queue} }) {
449 0 $connection->_datagram_dequeued(length($bytes));
450 }
451 }
452  
453 79 $self->{datagram_queue} = [];
454 79 $self->{datagram_callback} = undef;
455 79 return;
456 }
457  
458 32 ▶sub state {
Subroutine state: called CC=2 SCAR=7.1
Pod undocumented
459 32 my ($self, @args) = @_;
460 32 ▶ croak 'state() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 32 32
461 32 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 114 ▶sub is_complete {
Subroutine is_complete: called CC=3 SCAR=11.1
Pod undocumented
471 114 my ($self, @args) = @_;
472 114 ▶ croak 'is_complete() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 114 114
473 114 ▶ return $self->{state} eq 'complete' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'state'} eq 'complete' ? : 50 64 114
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 1708 ▶sub is_terminal {
Subroutine is_terminal: called CC=3 SCAR=11.1
Pod undocumented
489 1708 my ($self, @args) = @_;
490 1708 ▶ croak 'is_terminal() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 1708 1708
491 1708 ▶ return $TERMINAL{ $self->{state} } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$TERMINAL{$self->{'state'}} ? : 551 1157 1708
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 85 ▶sub _notify_finish {
Subroutine _notify_finish: called CC=4 SCAR=14.2
552 85 my ($self) = @_;
553 85 ▶ return unless $self->is_terminal && !$self->{finish_called};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_terminal and not $self->{"finish_called"} 0 85 85
Condition33%1/3
$self->is_terminal and not $self->{"finish_called"}
!ll&&!rl&&r
0085
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 85 $self->{finish_pending} = 1;
555 85 ▶ return if $self->{callback_depth};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"callback_depth"} 6 79 85
556 79 $self->{finish_called} = 1;
557 79 delete $self->{finish_pending};
558 # Terminal observers cannot undo cleanup or recursively report an error.
559 79 $self->_invoke('on_finish');
560 79 return;
561 }
562  
563 243 ▶sub _invoke {
Subroutine _invoke: called CC=8 SCAR=20.8
564 243 my ($self, $name, @args) = @_;
565  
566 243 ▶ my $callback = $self->{callbacks}{$name} or return 1;
Branch: 1 branch
BranchTrueFalseTotal
my $callback = $self->{"callbacks"}{$name} or return 1 103 140 243
567  
568 103 $self->{callback_depth}++;
569 103 my $ok = eval {
570 103 $callback->($self, @args);
571 96 1;
572 };
573  
574 103 my $error = "$@";
575 103 $self->{callback_depth}--;
576 103 ▶ 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 102 103
Condition83%5/6
not $ok || $self->is_terminal and $name =~ /\Aon_(?:request|response|data|body|request_end|informational)\z/
!ll&&!rl&&r
10201
$ok || $self->is_terminal
l!l&&r!l&&!r
9661
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 103 ▶ $self->_notify_finish if $self->{finish_pending};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"finish_pending"} 4 99 103
584 103 ▶ return $ok ? 1 : $error;
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 96 7 103
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 66 ▶sub request_body {
Subroutine request_body: called CC=13 SCAR=26.7
Pod undocumented
641 66 my ($self, @args) = @_;
642  
643 66 ▶ if (my $body = $self->{request_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $body = $self->{"request_body"}) 38 28 66
644 38 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 1 37 38
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 38 return $body;
656 }
657  
658 28 ▶ croak 'request_body(): Transaction is already terminal'
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 28 28
659 if $self->is_terminal;
660  
661 my $connection = $self->{connection}
662 28 ▶ 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") 28 0 28
663  
664 28 ▶ if ($connection->role eq 'server') {
Branch: 1 branch
BranchTrueFalseTotal
if ($connection->role eq "server") 15 13 28
665 croak 'request_body(): request receive mode is buffered'
666 15 ▶ unless $self->{request_receive_mode} eq 'stream';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"request_receive_mode"} eq "stream" 0 15 15
667 15 ▶ croak 'request_body options must be key/value pairs'
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 15 15
668 if @args % 2;
669  
670 15 require Unblock::HTTP3::Body::Reader;
671  
672 my %option = (
673 15 ▶ %{ $self->{request_receive_options} || {} },
Condition50%1/2
$self->{'request_receive_options'} || {}
l!l
150
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 15 my $body = Unblock::HTTP3::Body::Reader->_new(
678 $self,
679 'request',
680 %option,
681 );
682  
683 15 $self->{request_body} = $body;
684 15 return $body;
685 }
686  
687 croak 'request_body(): Request is not configured for incremental body production'
688 13 ▶ unless $self->{request_streaming};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"request_streaming"} 0 13 13
689 13 ▶ croak 'request_body options must be key/value pairs'
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 13 13
690 if @args % 2;
691  
692 13 require Unblock::HTTP3::Body::Stream;
693  
694 13 my $body = Unblock::HTTP3::Body::Stream->_new(
695 $self,
696 'request',
697 @args,
698 );
699  
700 13 $self->{request_body} = $body;
701 13 return $body;
702 }
703  
704 61 ▶sub response_body {
Subroutine response_body: called CC=15 SCAR=30.9
Pod undocumented
705 61 my ($self, @args) = @_;
706  
707 61 ▶ if (my $body = $self->{response_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $body = $self->{"response_body"}) 39 22 61
708 39 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 0 39 39
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 39 return $body;
720 }
721  
722 22 ▶ croak 'response_body(): Transaction is already terminal'
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 22 22
723 if $self->is_terminal;
724  
725 my $connection = $self->{connection}
726 22 ▶ 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") 22 0 22
727  
728 22 ▶ if ($connection->role eq 'client') {
Branch: 1 branch
BranchTrueFalseTotal
if ($connection->role eq "client") 9 13 22
729 croak 'response_body(): response receive mode is buffered'
730 9 ▶ unless $self->{response_receive_mode} eq 'stream';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"response_receive_mode"} eq "stream" 0 9 9
731 9 ▶ croak 'response_body options must be key/value pairs'
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 9 9
732 if @args % 2;
733  
734 9 require Unblock::HTTP3::Body::Reader;
735  
736 my %option = (
737 9 ▶ %{ $self->{response_receive_options} || {} },
Condition50%1/2
$self->{'response_receive_options'} || {}
l!l
90
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 9 my $body = Unblock::HTTP3::Body::Reader->_new(
742 $self,
743 'response',
744 %option,
745 );
746  
747 9 $self->{response_body} = $body;
748 9 return $body;
749 }
750  
751 croak 'response_body(): response output has already started'
752 13 ▶ if $self->{response_output_started};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"response_output_started"} 0 13 13
753 13 ▶ croak 'response_body options must be key/value pairs'
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 13 13
754 if @args % 2;
755  
756 my $response = $self->{response}
757 13 ▶ or croak 'response_body(): Transaction has no Response';
Branch: 1 branch
BranchTrueFalseTotal
my $response = $self->{"response"} or croak("response_body(): Transaction has no Response") 13 0 13
758  
759 13 $connection->_assert_response_body_allowed(
760 $self,
761 $response,
762 'response_body()',
763 );
764  
765 9 $self->{response_streaming} = 1;
766 9 ▶ $response->mark_incomplete if $response->can('mark_incomplete');
Branch: 1 branch
BranchTrueFalseTotal
if $response->can("mark_incomplete") 9 0 9
767  
768 9 require Unblock::HTTP3::Body::Stream;
769  
770 9 my $body = Unblock::HTTP3::Body::Stream->_new(
771 $self,
772 'response',
773 @args,
774 );
775  
776 9 $self->{response_body} = $body;
777 9 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 74 ▶sub _configure_receive_body {
Subroutine _configure_receive_body: called CC=6 SCAR=19.0
866 74 my ($self, $kind, $mode, $options) = @_;
867  
868 74 ▶ croak "unsupported HTTP body receive kind '$kind'"
Branch: 1 branch
BranchTrueFalseTotal
if $kind ne "request" and $kind ne "response" 0 74 74
Condition66%2/3
$kind ne "request" and $kind ne "response"
!ll&&!rl&&r
37370
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 74 ▶ croak 'receive body mode must be buffered or stream'
Branch: 1 branch
BranchTrueFalseTotal
if $mode ne "buffered" and $mode ne "stream" 0 74 74
Condition66%2/3
$mode ne "buffered" and $mode ne "stream"
!ll&&!rl&&r
54200
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 74 ▶ croak 'receive body options must be a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $options eq "HASH" 0 74 74
873 unless ref($options) eq 'HASH';
874  
875 74 $self->{ $kind . '_receive_mode' } = $mode;
876 74 $self->{ $kind . '_receive_options' } = { %$options };
877  
878 74 return $self;
879 }
880  
881 108 ▶sub _ensure_receive_reader {
Subroutine _ensure_receive_reader: called CC=3 SCAR=11.0
882 108 my ($self, $kind) = @_;
883  
884 108 ▶ return unless $self->{ $kind . '_receive_mode' } eq 'stream';
Branch: 1 branch
BranchTrueFalseTotal
unless $$self{$kind . '_receive_mode'} eq "stream" 19 89 108
885  
886 89 ▶ return $kind eq 'request'
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'request' ? : 45 44 89
887 ? $self->request_body
888 : $self->response_body;
889 }
890  
891 190 ▶sub _incoming_body_reader {
Subroutine _incoming_body_reader: called CC=2 SCAR=6.9
892 190 my ($self, $kind) = @_;
893  
894 190 ▶ return unless $self->{ $kind . '_receive_mode' } eq 'stream';
Branch: 1 branch
BranchTrueFalseTotal
unless $$self{$kind . '_receive_mode'} eq "stream" 123 67 190
895  
896 67 return $self->_ensure_receive_reader($kind);
897 }
898  
899 34 ▶sub _consume_received_body {
Subroutine _consume_received_body: called CC=2 SCAR=7.0
900 34 my ($self, $kind, $amount) = @_;
901  
902 my $connection = $self->{connection}
903 34 ▶ 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") 34 0 34
904  
905 34 $connection->_consume_received_body(
906 $self,
907 $kind,
908 $amount,
909 );
910  
911 34 return;
912 }
913  
914 18 ▶sub _received_body_complete {
Subroutine _received_body_complete: called CC=5 SCAR=19.6
915 18 my ($self, $kind) = @_;
916  
917 18 $self->{receive_done} = 1;
918 $self->_invoke_request_end
919 if $kind eq 'request'
920 18 ▶ && $self->{request_receive_mode} eq 'stream';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "request" and $self->{"request_receive_mode"} eq "stream" 9 9 18
Condition66%2/3
$kind eq "request" and $self->{"request_receive_mode"} eq "stream"
!ll&&!rl&&r
909
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
921  
922 18 ▶ return if $self->{callback_depth};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"callback_depth"} 18 0 18
923 0 my $connection = $self->{connection};
924 $connection->_maybe_complete_transaction($self->{stream_id})
925 0 ▶ if defined $connection;
Branch: 1 branch
BranchTrueFalseTotal
if defined $connection 0 0 0
926  
927 0 return;
928 }
929  
930 1 ▶sub _capsule_protocol_error {
Subroutine _capsule_protocol_error: called CC=3 SCAR=11.6
931 1 my ($self, $error) = @_;
932  
933 1 ▶ return if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 1 1
934  
935 1 my $connection = $self->{connection};
936 1 ▶ if (defined $connection) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $connection) { } 1 0 1
937 1 $connection->_capsule_protocol_error(
938 $self,
939 $error,
940 );
941 } else {
942 0 $self->_mark_error($error);
943 }
944  
945 1 return;
946 }
947  
948 37 ▶sub _write_body {
Subroutine _write_body: called CC=10 SCAR=24.1
949 37 my ($self, $kind, $bytes, $final, $operation) = @_;
950  
951 37 ▶ croak "$operation(): Transaction is already terminal"
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 37 37
952 if $self->is_terminal;
953 37 ▶ croak "$operation(): unsupported HTTP body producer '$kind'"
Branch: 1 branch
BranchTrueFalseTotal
if $kind ne "request" and $kind ne "response" 0 37 37
Condition66%2/3
$kind ne "request" and $kind ne "response"
!ll&&!rl&&r
22150
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
954 if $kind ne 'request' && $kind ne 'response';
955  
956 my $message = $kind eq 'request'
957 ? $self->{request}
958 : ($self->{response}
959 37 ▶ or croak "$operation(): Transaction has no Response");
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'request' ? : 22 15 37
Condition33%1/3
$self->{"response"} or croak("$operation(): Transaction has no Response")
l!l&&r!l&&!r
1500
MC/DC0%0/2
$self->{"response"} or croak("$operation(): Transaction has no Response")
$self->{"response"} croak("$operation(): Transaction has no Response")
Truth table33%1/3
A or B
A= $self->{"response"}B= croak("$operation(): Transaction has no Response")
ABresult
1X1
011
000
960  
961 my $connection = $self->{connection}
962 37 ▶ 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") 37 0 37
963  
964 37 my ($can_continue, $ok, $error);
965  
966 {
967 37 local $@;
968 37 $ok = eval {
969 37 $can_continue = $connection->_write_transaction_body(
970 $self,
971 $kind,
972 $bytes,
973 $final,
974 $operation,
975 );
976 37 1;
977 };
978 37 $error = $@;
979 }
980  
981 37 ▶ die $error unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 37 37
982  
983 37 ▶ $message->mark_complete
Branch: 1 branch
BranchTrueFalseTotal
if $final and $message->can("mark_complete") 18 19 37
Condition66%2/3
$final and $message->can("mark_complete")
!ll&&!rl&&r
19018
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
984 if $final && $message->can('mark_complete');
985 37 return $can_continue;
986 }
987  
988 24 ▶sub _request_is_streaming {
Subroutine _request_is_streaming: called CC=2 SCAR=7.2
989 24 my ($self) = @_;
990 24 ▶ return $self->{request_streaming} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'request_streaming'} ? : 24 0 24
991 }
992  
993 56 ▶sub _response_is_streaming {
Subroutine _response_is_streaming: called CC=2 SCAR=6.9
994 56 my ($self) = @_;
995 56 ▶ return $self->{response_streaming} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'response_streaming'} ? : 28 28 56
996 }
997  
998 2 ▶sub _enable_response_streaming {
Subroutine _enable_response_streaming: called CC=2 SCAR=7.0
999 2 my ($self) = @_;
1000 2 $self->{response_streaming} = 1;
1001 2 ▶ $self->{response}->mark_incomplete if defined $self->{response};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"response"} 2 0 2
1002 2 return $self;
1003 }
1004  
1005 40 ▶sub _buffered_body_bytes {
Subroutine _buffered_body_bytes: called CC=4 SCAR=14.1
1006 40 my ($self, $kind) = @_;
1007 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
1008 if $kind ne 'request' && $kind ne 'response';
1009  
1010 40 ▶ return 0 unless $self->{ $kind . '_buffered_seen' };
Branch: 1 branch
BranchTrueFalseTotal
unless $$self{$kind . '_buffered_seen'} 30 10 40
1011  
1012 return $self->{ $kind . '_buffered_bytes' }
1013 10 + length($self->{ $kind . '_buffered_body' });
1014 }
1015  
1016 33 ▶sub _append_buffered_body {
Subroutine _append_buffered_body: called CC=5 SCAR=16.9
1017 33 my ($self, $kind, $bytes) = @_;
1018 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
1019 if $kind ne 'request' && $kind ne 'response';
1020  
1021 33 $self->{ $kind . '_buffered_seen' } = 1;
1022  
1023 33 my $length = length($bytes);
1024  
1025 33 ▶ if ($length < $BUFFERED_BODY_RETAIN_BYTES) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length < $BUFFERED_BODY_RETAIN_BYTES) 29 4 33
1026 29 $self->{ $kind . '_buffered_body' } .= $bytes;
1027 29 return;
1028 }
1029  
1030 4 my $body_name = $kind . '_buffered_body';
1031 4 my $chunks = $self->{ $kind . '_buffered_chunks' };
1032 4 my $bytes_name = $kind . '_buffered_bytes';
1033  
1034 4 ▶ if (length($self->{$body_name})) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{$body_name}) 0 4 4
1035 0 my $tail = $self->{$body_name};
1036  
1037 0 push @$chunks, $tail;
1038 0 $self->{$bytes_name} += length($tail);
1039 0 $self->{$body_name} = '';
1040 }
1041  
1042 4 push @$chunks, $bytes;
1043 4 $self->{$bytes_name} += $length;
1044 4 return;
1045 }
1046  
1047 44 ▶sub _finish_received_message {
Subroutine _finish_received_message: called CC=12 SCAR=26.3
1048 44 my ($self, $kind) = @_;
1049 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
1050 if $kind ne 'request' && $kind ne 'response';
1051  
1052 my $message = $kind eq 'request'
1053 ? $self->{request}
1054 44 ▶ : $self->{response};
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'request' ? : 22 22 44
1055  
1056 44 ▶ return unless defined $message;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $message 0 44 44
1057  
1058 44 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($$self{$kind . '_receive_mode'} eq 'buffered') { } 44 0 44
1059 $self->{ $kind . '_receive_mode' } eq 'buffered'
1060 ) {
1061 44 my $body_name = $kind . '_buffered_body';
1062 44 my $chunks = $self->{ $kind . '_buffered_chunks' };
1063 44 my $body;
1064  
1065 44 ▶ if (@$chunks) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$chunks) { } 1 43 44
1066 push @$chunks, $self->{$body_name}
1067 1 ▶ if length($self->{$body_name});
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{$body_name} 0 1 1
1068  
1069 1 ▶ $body = @$chunks == 1
Branch: 1 branch
BranchTrueFalseTotal
@$chunks == 1 ? : 0 1 1
1070 ? $chunks->[0]
1071 : join('', @$chunks);
1072 } else {
1073 43 $body = $self->{$body_name};
1074 }
1075  
1076 44 $self->{$body_name} = '';
1077 44 $self->{ $kind . '_buffered_chunks' } = [];
1078 44 $self->{ $kind . '_buffered_bytes' } = 0;
1079 44 $self->{ $kind . '_buffered_seen' } = 0;
1080  
1081 44 ▶ $message->body($body) if $message->body_is_mutable;
Branch: 1 branch
BranchTrueFalseTotal
if $message->body_is_mutable 44 0 44
1082 } else {
1083 0 $self->{ $kind . '_buffered_body' } = '';
1084 0 $self->{ $kind . '_buffered_chunks' } = [];
1085 0 $self->{ $kind . '_buffered_bytes' } = 0;
1086 0 $self->{ $kind . '_buffered_seen' } = 0;
1087 }
1088  
1089 44 $message->freeze_trailers;
1090 44 $message->freeze;
1091 44 $message->mark_complete;
1092  
1093 44 $self->{receive_done} = 1;
1094 $self->_invoke_request_end
1095 if $kind eq 'request'
1096 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
1097  
1098 44 return;
1099 }
1100  
1101 31 ▶sub _invoke_request_end {
Subroutine _invoke_request_end: called CC=4 SCAR=15.0
1102 31 my ($self) = @_;
1103  
1104 31 ▶ 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 31 31
Condition33%1/3
$self->is_terminal or $self->{"request_end_callback_called"}
l!l&&r!l&&!r
0031
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
1105 31 $self->{request_end_callback_called} = 1;
1106  
1107 my $result = $self->_invoke(
1108 'on_request_end',
1109 $self->{request},
1110 31 );
1111 31 ▶ die $result unless $result eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $result eq 1 0 31 31
1112  
1113 31 return;
1114 }
1115  
1116 79 ▶sub _discard_received_body_buffers {
Subroutine _discard_received_body_buffers: called CC=2 SCAR=6.9
1117 79 my ($self) = @_;
1118  
1119 79 for my $kind (qw(request response)) {
1120 158 $self->{ $kind . '_buffered_body' } = '';
1121 158 $self->{ $kind . '_buffered_chunks' } = [];
1122 158 $self->{ $kind . '_buffered_bytes' } = 0;
1123 158 $self->{ $kind . '_buffered_seen' } = 0;
1124 }
1125  
1126 79 return;
1127 }
1128  
1129 420 ▶sub _request_body_object {
Subroutine _request_body_object: called CC=1 SCAR=0.0
1130 420 my ($self) = @_;
1131 420 return $self->{request_body};
1132 }
1133  
1134 413 ▶sub _response_body_object {
Subroutine _response_body_object: called CC=1 SCAR=0.0
1135 413 my ($self) = @_;
1136 413 return $self->{response_body};
1137 }
1138  
1139 29 ▶sub _mark_response_started {
Subroutine _mark_response_started: called CC=1 SCAR=0.0
1140 29 my ($self) = @_;
1141 29 $self->{response_output_started} = 1;
1142 29 return $self;
1143 }
1144  
1145 2 ▶sub _push_informational {
Subroutine _push_informational: called CC=2 SCAR=7.0
1146 2 my ($self, $response) = @_;
1147  
1148 2 ▶ croak 'informational response must implement the Uniform HTTP response contract'
Branch: 1 branch
BranchTrueFalseTotal
unless _response_contract($response) 0 2 2
1149 unless _response_contract($response);
1150  
1151 2 push @{ $self->{informational} }, $response;
1152 2 return $response;
1153 }
1154  
1155 29 ▶sub _set_response {
Subroutine _set_response: called CC=4 SCAR=14.5
1156 29 my ($self, $response) = @_;
1157  
1158 29 ▶ croak 'cannot attach a response to a terminal Transaction'
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 29 29
1159 if $self->is_terminal;
1160 croak 'Transaction already has a response'
1161 29 ▶ if defined $self->{response};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"response"} 0 29 29
1162 29 ▶ croak 'Transaction response must implement the Uniform HTTP response contract'
Branch: 1 branch
BranchTrueFalseTotal
unless _response_contract($response) 0 29 29
1163 unless _response_contract($response);
1164  
1165 29 $self->{response} = $response;
1166 29 return $response;
1167 }
1168  
1169 # Commit the terminal state before body cancellation callbacks can re-enter.
1170 # Always release both bodies and notify observers even when a callback throws.
1171 79 ▶sub _terminal_cleanup {
Subroutine _terminal_cleanup: called CC=6 SCAR=18.4
1172 79 my ($self) = @_;
1173 79 my $error = '';
1174 79 for my $body ($self->{request_body}, $self->{response_body}) {
1175 158 ▶ next unless $body && !$body->is_complete;
Branch: 1 branch
BranchTrueFalseTotal
unless $body and not $body->is_complete 144 14 158
Condition100%3/3
$body and not $body->is_complete
!ll&&!rl&&r
1143014
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
1176 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
1177 }
1178 79 $self->_discard_datagrams;
1179 79 $self->_discard_received_body_buffers;
1180 79 return $error;
1181 }
1182  
1183 54 ▶sub _mark_complete {
Subroutine _mark_complete: called CC=4 SCAR=14.0
1184 54 my ($self) = @_;
1185 54 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 54 54
1186 54 $self->{state} = 'complete';
1187 54 my $error = $self->_terminal_cleanup;
1188 54 my $result = $self->_invoke('on_complete');
1189 54 $self->_notify_finish;
1190 54 ▶ die $error if length $error;
Branch: 1 branch
BranchTrueFalseTotal
if length $error 0 54 54
1191 54 ▶ die $result unless $result eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $result eq 1 1 53 54
1192 53 return $self;
1193 }
1194  
1195 16 ▶sub _mark_cancelled {
Subroutine _mark_cancelled: called CC=3 SCAR=11.2
1196 16 my ($self) = @_;
1197 16 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 16 16
1198 16 $self->{state} = 'cancelled';
1199 16 my $error = $self->_terminal_cleanup;
1200 16 $self->_notify_finish;
1201 16 ▶ die $error if length $error;
Branch: 1 branch
BranchTrueFalseTotal
if length $error 0 16 16
1202 16 return $self;
1203 }
1204  
1205 9 ▶sub _mark_error {
Subroutine _mark_error: called CC=5 SCAR=16.3
1206 9 my ($self, $error, $error_code) = @_;
1207 9 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 9 9
1208 9 $self->{state} = 'error';
1209 9 ▶ $self->{error} = defined($error) ? "$error" : 'HTTP/3 transaction failed';
Branch: 1 branch
BranchTrueFalseTotal
defined $error ? : 9 0 9
1210 9 my $cleanup_error = $self->_terminal_cleanup;
1211 9 my $result = $self->_invoke('on_error', $self->{error}, $error_code);
1212 9 $self->_notify_finish;
1213 9 ▶ die $cleanup_error if length $cleanup_error;
Branch: 1 branch
BranchTrueFalseTotal
if length $cleanup_error 0 9 9
1214 9 ▶ die $result unless $result eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $result eq 1 2 7 9
1215 7 return $self;
1216 }
1217  
1218 24 1;
1219  
1220 __END__
« blib/lib/Unblock/HTTP3/Capsule/Parser.pm ↑ Summary blib/lib/Unblock/HTTP3/_Native.pm »