blib/lib/Unblock/HTTP3/Transaction.pm

filter: Statementstmt 95.0% 484 / 509 Branchbran 62.1% 220 / 354 Conditioncond 56.1% 55 / 98 MC/DCmcdc 20.6% 12 / 58 Subroutinesub 97.5% 79 / 81 Podpod 0.0% 0 / 33 totaltotal 75.0% 850 / 1133 CC 217 SCAR 20.5
CC
217
Cov
79%
response_body
22.1
_set_callback
20.0
_new
18.1
CRAP 7.8
« blib/lib/Unblock/HTTP3/Capsule/Parser.pm ↑ Summary blib/lib/Unblock/HTTP3/_Native.pm »
1 package Unblock::HTTP3::Transaction;
2  
3 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 20 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 20 ▶use Scalar::Util qw(blessed weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 20 ▶use Uniform::HTTP::Request 0.06 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 20 ▶use Uniform::HTTP::Response 0.06 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 20 ▶use Unblock::HTTP3 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 20 ▶use Unblock::HTTP3::_Native ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 20 our $VERSION = '0.12';
16  
17 20 my %TERMINAL = map { $_ => 1 } qw(complete cancelled error);
18 20 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 79 ▶sub _parse_priority_field {
Subroutine _parse_priority_field: called CC=4 SCAR=13.9
64 79 my ($value) = @_;
65  
66 return {
67 79 ▶ urgency => 3,
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 75 4 79
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 76 ▶sub _request_contract {
Subroutine _request_contract: called CC=4 SCAR=14.3
87 76 my ($request) = @_;
88 76 ▶ return unless blessed($request);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($request) 0 76 76
89  
90 76 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 1064 ▶ return unless $request->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $request->can($method) 0 1064 1064
97 }
98  
99 76 return 1;
100 }
101  
102 72 ▶sub _response_contract {
Subroutine _response_contract: called CC=4 SCAR=14.3
103 72 my ($response) = @_;
104 72 ▶ return unless blessed($response);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($response) 0 72 72
105  
106 72 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 720 ▶ return unless $response->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $response->can($method) 0 720 720
113 }
114  
115 72 return 1;
116 }
117  
118 76 ▶sub _new {
Subroutine _new: called CC=14 SCAR=29.0
119 76 my ($class, %args) = @_;
120  
121 76 my $connection = delete $args{connection};
122 76 my $stream_id = delete $args{stream_id};
123 76 my $request = delete $args{request};
124 76 my $response = delete $args{response};
125 76 ▶ my $callbacks = delete($args{callbacks}) || {};
Condition100%2/2
delete $args{'callbacks'} || {}
l!l
5521
MC/DC100%1/1
delete $args{'callbacks'} || {}
delete $args{'callbacks'}
Truth table100%2/2
A
A= delete $args{'callbacks'}
Aresult
11
00
126 76 ▶ my $request_streaming = delete $args{request_streaming} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
delete $args{'request_streaming'} ? : 14 62 76
127 76 ▶ my $early_data = delete $args{early_data} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
delete $args{'early_data'} ? : 3 73 76
128  
129 76 ▶ croak 'Transaction requires a Unblock::HTTP3::Connection'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($connection) and $connection->isa("Unblock::HTTP3::Connection") 0 76 76
Condition33%1/3
builtin::blessed($connection) and $connection->isa("Unblock::HTTP3::Connection")
!ll&&!rl&&r
0076
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 76 ▶ 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 76 76
Condition33%2/6
defined $stream_id and not ref $stream_id and $stream_id =~ /\A[0-9]+\z/
!ll&&!rl&&r
0076
defined $stream_id and not ref $stream_id
!ll&&!rl&&r
0076
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 76 ▶ croak 'Transaction requires the Uniform HTTP request contract'
Branch: 1 branch
BranchTrueFalseTotal
unless _request_contract($request) 0 76 76
137 unless _request_contract($request);
138 76 ▶ croak 'Transaction response must implement the Uniform HTTP response contract'
Branch: 1 branch
BranchTrueFalseTotal
if defined $response and not _response_contract($response) 0 76 76
Condition66%2/3
defined $response and not _response_contract($response)
!ll&&!rl&&r
30460
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 76 ▶ croak 'Transaction callbacks must be a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $callbacks eq "HASH" 0 76 76
142 unless ref($callbacks) eq 'HASH';
143 76 ▶ croak 'unknown Transaction option: ' . join(', ', sort keys %args)
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 76 76
144 if %args;
145  
146 76 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 76 weaken($self->{connection});
188  
189 76 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 417 ▶sub stream_id {
Subroutine stream_id: called CC=2 SCAR=7.1
Pod undocumented
199 417 my ($self, @args) = @_;
200 417 ▶ croak 'stream_id() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 417 417
201 417 return $self->{stream_id};
202 }
203  
204 337 ▶sub request {
Subroutine request: called CC=2 SCAR=7.1
Pod undocumented
205 337 my ($self, @args) = @_;
206 337 ▶ croak 'request() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 337 337
207 337 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 246 ▶sub response {
Subroutine response: called CC=2 SCAR=7.1
Pod undocumented
223 246 my ($self, @args) = @_;
224 246 ▶ croak 'response() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 246 246
225 246 return $self->{response};
226 }
227  
228 1 ▶sub local_reset_code {
Subroutine local_reset_code: called CC=2 SCAR=7.1
Pod undocumented
229 1 my ($self, @args) = @_;
230 1 ▶ croak 'local_reset_code() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 1 1
231 1 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 3 ▶sub _mark_local_reset {
Subroutine _mark_local_reset: called CC=1 SCAR=0.0
265 3 my ($self, $code) = @_;
266 3 $self->{local_reset_code} = 0 + $code;
267 3 return $self;
268 }
269  
270 2 ▶sub _mark_remote_reset {
Subroutine _mark_remote_reset: called CC=1 SCAR=0.0
271 2 my ($self, $code) = @_;
272 2 $self->{remote_reset_code} = 0 + $code;
273 2 return $self;
274 }
275  
276 2 ▶sub _mark_local_stop_sending {
Subroutine _mark_local_stop_sending: called CC=1 SCAR=0.0
277 2 my ($self, $code) = @_;
278 2 $self->{local_stop_sending_code} = 0 + $code;
279 2 return $self;
280 }
281  
282 2 ▶sub _mark_remote_stop_sending {
Subroutine _mark_remote_stop_sending: called CC=1 SCAR=0.0
283 2 my ($self, $code) = @_;
284 2 $self->{remote_stop_sending_code} = 0 + $code;
285 2 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 55 ▶sub _discard_datagrams {
Subroutine _discard_datagrams: called CC=3 SCAR=11.0
443 55 my ($self) = @_;
444  
445 55 my $connection = $self->{connection};
446  
447 55 ▶ if (defined $connection) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $connection) 53 2 55
448 53 for my $bytes (@{ $self->{datagram_queue} }) {
449 0 $connection->_datagram_dequeued(length($bytes));
450 }
451 }
452  
453 55 $self->{datagram_queue} = [];
454 55 $self->{datagram_callback} = undef;
455 55 return;
456 }
457  
458 8 ▶sub state {
Subroutine state: called CC=2 SCAR=7.1
Pod undocumented
459 8 my ($self, @args) = @_;
460 8 ▶ croak 'state() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 8 8
461 8 return $self->{state};
462 }
463  
464 3 ▶sub error {
Subroutine error: called CC=2 SCAR=7.1
Pod undocumented
465 3 my ($self, @args) = @_;
466 3 ▶ croak 'error() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 3 3
467 3 return $self->{error};
468 }
469  
470 101 ▶sub is_complete {
Subroutine is_complete: called CC=3 SCAR=11.1
Pod undocumented
471 101 my ($self, @args) = @_;
472 101 ▶ croak 'is_complete() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 101 101
473 101 ▶ return $self->{state} eq 'complete' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'state'} eq 'complete' ? : 48 53 101
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 0 ▶sub is_error {
Subroutine is_error: not called CC=3 SCAR=24.8
Pod undocumented
483 0 my ($self, @args) = @_;
484 0 ▶ croak 'is_error() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 0 0
485 0 ▶ return $self->{state} eq 'error' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'state'} eq 'error' ? : 0 0 0
486 }
487  
488 918 ▶sub is_terminal {
Subroutine is_terminal: called CC=3 SCAR=11.1
Pod undocumented
489 918 my ($self, @args) = @_;
490 918 ▶ croak 'is_terminal() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 918 918
491 918 ▶ return $TERMINAL{ $self->{state} } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$TERMINAL{$self->{'state'}} ? : 241 677 918
492 }
493  
494 0 ▶sub _set_callback {
Subroutine _set_callback: not called CC=4 SCAR=30.0
495 0 my ($self, $name, $callback) = @_;
496  
497 0 ▶ croak "_set_callback(): callback must be a code reference or undef"
Branch: 1 branch
BranchTrueFalseTotal
if defined $callback and ref $callback ne "CODE" 0 0 0
Condition0%0/3
defined $callback and ref $callback ne "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $callback and ref $callback ne "CODE"
defined $callback ref $callback ne "CODE"
Truth table0%0/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 0 ▶ if (defined $callback) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $callback) { } 0 0 0
501 0 $self->{callbacks}{$name} = $callback;
502 } else {
503 0 delete $self->{callbacks}{$name};
504 }
505  
506 0 return $self;
507 }
508  
509 125 ▶sub _invoke {
Subroutine _invoke: called CC=3 SCAR=11.0
510 125 my ($self, $name, @args) = @_;
511  
512 125 ▶ my $callback = $self->{callbacks}{$name} or return 1;
Branch: 1 branch
BranchTrueFalseTotal
my $callback = $self->{"callbacks"}{$name} or return 1 52 73 125
513  
514 52 my $ok = eval {
515 52 $callback->($self, @args);
516 52 1;
517 };
518  
519 52 ▶ return $ok ? 1 : $@;
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 52 0 52
520 }
521  
522 1 ▶sub next_informational {
Subroutine next_informational: called CC=2 SCAR=7.0
Pod undocumented
523 1 my ($self, @args) = @_;
524  
525 1 ▶ croak 'next_informational() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 1 1
526 1 return shift @{ $self->{informational} };
527 }
528  
529 7 ▶sub send_informational {
Subroutine send_informational: called CC=12 SCAR=25.8
Pod undocumented
530 7 my ($self, @arg) = @_;
531  
532 7 my $response;
533 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
534 3 ▶ croak 'send_informational(): response object does not take options'
Branch: 1 branch
BranchTrueFalseTotal
unless @arg == 1 1 2 3
535 unless @arg == 1;
536 2 $response = $arg[0];
537 } else {
538 4 ▶ croak 'send_informational(): fields must be key/value pairs'
Branch: 1 branch
BranchTrueFalseTotal
if @arg % 2 1 3 4
539 if @arg % 2;
540 3 $response = Uniform::HTTP::Response->new(@arg);
541 }
542  
543 5 ▶ croak 'send_informational(): Transaction is already terminal'
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 5 5
544 if $self->is_terminal;
545 my $connection = $self->{connection}
546 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
547  
548 5 $connection->_assert_response_contract(
549 $response,
550 'send_informational()',
551 );
552 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
553 unless $response->status >= 100
554 && $response->status <= 199
555 && $response->status != 101;
556 4 ▶ croak 'send_informational(): informational responses cannot have a body'
Branch: 1 branch
BranchTrueFalseTotal
if $response->has_buffered_body 0 4 4
557 if $response->has_buffered_body;
558 4 ▶ croak 'send_informational(): informational responses cannot have trailers'
Branch: 1 branch
BranchTrueFalseTotal
if $response->has_trailers 0 4 4
559 if $response->has_trailers;
560  
561 4 $connection->_send_informational_response(
562 $self,
563 $response,
564 );
565  
566 4 return $self;
567 }
568  
569 2 ▶sub is_response_started {
Subroutine is_response_started: called CC=3 SCAR=11.7
Pod undocumented
570 2 my ($self, @args) = @_;
571 2 ▶ croak 'is_response_started() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 2 2
572 2 ▶ return $self->{response_output_started} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'response_output_started'} ? : 2 0 2
573 }
574  
575 54 ▶sub request_body {
Subroutine request_body: called CC=13 SCAR=26.7
Pod undocumented
576 54 my ($self, @args) = @_;
577  
578 54 ▶ if (my $body = $self->{request_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $body = $self->{"request_body"}) 33 21 54
579 33 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 1 32 33
580 1 ▶ croak 'request_body options must be key/value pairs'
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 1 1
581 if @args % 2;
582  
583 1 ▶ if ($body->can('_configure')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($body->can('_configure')) { } 1 0 1
584 1 $body->_configure(@args);
585 } else {
586 0 croak 'request_body options may only be supplied when the producer is created';
587 }
588 }
589  
590 33 return $body;
591 }
592  
593 21 ▶ croak 'request_body(): Transaction is already terminal'
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 21 21
594 if $self->is_terminal;
595  
596 my $connection = $self->{connection}
597 21 ▶ 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") 21 0 21
598  
599 21 ▶ if ($connection->role eq 'server') {
Branch: 1 branch
BranchTrueFalseTotal
if ($connection->role eq "server") 9 12 21
600 croak 'request_body(): request receive mode is buffered'
601 9 ▶ unless $self->{request_receive_mode} eq 'stream';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"request_receive_mode"} eq "stream" 0 9 9
602 9 ▶ croak 'request_body options must be key/value pairs'
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 9 9
603 if @args % 2;
604  
605 9 require Unblock::HTTP3::Body::Reader;
606  
607 my %option = (
608 9 ▶ %{ $self->{request_receive_options} || {} },
Condition50%1/2
$self->{'request_receive_options'} || {}
l!l
90
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
609 @args,
610 );
611  
612 9 my $body = Unblock::HTTP3::Body::Reader->_new(
613 $self,
614 'request',
615 %option,
616 );
617  
618 9 $self->{request_body} = $body;
619 9 return $body;
620 }
621  
622 croak 'request_body(): Request is not configured for incremental body production'
623 12 ▶ unless $self->{request_streaming};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"request_streaming"} 0 12 12
624 12 ▶ croak 'request_body options must be key/value pairs'
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 12 12
625 if @args % 2;
626  
627 12 require Unblock::HTTP3::Body::Stream;
628  
629 12 my $body = Unblock::HTTP3::Body::Stream->_new(
630 $self,
631 'request',
632 @args,
633 );
634  
635 12 $self->{request_body} = $body;
636 12 return $body;
637 }
638  
639 57 ▶sub response_body {
Subroutine response_body: called CC=15 SCAR=30.9
Pod undocumented
640 57 my ($self, @args) = @_;
641  
642 57 ▶ if (my $body = $self->{response_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $body = $self->{"response_body"}) 36 21 57
643 36 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 0 36 36
644 0 ▶ croak 'response_body options must be key/value pairs'
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 0 0
645 if @args % 2;
646  
647 0 ▶ if ($body->can('_configure')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($body->can('_configure')) { } 0 0 0
648 0 $body->_configure(@args);
649 } else {
650 0 croak 'response_body options may only be supplied when the producer is created';
651 }
652 }
653  
654 36 return $body;
655 }
656  
657 21 ▶ croak 'response_body(): Transaction is already terminal'
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 21 21
658 if $self->is_terminal;
659  
660 my $connection = $self->{connection}
661 21 ▶ 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") 21 0 21
662  
663 21 ▶ if ($connection->role eq 'client') {
Branch: 1 branch
BranchTrueFalseTotal
if ($connection->role eq "client") 8 13 21
664 croak 'response_body(): response receive mode is buffered'
665 8 ▶ unless $self->{response_receive_mode} eq 'stream';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"response_receive_mode"} eq "stream" 0 8 8
666 8 ▶ croak 'response_body options must be key/value pairs'
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 8 8
667 if @args % 2;
668  
669 8 require Unblock::HTTP3::Body::Reader;
670  
671 my %option = (
672 8 ▶ %{ $self->{response_receive_options} || {} },
Condition50%1/2
$self->{'response_receive_options'} || {}
l!l
80
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
673 @args,
674 );
675  
676 8 my $body = Unblock::HTTP3::Body::Reader->_new(
677 $self,
678 'response',
679 %option,
680 );
681  
682 8 $self->{response_body} = $body;
683 8 return $body;
684 }
685  
686 croak 'response_body(): response output has already started'
687 13 ▶ if $self->{response_output_started};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"response_output_started"} 0 13 13
688 13 ▶ croak 'response_body options must be key/value pairs'
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 13 13
689 if @args % 2;
690  
691 my $response = $self->{response}
692 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
693  
694 13 $connection->_assert_response_body_allowed(
695 $self,
696 $response,
697 'response_body()',
698 );
699  
700 9 $self->{response_streaming} = 1;
701 9 ▶ $response->mark_incomplete if $response->can('mark_incomplete');
Branch: 1 branch
BranchTrueFalseTotal
if $response->can("mark_incomplete") 9 0 9
702  
703 9 require Unblock::HTTP3::Body::Stream;
704  
705 9 my $body = Unblock::HTTP3::Body::Stream->_new(
706 $self,
707 'response',
708 @args,
709 );
710  
711 9 $self->{response_body} = $body;
712 9 return $body;
713 }
714  
715 30 ▶sub respond {
Subroutine respond: called CC=9 SCAR=22.2
Pod undocumented
716 30 my ($self, @arg) = @_;
717  
718 30 my ($response, %option);
719 30 ▶ if (@arg && ref($arg[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (@arg and ref $arg[0]) { } 26 4 30
Condition66%2/3
@arg and ref $arg[0]
!ll&&!rl&&r
0426
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
720 26 $response = shift @arg;
721 26 ▶ croak 'respond(): options must be key/value pairs' if @arg % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @arg % 2 0 26 26
722 26 %option = @arg;
723 } else {
724 4 ▶ croak 'respond(): fields must be key/value pairs' if @arg % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @arg % 2 1 3 4
725 3 my %field = @arg;
726 3 for my $name (qw(stream_body on_drain on_error)) {
727 9 ▶ $option{$name} = delete $field{$name} if exists $field{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $field{$name} 3 6 9
728 }
729 3 $response = Uniform::HTTP::Response->new(%field);
730 }
731  
732 29 ▶ croak 'respond(): Transaction is already terminal'
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 29 29
733 if $self->is_terminal;
734  
735 my $connection = $self->{connection}
736 29 ▶ 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") 29 0 29
737  
738 29 $connection->_respond_transaction(
739 $self,
740 $response,
741 %option,
742 );
743  
744 20 return $self;
745 }
746  
747 1 ▶sub write {
Subroutine write: called CC=3 SCAR=11.4
Pod undocumented
748 1 my ($self, $bytes) = @_;
749  
750 1 ▶ croak 'write(): Transaction is already terminal'
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 1 1
751 if $self->is_terminal;
752  
753 my $connection = $self->{connection}
754 1 ▶ 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") 1 0 1
755  
756 1 return $connection->_write_stream_body(
757 $self,
758 $bytes,
759 0,
760 'write',
761 );
762 }
763  
764 1 ▶sub end {
Subroutine end: called CC=5 SCAR=17.0
Pod undocumented
765 1 my ($self, @args) = @_;
766  
767 1 ▶ croak 'end(): accepts at most one final byte string'
Branch: 1 branch
BranchTrueFalseTotal
if @args > 1 0 1 1
768 if @args > 1;
769 1 ▶ croak 'end(): Transaction is already terminal'
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 1 1
770 if $self->is_terminal;
771  
772 my $connection = $self->{connection}
773 1 ▶ 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") 1 0 1
774  
775 1 ▶ my $bytes = @args ? $args[0] : '';
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 1 0 1
776 1 $connection->_write_stream_body(
777 $self,
778 $bytes,
779 1,
780 'end',
781 );
782  
783 1 return $self;
784 }
785  
786 1 ▶sub cancel {
Subroutine cancel: called CC=4 SCAR=15.0
Pod undocumented
787 1 my ($self) = @_;
788  
789 1 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 1 1
790  
791 1 my $connection = $self->{connection};
792 1 ▶ if (defined $connection) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $connection) 1 0 1
793 1 $connection->_cancel_transaction($self);
794 }
795  
796 1 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 1 0 1
797 0 return $self->_mark_cancelled;
798 }
799  
800 55 ▶sub _configure_receive_body {
Subroutine _configure_receive_body: called CC=6 SCAR=19.0
801 55 my ($self, $kind, $mode, $options) = @_;
802  
803 55 ▶ croak "unsupported HTTP body receive kind '$kind'"
Branch: 1 branch
BranchTrueFalseTotal
if $kind ne "request" and $kind ne "response" 0 55 55
Condition66%2/3
$kind ne "request" and $kind ne "response"
!ll&&!rl&&r
27280
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
804 if $kind ne 'request' && $kind ne 'response';
805 55 ▶ croak 'receive body mode must be buffered or stream'
Branch: 1 branch
BranchTrueFalseTotal
if $mode ne "buffered" and $mode ne "stream" 0 55 55
Condition66%2/3
$mode ne "buffered" and $mode ne "stream"
!ll&&!rl&&r
36190
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
806 if $mode ne 'buffered' && $mode ne 'stream';
807 55 ▶ croak 'receive body options must be a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $options eq "HASH" 0 55 55
808 unless ref($options) eq 'HASH';
809  
810 55 $self->{ $kind . '_receive_mode' } = $mode;
811 55 $self->{ $kind . '_receive_options' } = { %$options };
812  
813 55 return $self;
814 }
815  
816 91 ▶sub _ensure_receive_reader {
Subroutine _ensure_receive_reader: called CC=3 SCAR=11.0
817 91 my ($self, $kind) = @_;
818  
819 91 ▶ return unless $self->{ $kind . '_receive_mode' } eq 'stream';
Branch: 1 branch
BranchTrueFalseTotal
unless $$self{$kind . '_receive_mode'} eq "stream" 16 75 91
820  
821 75 ▶ return $kind eq 'request'
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'request' ? : 35 40 75
822 ? $self->request_body
823 : $self->response_body;
824 }
825  
826 157 ▶sub _incoming_body_reader {
Subroutine _incoming_body_reader: called CC=2 SCAR=6.9
827 157 my ($self, $kind) = @_;
828  
829 157 ▶ return unless $self->{ $kind . '_receive_mode' } eq 'stream';
Branch: 1 branch
BranchTrueFalseTotal
unless $$self{$kind . '_receive_mode'} eq "stream" 99 58 157
830  
831 58 return $self->_ensure_receive_reader($kind);
832 }
833  
834 26 ▶sub _consume_received_body {
Subroutine _consume_received_body: called CC=2 SCAR=7.0
835 26 my ($self, $kind, $amount) = @_;
836  
837 my $connection = $self->{connection}
838 26 ▶ 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") 26 0 26
839  
840 26 $connection->_consume_received_body(
841 $self,
842 $kind,
843 $amount,
844 );
845  
846 26 return;
847 }
848  
849 15 ▶sub _received_body_complete {
Subroutine _received_body_complete: called CC=4 SCAR=14.0
850 15 my ($self, $kind) = @_;
851  
852 $self->_invoke_request_end
853 if $kind eq 'request'
854 15 ▶ && $self->{request_receive_mode} eq 'stream';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "request" and $self->{"request_receive_mode"} eq "stream" 7 8 15
Condition66%2/3
$kind eq "request" and $self->{"request_receive_mode"} eq "stream"
!ll&&!rl&&r
807
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
855  
856 15 my $connection = $self->{connection};
857 $connection->_maybe_complete_transaction($self->{stream_id})
858 15 ▶ if defined $connection;
Branch: 1 branch
BranchTrueFalseTotal
if defined $connection 15 0 15
859  
860 15 return;
861 }
862  
863 1 ▶sub _capsule_protocol_error {
Subroutine _capsule_protocol_error: called CC=3 SCAR=11.6
864 1 my ($self, $error) = @_;
865  
866 1 ▶ return if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 1 1
867  
868 1 my $connection = $self->{connection};
869 1 ▶ if (defined $connection) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $connection) { } 1 0 1
870 1 $connection->_capsule_protocol_error(
871 $self,
872 $error,
873 );
874 } else {
875 0 $self->_mark_error($error);
876 }
877  
878 1 return;
879 }
880  
881 35 ▶sub _write_body {
Subroutine _write_body: called CC=10 SCAR=24.1
882 35 my ($self, $kind, $bytes, $final, $operation) = @_;
883  
884 35 ▶ croak "$operation(): Transaction is already terminal"
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 35 35
885 if $self->is_terminal;
886 35 ▶ croak "$operation(): unsupported HTTP body producer '$kind'"
Branch: 1 branch
BranchTrueFalseTotal
if $kind ne "request" and $kind ne "response" 0 35 35
Condition66%2/3
$kind ne "request" and $kind ne "response"
!ll&&!rl&&r
20150
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
887 if $kind ne 'request' && $kind ne 'response';
888  
889 my $message = $kind eq 'request'
890 ? $self->{request}
891 : ($self->{response}
892 35 ▶ or croak "$operation(): Transaction has no Response");
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'request' ? : 20 15 35
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
893  
894 my $connection = $self->{connection}
895 35 ▶ 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") 35 0 35
896  
897 35 my ($can_continue, $ok, $error);
898  
899 {
900 35 local $@;
901 35 $ok = eval {
902 35 $can_continue = $connection->_write_transaction_body(
903 $self,
904 $kind,
905 $bytes,
906 $final,
907 $operation,
908 );
909 35 1;
910 };
911 35 $error = $@;
912 }
913  
914 35 ▶ die $error unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 35 35
915  
916 35 ▶ $message->mark_complete
Branch: 1 branch
BranchTrueFalseTotal
if $final and $message->can("mark_complete") 17 18 35
Condition66%2/3
$final and $message->can("mark_complete")
!ll&&!rl&&r
18017
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
917 if $final && $message->can('mark_complete');
918 35 return $can_continue;
919 }
920  
921 20 ▶sub _request_is_streaming {
Subroutine _request_is_streaming: called CC=2 SCAR=7.2
922 20 my ($self) = @_;
923 20 ▶ return $self->{request_streaming} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'request_streaming'} ? : 20 0 20
924 }
925  
926 51 ▶sub _response_is_streaming {
Subroutine _response_is_streaming: called CC=2 SCAR=6.9
927 51 my ($self) = @_;
928 51 ▶ return $self->{response_streaming} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'response_streaming'} ? : 28 23 51
929 }
930  
931 2 ▶sub _enable_response_streaming {
Subroutine _enable_response_streaming: called CC=2 SCAR=7.0
932 2 my ($self) = @_;
933 2 $self->{response_streaming} = 1;
934 2 ▶ $self->{response}->mark_incomplete if defined $self->{response};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"response"} 2 0 2
935 2 return $self;
936 }
937  
938 25 ▶sub _buffered_body_bytes {
Subroutine _buffered_body_bytes: called CC=4 SCAR=14.1
939 25 my ($self, $kind) = @_;
940 25 ▶ croak "unsupported buffered body kind '$kind'"
Branch: 1 branch
BranchTrueFalseTotal
if $kind ne "request" and $kind ne "response" 0 25 25
Condition66%2/3
$kind ne "request" and $kind ne "response"
!ll&&!rl&&r
11140
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
941 if $kind ne 'request' && $kind ne 'response';
942  
943 25 ▶ return 0 unless $self->{ $kind . '_buffered_seen' };
Branch: 1 branch
BranchTrueFalseTotal
unless $$self{$kind . '_buffered_seen'} 17 8 25
944  
945 return $self->{ $kind . '_buffered_bytes' }
946 8 + length($self->{ $kind . '_buffered_body' });
947 }
948  
949 25 ▶sub _append_buffered_body {
Subroutine _append_buffered_body: called CC=5 SCAR=16.9
950 25 my ($self, $kind, $bytes) = @_;
951 25 ▶ croak "unsupported buffered body kind '$kind'"
Branch: 1 branch
BranchTrueFalseTotal
if $kind ne "request" and $kind ne "response" 0 25 25
Condition66%2/3
$kind ne "request" and $kind ne "response"
!ll&&!rl&&r
9160
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
952 if $kind ne 'request' && $kind ne 'response';
953  
954 25 $self->{ $kind . '_buffered_seen' } = 1;
955  
956 25 my $length = length($bytes);
957  
958 25 ▶ if ($length < $BUFFERED_BODY_RETAIN_BYTES) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length < $BUFFERED_BODY_RETAIN_BYTES) 21 4 25
959 21 $self->{ $kind . '_buffered_body' } .= $bytes;
960 21 return;
961 }
962  
963 4 my $body_name = $kind . '_buffered_body';
964 4 my $chunks = $self->{ $kind . '_buffered_chunks' };
965 4 my $bytes_name = $kind . '_buffered_bytes';
966  
967 4 ▶ if (length($self->{$body_name})) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{$body_name}) 0 4 4
968 0 my $tail = $self->{$body_name};
969  
970 0 push @$chunks, $tail;
971 0 $self->{$bytes_name} += length($tail);
972 0 $self->{$body_name} = '';
973 }
974  
975 4 push @$chunks, $bytes;
976 4 $self->{$bytes_name} += $length;
977 4 return;
978 }
979  
980 36 ▶sub _finish_received_message {
Subroutine _finish_received_message: called CC=12 SCAR=25.2
981 36 my ($self, $kind) = @_;
982 36 ▶ croak "unsupported received message kind '$kind'"
Branch: 1 branch
BranchTrueFalseTotal
if $kind ne "request" and $kind ne "response" 0 36 36
Condition66%2/3
$kind ne "request" and $kind ne "response"
!ll&&!rl&&r
17190
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
983 if $kind ne 'request' && $kind ne 'response';
984  
985 my $message = $kind eq 'request'
986 ? $self->{request}
987 36 ▶ : $self->{response};
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'request' ? : 17 19 36
988  
989 36 ▶ return unless defined $message;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $message 0 36 36
990  
991 36 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($$self{$kind . '_receive_mode'} eq 'buffered' and $$self{$kind . '_buffered_seen'}) { } 16 20 36
Condition66%2/3
$$self{$kind . '_receive_mode'} eq "buffered" and $$self{$kind . '_buffered_seen'}
!ll&&!rl&&r
02016
MC/DC50%1/2
$$self{$kind . '_receive_mode'} eq "buffered" and $$self{$kind . '_buffered_seen'}
$$self{$kind . '_receive_mode'} eq "buffered" $$self{$kind . '_buffered_seen'}
Truth table66%2/3
A and B
A= $$self{$kind . '_receive_mode'} eq "buffered"B= $$self{$kind . '_buffered_seen'}
ABresult
0X0
100
111
992 $self->{ $kind . '_receive_mode' } eq 'buffered'
993 && $self->{ $kind . '_buffered_seen' }
994 ) {
995 16 my $body_name = $kind . '_buffered_body';
996 16 my $chunks = $self->{ $kind . '_buffered_chunks' };
997 16 my $body;
998  
999 16 ▶ if (@$chunks) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$chunks) { } 1 15 16
1000 push @$chunks, $self->{$body_name}
1001 1 ▶ if length($self->{$body_name});
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{$body_name} 0 1 1
1002  
1003 1 ▶ $body = @$chunks == 1
Branch: 1 branch
BranchTrueFalseTotal
@$chunks == 1 ? : 0 1 1
1004 ? $chunks->[0]
1005 : join('', @$chunks);
1006 } else {
1007 15 $body = $self->{$body_name};
1008 }
1009  
1010 16 $self->{$body_name} = '';
1011 16 $self->{ $kind . '_buffered_chunks' } = [];
1012 16 $self->{ $kind . '_buffered_bytes' } = 0;
1013 16 $self->{ $kind . '_buffered_seen' } = 0;
1014  
1015 16 $message->body($body);
1016 } else {
1017 20 $self->{ $kind . '_buffered_body' } = '';
1018 20 $self->{ $kind . '_buffered_chunks' } = [];
1019 20 $self->{ $kind . '_buffered_bytes' } = 0;
1020 20 $self->{ $kind . '_buffered_seen' } = 0;
1021 }
1022  
1023 36 $message->freeze_trailers;
1024 36 $message->freeze;
1025 36 $message->mark_complete;
1026  
1027 $self->_invoke_request_end
1028 if $kind eq 'request'
1029 36 ▶ && $self->{request_receive_mode} eq 'buffered';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "request" and $self->{"request_receive_mode"} eq "buffered" 17 19 36
Condition66%2/3
$kind eq "request" and $self->{"request_receive_mode"} eq "buffered"
!ll&&!rl&&r
19017
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
1030  
1031 36 return;
1032 }
1033  
1034 24 ▶sub _invoke_request_end {
Subroutine _invoke_request_end: called CC=3 SCAR=11.2
1035 24 my ($self) = @_;
1036  
1037 24 ▶ return if $self->{request_end_callback_called};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"request_end_callback_called"} 0 24 24
1038 24 $self->{request_end_callback_called} = 1;
1039  
1040 my $result = $self->_invoke(
1041 'on_request_end',
1042 $self->{request},
1043 24 );
1044 24 ▶ die $result unless $result eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $result eq 1 0 24 24
1045  
1046 24 return;
1047 }
1048  
1049 55 ▶sub _discard_received_body_buffers {
Subroutine _discard_received_body_buffers: called CC=2 SCAR=6.9
1050 55 my ($self) = @_;
1051  
1052 55 for my $kind (qw(request response)) {
1053 110 $self->{ $kind . '_buffered_body' } = '';
1054 110 $self->{ $kind . '_buffered_chunks' } = [];
1055 110 $self->{ $kind . '_buffered_bytes' } = 0;
1056 110 $self->{ $kind . '_buffered_seen' } = 0;
1057 }
1058  
1059 55 return;
1060 }
1061  
1062 293 ▶sub _request_body_object {
Subroutine _request_body_object: called CC=1 SCAR=0.0
1063 293 my ($self) = @_;
1064 293 return $self->{request_body};
1065 }
1066  
1067 286 ▶sub _response_body_object {
Subroutine _response_body_object: called CC=1 SCAR=0.0
1068 286 my ($self) = @_;
1069 286 return $self->{response_body};
1070 }
1071  
1072 24 ▶sub _mark_response_started {
Subroutine _mark_response_started: called CC=1 SCAR=0.0
1073 24 my ($self) = @_;
1074 24 $self->{response_output_started} = 1;
1075 24 return $self;
1076 }
1077  
1078 55 ▶sub _cancel_body_producers {
Subroutine _cancel_body_producers: called CC=5 SCAR=16.1
1079 55 my ($self) = @_;
1080  
1081 55 ▶ if (my $body = $self->{request_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $body = $self->{"request_body"}) 20 35 55
1082 20 ▶ $body->_cancel unless $body->is_complete;
Branch: 1 branch
BranchTrueFalseTotal
unless $body->is_complete 2 18 20
1083 }
1084  
1085 55 ▶ if (my $body = $self->{response_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $body = $self->{"response_body"}) 16 39 55
1086 16 ▶ $body->_cancel unless $body->is_complete;
Branch: 1 branch
BranchTrueFalseTotal
unless $body->is_complete 8 8 16
1087 }
1088  
1089 55 return;
1090 }
1091  
1092 2 ▶sub _push_informational {
Subroutine _push_informational: called CC=2 SCAR=7.0
1093 2 my ($self, $response) = @_;
1094  
1095 2 ▶ croak 'informational response must implement the Uniform HTTP response contract'
Branch: 1 branch
BranchTrueFalseTotal
unless _response_contract($response) 0 2 2
1096 unless _response_contract($response);
1097  
1098 2 push @{ $self->{informational} }, $response;
1099 2 return $response;
1100 }
1101  
1102 24 ▶sub _set_response {
Subroutine _set_response: called CC=4 SCAR=14.5
1103 24 my ($self, $response) = @_;
1104  
1105 24 ▶ croak 'cannot attach a response to a terminal Transaction'
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 24 24
1106 if $self->is_terminal;
1107 croak 'Transaction already has a response'
1108 24 ▶ if defined $self->{response};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"response"} 0 24 24
1109 24 ▶ croak 'Transaction response must implement the Uniform HTTP response contract'
Branch: 1 branch
BranchTrueFalseTotal
unless _response_contract($response) 0 24 24
1110 unless _response_contract($response);
1111  
1112 24 $self->{response} = $response;
1113 24 return $response;
1114 }
1115  
1116 44 ▶sub _mark_complete {
Subroutine _mark_complete: called CC=3 SCAR=11.1
1117 44 my ($self) = @_;
1118 44 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 44 44
1119  
1120 44 $self->_cancel_body_producers;
1121 44 $self->_discard_datagrams;
1122 44 $self->_discard_received_body_buffers;
1123 44 $self->{state} = 'complete';
1124  
1125 44 my $result = $self->_invoke('on_complete');
1126 44 ▶ die $result unless $result eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $result eq 1 0 44 44
1127  
1128 44 return $self;
1129 }
1130  
1131 5 ▶sub _mark_cancelled {
Subroutine _mark_cancelled: called CC=2 SCAR=7.0
1132 5 my ($self) = @_;
1133 5 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 5 5
1134  
1135 5 $self->_cancel_body_producers;
1136 5 $self->_discard_datagrams;
1137 5 $self->_discard_received_body_buffers;
1138 5 $self->{state} = 'cancelled';
1139  
1140 5 return $self;
1141 }
1142  
1143 6 ▶sub _mark_error {
Subroutine _mark_error: called CC=4 SCAR=14.1
1144 6 my ($self, $error, $error_code) = @_;
1145 6 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 6 6
1146  
1147 6 $self->_cancel_body_producers;
1148 6 $self->_discard_datagrams;
1149 6 $self->_discard_received_body_buffers;
1150 6 $self->{state} = 'error';
1151 6 ▶ $self->{error} = defined($error) ? "$error" : 'HTTP/3 transaction failed';
Branch: 1 branch
BranchTrueFalseTotal
defined $error ? : 6 0 6
1152  
1153 my $result = $self->_invoke(
1154 'on_error',
1155 $self->{error},
1156 6 $error_code,
1157 );
1158 6 ▶ die $result unless $result eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $result eq 1 0 6 6
1159  
1160 6 return $self;
1161 }
1162  
1163 20 1;
1164  
1165 __END__
« blib/lib/Unblock/HTTP3/Capsule/Parser.pm ↑ Summary blib/lib/Unblock/HTTP3/_Native.pm »