HTTP/Client.pm

filter: Statementstmt 75.4% 619 / 820 Branchbran 59.1% 369 / 624 Conditioncond 51.2% 318 / 621 MC/DCmcdc 30.4% 97 / 319 Subroutinesub 73.1% 49 / 67 Podpod 0.0% 0 / 11 totaltotal 58.9% 1452 / 2462 CC 545 SCAR 51.1
CC
545
Cov
63%
connect_websocket
756.0
_dispatch
564.0
request
314.7
CRAP 165.8
↑ Summary HTTP/Server.pm »
1 package Unblock::HTTP::Client;
2  
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use Scalar::Util qw(blessed refaddr weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use Uniform::HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 12 ▶use Unblock::HTTP::_Policy;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use Unblock::HTTP::_EngineFactory;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 ▶use Unblock::HTTP::_ClientOperation;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 12 ▶use Unblock::HTTP::_AltSvc;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 12 our $VERSION = '0.03';
15  
16 60 ▶sub new {
Subroutine new: called CC=31 SCAR=35.1
Pod undocumented
17 60 my ($class, @args) = @_;
18 60 ▶ croak 'new(): expected named arguments' if @args % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 60 60
19 60 my %option = @args;
20 60 my %protocols;
21 60 for my $name (qw(http1 http2 http3)) {
22 180 ▶ $protocols{$name} = delete $option{$name} if exists $option{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $option{$name} 66 114 180
23 }
24 60 my $policy = Unblock::HTTP::_Policy->new(%protocols, _websocket_role => 'client');
25 60 my %factory;
26 60 for my $name (qw(connect_stream connect_quic defer schedule_timer release_connection)) {
27 300 ▶ $factory{$name} = delete $option{$name} if exists $option{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $option{$name} 141 159 300
28 croak "new(): $name must be a coderef"
29 300 ▶ if exists($factory{$name}) && ref($factory{$name}) ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if exists $factory{$name} and ref $factory{$name} ne "CODE" 0 300 300
Condition66%2/3
exists $factory{$name} and ref $factory{$name} ne "CODE"
!ll&&!rl&&r
1591410
MC/DC0%0/2
exists $factory{$name} and ref $factory{$name} ne "CODE"
exists $factory{$name} ref $factory{$name} ne "CODE"
Truth table66%2/3
A and B
A= exists $factory{$name}B= ref $factory{$name} ne "CODE"
ABresult
0X0
100
111
30 }
31 60 ▶ croak 'new(): defer callback is required' unless $factory{defer};
Branch: 1 branch
BranchTrueFalseTotal
unless $factory{"defer"} 1 59 60
32 croak 'new(): connect_stream is required for HTTP/1 or HTTP/2'
33 if ($policy->enabled('http/1.1') || $policy->enabled('h2'))
34 59 ▶ && !$factory{connect_stream};
Branch: 1 branch
BranchTrueFalseTotal
if $policy->enabled("http/1.1") || $policy->enabled("h2") and not $factory{"connect_stream"} 1 58 59
Condition100%6/6
$policy->enabled("http/1.1") || $policy->enabled("h2") and not $factory{"connect_stream"}
!ll&&!rl&&r
12461
$policy->enabled("http/1.1") or $policy->enabled("h2")
l!l&&r!l&&!r
361112
MC/DC66%2/3
$policy->enabled("http/1.1") || $policy->enabled("h2") and not $factory{"connect_stream"}
$policy->enabled("http/1.1") $policy->enabled("h2") not $factory{"connect_stream"}
Truth table80%4/5
A or B and not(C)
A= $policy->enabled("http/1.1")B= $policy->enabled("h2")C= not $factory{"connect_stream"}
ABCresult
00X0
1X00
0100
1X11
0111
35 croak 'new(): connect_quic is required for HTTP/3'
36 58 ▶ if $policy->enabled('h3') && !$factory{connect_quic};
Branch: 1 branch
BranchTrueFalseTotal
if $policy->enabled("h3") and not $factory{"connect_quic"} 1 57 58
Condition100%3/3
$policy->enabled("h3") and not $factory{"connect_quic"}
!ll&&!rl&&r
44131
MC/DC100%2/2
$policy->enabled("h3") and not $factory{"connect_quic"}
$policy->enabled("h3") not $factory{"connect_quic"}
Truth table100%3/3
A and not(B)
A= $policy->enabled("h3")B= not $factory{"connect_quic"}
ABresult
0X0
100
111
37  
38 57 my $clock = delete $option{alt_svc_clock};
39 57 ▶ croak 'new(): alt_svc_clock must be a coderef'
Branch: 1 branch
BranchTrueFalseTotal
if defined $clock and ref $clock ne "CODE" 0 57 57
Condition66%2/3
defined $clock and ref $clock ne "CODE"
!ll&&!rl&&r
5610
MC/DC0%0/2
defined $clock and ref $clock ne "CODE"
defined $clock ref $clock ne "CODE"
Truth table66%2/3
A and B
A= defined $clockB= ref $clock ne "CODE"
ABresult
0X0
100
111
40 if defined($clock) && ref($clock) ne 'CODE';
41 57 ▶ my $alt_svc = Unblock::HTTP::_AltSvc->new(
Branch: 1 branch
BranchTrueFalseTotal
defined $clock ? : 1 56 57
42 (defined($clock) ? (clock => $clock) : ()),
43 );
44  
45 57 my $idle_timeout = delete $option{idle_timeout};
46 57 ▶ if (defined $idle_timeout) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $idle_timeout) 13 44 57
47 13 ▶ croak 'new(): idle_timeout must be a positive number of seconds'
Branch: 1 branch
BranchTrueFalseTotal
if ref $idle_timeout or not $idle_timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/ or $idle_timeout <= 0 5 8 13
Condition100%6/6
ref $idle_timeout or not $idle_timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/ or $idle_timeout <= 0
l!l&&r!l&&!r
418
ref $idle_timeout or not $idle_timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/
l!l&&r!l&&!r
139
MC/DC100%3/3
ref $idle_timeout or not $idle_timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/ or $idle_timeout <= 0
ref $idle_timeout not $idle_timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/ $idle_timeout <= 0
Truth table100%4/4
A or not(B) or C
A= ref $idle_timeoutB= not $idle_timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/C= $idle_timeout <= 0
ABCresult
1XX1
01X1
0011
0000
48 if ref($idle_timeout)
49 || $idle_timeout !~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/
50 || $idle_timeout <= 0;
51 croak 'new(): idle_timeout requires schedule_timer callback'
52 8 ▶ unless $factory{schedule_timer};
Branch: 1 branch
BranchTrueFalseTotal
unless $factory{"schedule_timer"} 1 7 8
53 7 $idle_timeout += 0;
54 }
55  
56 51 my %limit;
57 51 for my $key (qw(max_pending_requests max_connections_per_origin max_streams_per_connection)) {
58 153 ▶ my $default = $key eq 'max_pending_requests' ? 128
Branch: 2 branches
BranchTrueFalseTotal
$key eq 'max_pending_requests' ? : 51 102 153
$key eq 'max_connections_per_origin' ? : 51 51 102
59 : $key eq 'max_connections_per_origin' ? 4 : 32;
60 153 ▶ my $value = exists($option{$key}) ? delete($option{$key}) : $default;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{$key} ? : 35 118 153
61 153 ▶ croak "new(): $key must be a positive integer"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and not ref $value and $value =~ /\A[0-9]+\z/ and $value > 0 0 153 153
Condition33%3/9
defined $value and not ref $value and $value =~ /\A[0-9]+\z/ and $value > 0
!ll&&!rl&&r
00153
defined $value and not ref $value and $value =~ /\A[0-9]+\z/
!ll&&!rl&&r
00153
defined $value and not ref $value
!ll&&!rl&&r
00153
MC/DC0%0/4
defined $value and not ref $value and $value =~ /\A[0-9]+\z/ and $value > 0
defined $value not ref $value $value =~ /\A[0-9]+\z/ $value > 0
Truth table20%1/5
A and not(B) and C and D
A= defined $valueB= not ref $valueC= $value =~ /\A[0-9]+\z/D= $value > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
62 unless defined($value) && !ref($value)
63 && $value =~ /\A[0-9]+\z/ && $value > 0;
64 153 $limit{$key} = $value;
65 }
66 51 ▶ croak 'new(): unknown option: ' . join(', ', sort keys %option) if %option;
Branch: 1 branch
BranchTrueFalseTotal
if %option 0 51 51
67 51 return bless {
68 policy => $policy,
69 factory => \%factory,
70 limit => \%limit,
71 pending_count => 0,
72 active_operations => {},
73 shutdown => 0,
74 pools => {},
75 alt_svc => $alt_svc,
76 idle_timeout => $idle_timeout,
77 }, $class;
78 }
79  
80 1 ▶sub protocols { $_[0]{policy}->protocols }
Subroutine protocols: called CC=1 SCAR=0.0
Pod undocumented
81 51 ▶sub alpn_protocols { $_[0]{policy}->alpn_protocols }
Subroutine alpn_protocols: called CC=1 SCAR=0.0
Pod undocumented
82 0 ▶sub supports { $_[0]{policy}->enabled($_[1]) }
Subroutine supports: not called CC=1 SCAR=6.9
Pod undocumented
83 24 ▶sub pending_count { $_[0]{pending_count} }
Subroutine pending_count: called CC=1 SCAR=0.0
Pod undocumented
84 2 ▶sub is_shutdown { $_[0]{shutdown} ? 1 : 0 }
Subroutine is_shutdown: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'shutdown'} ? : 1 1 2
85  
86 # A copied, observational-only snapshot. No transport or engine objects
87 # escape, and taking a snapshot never runs scheduler or timer callbacks.
88 20 ▶sub pool_stats {
Subroutine pool_stats: called CC=13 SCAR=25.8
Pod undocumented
89 20 my ($self) = @_;
90 my $total = {
91 origins => 0, connections => 0, active => 0, idle => 0,
92 retiring => 0, credit_blocked => 0, connecting => 0,
93 pending => $self->{pending_count},
94 20 by_origin => [],
95 };
96 20 for my $key (sort keys %{ $self->{pools} }) {
97 13 my $pool = $self->{pools}{$key};
98 my $one = {
99 scheme => $pool->{info}{scheme},
100 host => $pool->{info}{host},
101 port => $pool->{info}{port},
102 connections => 0, active => 0, idle => 0,
103 retiring => 0, credit_blocked => 0,
104 connecting => $pool->{connecting} ? 1 : 0,
105 13 ▶ pending => scalar @{ $pool->{pending} },
Branch: 1 branch
BranchTrueFalseTotal
$pool->{'connecting'} ? : 5 8 13
106 };
107 13 for my $conn (@{ $pool->{connections} }) {
108 7 $one->{connections}++;
109 7 $one->{active} += $conn->{active};
110 7 ▶ $one->{retiring}++ if $conn->{stale} || _retired($conn);
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"stale"} or _retired($conn) 3 4 7
Condition66%2/3
$conn->{"stale"} or _retired($conn)
l!l&&r!l&&!r
304
MC/DC50%1/2
$conn->{"stale"} or _retired($conn)
$conn->{"stale"} _retired($conn)
Truth table66%2/3
A or B
A= $conn->{"stale"}B= _retired($conn)
ABresult
1X1
011
000
111 7 ▶ $one->{credit_blocked}++ if $conn->{credit_blocked};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"credit_blocked"} 1 6 7
112 $one->{idle}++ if !$conn->{active} && !$conn->{credit_blocked}
113 7 ▶ && !$conn->{released} && !_closed($conn)
Branch: 1 branch
BranchTrueFalseTotal
unless $conn->{"active"} or $conn->{"credit_blocked"} or $conn->{"released"} or _closed($conn) or _retired($conn) 2 5 7
Condition75%9/12
$conn->{"active"} or $conn->{"credit_blocked"} or $conn->{"released"} or _closed($conn) or _retired($conn)
l!l&&r!l&&!r
502
$conn->{"active"} or $conn->{"credit_blocked"} or $conn->{"released"} or _closed($conn)
l!l&&r!l&&!r
502
$conn->{"active"} or $conn->{"credit_blocked"} or $conn->{"released"}
l!l&&r!l&&!r
502
$conn->{"active"} or $conn->{"credit_blocked"}
l!l&&r!l&&!r
412
MC/DC40%2/5
$conn->{"active"} or $conn->{"credit_blocked"} or $conn->{"released"} or _closed($conn) or _retired($conn)
$conn->{"active"} $conn->{"credit_blocked"} $conn->{"released"} _closed($conn) _retired($conn)
Truth table50%3/6
A or B or C or D or E
A= $conn->{"active"}B= $conn->{"credit_blocked"}C= $conn->{"released"}D= _closed($conn)E= _retired($conn)
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
114 && !_retired($conn);
115 }
116 13 for my $count (qw(connections active idle retiring credit_blocked connecting)) {
117 78 $total->{$count} += $one->{$count};
118 }
119 13 push @{ $total->{by_origin} }, $one;
120 13 $total->{origins}++;
121 }
122 20 return $total;
123 }
124  
125 # A framework explicitly invokes this when its network identity changes.
126 # No active transaction is replayed, cancelled or moved between engines.
127 # Stop new admission, cancel unsent work, and retire live connections.
128 # Accepted transactions finish normally; idle transports are released now.
129 11 ▶sub shutdown {
Subroutine shutdown: called CC=11 SCAR=24.0
Pod undocumented
130 11 my ($self) = @_;
131 11 ▶ return $self if $self->{shutdown};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"shutdown"} 1 10 11
132 10 $self->{shutdown} = 1;
133 10 $self->{alt_svc}->clear;
134 10 for my $pool (values %{ $self->{pools} }) {
135 # A recovered H3 stream may have taken its request away from a
136 # speculative factory. Cancel the outstanding connector even if
137 # no request is left in the pending queue.
138 $self->_abandon_connect($pool, $pool->{attempt}{op})
139 7 ▶ if $pool->{attempt};
Branch: 1 branch
BranchTrueFalseTotal
if $pool->{"attempt"} 2 5 7
140 local $pool->{callback_depth} =
141 7 ▶ ($pool->{callback_depth} || 0) + 1;
Condition50%1/2
$pool->{'callback_depth'} || 0
l!l
07
MC/DC0%0/1
$pool->{'callback_depth'} || 0
$pool->{'callback_depth'}
Truth table50%1/2
A
A= $pool->{'callback_depth'}
Aresult
11
00
142 7 for my $op (@{ [ @{ $pool->{pending} } ] }) {
143 2 ▶ $op->cancel unless $op->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
unless $op->is_terminal 2 0 2
144 }
145 7 my @live;
146 7 for my $conn (@{ $pool->{connections} }) {
147 5 ▶ next if $conn->{released};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"released"} 0 5 5
148 5 $conn->{stale} = 1;
149 5 ▶ $self->_cancel_idle($conn) if $conn->{idle_cancel};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"idle_cancel"} 1 4 5
150 5 ▶ if ($conn->{active}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conn->{'active'}) { } 2 3 5
151 2 push @live, $conn;
152 } else {
153 3 $self->_release_connection($conn, 'shutdown');
154 }
155 }
156 7 $pool->{connections} = \@live;
157 7 $self->_delete_empty_pool($pool);
158 }
159 10 return $self;
160 }
161  
162 7 ▶sub network_changed {
Subroutine network_changed: called CC=14 SCAR=26.4
Pod undocumented
163 7 my ($self) = @_;
164 7 ▶ return if $self->{shutdown};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"shutdown"} 1 6 7
165 6 $self->{alt_svc}->clear;
166 6 for my $pool (values %{ $self->{pools} }) {
167 # Suppress synchronous reentry from user-owned release hooks.
168 6 ▶ local $pool->{callback_depth} = ($pool->{callback_depth} || 0) + 1;
Condition50%1/2
$pool->{'callback_depth'} || 0
l!l
06
MC/DC0%0/1
$pool->{'callback_depth'} || 0
$pool->{'callback_depth'}
Truth table50%1/2
A
A= $pool->{'callback_depth'}
Aresult
11
00
169 6 ▶ if (my $attempt = $pool->{attempt}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $attempt = $pool->{"attempt"}) 2 4 6
170 2 my $op = $attempt->{op};
171 2 $self->_abandon_connect($pool, $op);
172 2 ▶ $op->{state} = 'queued' unless $op->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
unless $op->is_terminal 2 0 2
173 }
174 6 for my $op (@{ $pool->{pending} }) {
175 6 ▶ next if $op->is_terminal || !$op->{alt_svc};
Branch: 1 branch
BranchTrueFalseTotal
if $op->is_terminal or not $op->{"alt_svc"} 5 1 6
Condition66%2/3
$op->is_terminal or not $op->{"alt_svc"}
l!l&&r!l&&!r
051
MC/DC50%1/2
$op->is_terminal or not $op->{"alt_svc"}
$op->is_terminal not $op->{"alt_svc"}
Truth table66%2/3
A or not(B)
A= $op->is_terminalB= not $op->{"alt_svc"}
ABresult
1X1
011
000
176 1 delete $op->{alt_svc};
177 1 $op->{version} = 'tcp';
178 1 $op->{state} = 'queued';
179 }
180 6 my (@keep, @release);
181 6 for my $conn (@{ $pool->{connections} }) {
182 3 $conn->{stale} = 1;
183 3 ▶ $self->_cancel_idle($conn) if $conn->{idle_cancel};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"idle_cancel"} 1 2 3
184 3 ▶ if ($conn->{active}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conn->{'active'}) { } 1 2 3
185 1 push @keep, $conn;
186 } else {
187 2 push @release, $conn;
188 }
189 }
190 6 $pool->{connections} = \@keep;
191 6 $self->_release_connection($_, 'network_changed') for @release;
192 6 ▶ $self->_schedule($pool) if @{ $pool->{pending} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$pool->{"pending"};} 4 2 6
193 6 $self->_delete_empty_pool($pool);
194 }
195 6 return;
196 }
197  
198 # HTTP1 upgrades transfer the socket out of the pool. HTTP2 and HTTP3
199 # CONNECT use independent streams on a multiplexed pooled connection.
200 0 ▶sub connect_websocket {
Subroutine connect_websocket: not called CC=27 SCAR=66.3
Pod undocumented
201 0 my ($self, @args) = @_;
202 0 ▶ croak 'connect_websocket(): expected named arguments' if @args % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 0 0
203 0 my %option = @args;
204 0 my $http_version = delete $option{http_version};
205 $http_version = $self->{policy}->websocket_enabled('http/1.1') ? '1.1'
206 0 ▶ : $self->{policy}->websocket_enabled('h2') ? '2' : '3'
Branch: 3 branches
BranchTrueFalseTotal
unless defined $http_version 0 0 0
$self->{'policy'}->websocket_enabled('http/1.1') ? : 0 0 0
$self->{'policy'}->websocket_enabled('h2') ? : 0 0 0
207 unless defined $http_version;
208 0 ▶ croak 'connect_websocket(): http_version must be 1.1, 2 or 3'
Branch: 1 branch
BranchTrueFalseTotal
if ref $http_version or not $http_version =~ /\A(?:1\.1|2|3)\z/ 0 0 0
Condition0%0/3
ref $http_version or not $http_version =~ /\A(?:1\.1|2|3)\z/
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $http_version or not $http_version =~ /\A(?:1\.1|2|3)\z/
ref $http_version not $http_version =~ /\A(?:1\.1|2|3)\z/
Truth table0%0/3
A or not(B)
A= ref $http_versionB= not $http_version =~ /\A(?:1\.1|2|3)\z/
ABresult
1X1
011
000
209 if ref($http_version) || $http_version !~ /\A(?:1\.1|2|3)\z/;
210 0 ▶ my $ws_protocol = $http_version eq '3' ? 'h3'
Branch: 2 branches
BranchTrueFalseTotal
$http_version eq '3' ? : 0 0 0
$http_version eq '2' ? : 0 0 0
211 : $http_version eq '2' ? 'h2' : 'http/1.1';
212 croak "connect_websocket(): $ws_protocol websocket support is disabled"
213 0 ▶ unless $self->{policy}->websocket_enabled($ws_protocol);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"policy"}->websocket_enabled($ws_protocol) 0 0 0
214 0 my $url = delete $option{url};
215 0 ▶ croak 'connect_websocket(): url is required'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $url and not ref $url and length $url 0 0 0
Condition0%0/6
defined $url and not ref $url and length $url
!ll&&!rl&&r
000
defined $url and not ref $url
!ll&&!rl&&r
000
MC/DC0%0/3
defined $url and not ref $url and length $url
defined $url not ref $url length $url
Truth table0%0/4
A and not(B) and C
A= defined $urlB= not ref $urlC= length $url
ABCresult
0XX0
10X0
1100
1111
216 unless defined($url) && !ref($url) && length($url);
217 0 my %handshake_option;
218 0 for my $name (qw(headers origin subprotocols permessage_deflate)) {
219 $handshake_option{$name} = delete $option{$name}
220 0 ▶ if exists $option{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $option{$name} 0 0 0
221 }
222 0 my %session_option;
223 0 for my $name (qw(
224 backend max_message_size high_water low_water random_bytes
225 on_message on_ping on_pong on_close on_drain
226 )) {
227 $session_option{$name} = delete $option{$name}
228 0 ▶ if exists $option{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $option{$name} 0 0 0
229 }
230 0 my $on_open = delete $option{on_open};
231 0 ▶ croak 'connect_websocket(): on_open must be a coderef'
Branch: 1 branch
BranchTrueFalseTotal
if defined $on_open and ref $on_open ne "CODE" 0 0 0
Condition0%0/3
defined $on_open and ref $on_open ne "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $on_open and ref $on_open ne "CODE"
defined $on_open ref $on_open ne "CODE"
Truth table0%0/3
A and B
A= defined $on_openB= ref $on_open ne "CODE"
ABresult
0X0
100
111
232 if defined($on_open) && ref($on_open) ne 'CODE';
233 0 my $on_error = delete $option{on_error};
234 0 ▶ croak 'connect_websocket(): on_error must be a coderef'
Branch: 1 branch
BranchTrueFalseTotal
if defined $on_error and ref $on_error ne "CODE" 0 0 0
Condition0%0/3
defined $on_error and ref $on_error ne "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $on_error and ref $on_error ne "CODE"
defined $on_error ref $on_error ne "CODE"
Truth table0%0/3
A and B
A= defined $on_errorB= ref $on_error ne "CODE"
ABresult
0X0
100
111
235 if defined($on_error) && ref($on_error) ne 'CODE';
236 0 my $on_finish = delete $option{on_finish};
237 0 ▶ croak 'connect_websocket(): on_finish must be a coderef'
Branch: 1 branch
BranchTrueFalseTotal
if defined $on_finish and ref $on_finish ne "CODE" 0 0 0
Condition0%0/3
defined $on_finish and ref $on_finish ne "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $on_finish and ref $on_finish ne "CODE"
defined $on_finish ref $on_finish ne "CODE"
Truth table0%0/3
A and B
A= defined $on_finishB= ref $on_finish ne "CODE"
ABresult
0X0
100
111
238 if defined($on_finish) && ref($on_finish) ne 'CODE';
239 0 my $timeout = delete $option{timeout};
240 0 ▶ croak 'connect_websocket(): unknown option: ' . join(', ', sort keys %option)
Branch: 1 branch
BranchTrueFalseTotal
if %option 0 0 0
241 if %option;
242  
243 0 require Unblock::WebSocket::Handshake;
244 0 my ($handshake, $request) =
245 Unblock::WebSocket::Handshake->client_request(
246 $url, http_version => $http_version, %handshake_option,
247 );
248 0 my $http_url = "$url";
249 0 $http_url =~ s/\Aws:/http:/i;
250 0 $http_url =~ s/\Awss:/https:/i;
251 0 my $spec = {
252 handshake => $handshake,
253 options => \%session_option,
254 on_open => $on_open,
255 };
256 0 ▶ return $self->request(
Branch: 3 branches
BranchTrueFalseTotal
defined $on_error ? : 0 0 0
defined $on_finish ? : 0 0 0
defined $timeout ? : 0 0 0
257 url => $http_url,
258 http_version => $http_version,
259 _websocket_request => $request,
260 _websocket_connect => $spec,
261 (defined($on_error) ? (on_error => $on_error) : ()),
262 (defined($on_finish) ? (on_finish => $on_finish) : ()),
263 (defined($timeout) ? (timeout => $timeout) : ()),
264 );
265 }
266  
267 529 ▶sub request {
Subroutine request: called CC=100 SCAR=57.5
Pod undocumented
268 529 my ($self, @args) = @_;
269 529 ▶ croak 'request(): Client is shut down' if $self->{shutdown};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"shutdown"} 1 528 529
270 528 ▶ croak 'request(): expected named arguments' if @args % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 528 528
271 528 my %field = @args;
272 528 my $ws_spec = delete $field{_websocket_connect};
273 528 my $ws_request = delete $field{_websocket_request};
274 528 ▶ croak 'request(): internal WebSocket options must occur together'
Branch: 1 branch
BranchTrueFalseTotal
if (!!$ws_spec) != !!$ws_request 0 528 528
275 if (!!$ws_spec) != (!!$ws_request);
276 croak 'request(): WebSocket option is disabled'
277 if $ws_spec && !$self->{policy}->websocket_enabled(
278 528 ▶ $ws_request->version eq '3' ? 'h3'
Branch: 3 branches
BranchTrueFalseTotal
if $ws_spec and not $self->{"policy"}->websocket_enabled($ws_request->version eq 3 ? "h3" : ($ws_request->version eq 2 ? "h2" : "http/1.1")) 0 528 528
$ws_request->version eq '3' ? : 0 0 0
$ws_request->version eq '2' ? : 0 0 0
Condition33%1/3
$ws_spec and not $self->{"policy"}->websocket_enabled($ws_request->version eq 3 ? "h3" : ($ws_request->version eq 2 ? "h2" : "http/1.1"))
!ll&&!rl&&r
52800
MC/DC0%0/2
$ws_spec and not $self->{"policy"}->websocket_enabled($ws_request->version eq 3 ? "h3" : ($ws_request->version eq 2 ? "h2" : "http/1.1"))
$ws_spec not $self->{"policy"}->websocket_enabled($ws_request->version eq 3 ? "h3" : ($ws_request->version eq 2 ? "h2" : "http/1.1"))
Truth table33%1/3
A and not(B)
A= $ws_specB= not $self->{"policy"}->websocket_enabled($ws_request->version eq 3 ? "h3" : ($ws_request->version eq 2 ? "h2" : "http/1.1"))
ABresult
0X0
100
111
279 : $ws_request->version eq '2' ? 'h2' : 'http/1.1'
280 );
281 528 my $url = delete $field{url};
282 528 ▶ croak 'request(): url is required' unless defined($url) && !ref($url) && length($url);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $url and not ref $url and length $url 0 528 528
Condition33%2/6
defined $url and not ref $url and length $url
!ll&&!rl&&r
00528
defined $url and not ref $url
!ll&&!rl&&r
00528
MC/DC0%0/3
defined $url and not ref $url and length $url
defined $url not ref $url length $url
Truth table25%1/4
A and not(B) and C
A= defined $urlB= not ref $urlC= length $url
ABCresult
0XX0
10X0
1100
1111
283 528 my ($scheme, $host, $port, $authority, $target);
284 # Common canonical ASCII URLs need no URI object. Keep this match
285 # intentionally restrictive: noncanonical schemes/hosts, IPv6,
286 # escaping, fragments and exotic targets still use URI below.
287 # No URL cache, shared parser state or persistent allocation.
288 528 ▶ if ($url =~ m{
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ m[ \A (https?):// ([a-z0-9]+(?:[a-z0-9-]*[a-z0-9])? (?:\.[a-z0-9]+(?:[a-z0-9-]*[a-z0-9])?)*) (?::([1-9][0-9]{0,4}))? ([/?][A-Za-z0-9._~/?&=+\-]*)? \z ]x and !defined($3) || $3 <= 65535) { } 513 15 528
Condition100%6/6
$url =~ m[ \A (https?):// ([a-z0-9]+(?:[a-z0-9-]*[a-z0-9])? (?:\.[a-z0-9]+(?:[a-z0-9-]*[a-z0-9])?)*) (?::([1-9][0-9]{0,4}))? ([/?][A-Za-z0-9._~/?&=+\-]*)? \z ]x and !defined($3) || $3 <= 65535
!ll&&!rl&&r
141513
not defined $3 or $3 <= 65535
l!l&&r!l&&!r
50761
MC/DC100%3/3
$url =~ m[ \A (https?):// ([a-z0-9]+(?:[a-z0-9-]*[a-z0-9])? (?:\.[a-z0-9]+(?:[a-z0-9-]*[a-z0-9])?)*) (?::([1-9][0-9]{0,4}))? ([/?][A-Za-z0-9._~/?&=+\-]*)? \z ]x and !defined($3) || $3 <= 65535
$url =~ m[ \A (https?):// ([a-z0-9]+(?:[a-z0-9-]*[a-z0-9])? (?:\.[a-z0-9]+(?:[a-z0-9-]*[a-z0-9])?)*) (?::([1-9][0-9]{0,4}))? ([/?][A-Za-z0-9._~/?&=+\-]*)? \z ]x not defined $3 $3 <= 65535
Truth table100%4/4
A and not(B) or C
A= $url =~ m[ \A (https?):// ([a-z0-9]+(?:[a-z0-9-]*[a-z0-9])? (?:\.[a-z0-9]+(?:[a-z0-9-]*[a-z0-9])?)*) (?::([1-9][0-9]{0,4}))? ([/?][A-Za-z0-9._~/?&=+\-]*)? \z ]xB= not defined $3C= $3 <= 65535
ABCresult
0XX0
1000
11X1
1011
289 \A (https?)://
290 ([a-z0-9]+(?:[a-z0-9-]*[a-z0-9])?
291 (?:\.[a-z0-9]+(?:[a-z0-9-]*[a-z0-9])?)*)
292 (?::([1-9][0-9]{0,4}))?
293 ([/?][A-Za-z0-9._~/?&=+\-]*)?
294 \z
295 }x && (!defined($3) || $3 <= 65535)) {
296 513 my $given_port = $3;
297 513 ($scheme, $host) = ($1, $2);
298 513 ▶ $port = defined($given_port) ? $given_port
Branch: 2 branches
BranchTrueFalseTotal
defined $given_port ? : 6 507 513
$scheme eq 'https' ? : 459 48 507
299 : $scheme eq 'https' ? 443 : 80;
300 513 $authority = $host;
301 513 ▶ $authority .= ":$given_port" if defined $given_port;
Branch: 1 branch
BranchTrueFalseTotal
if defined $given_port 6 507 513
302 513 ▶ $target = defined($4) ? $4 : '/';
Branch: 1 branch
BranchTrueFalseTotal
defined $4 ? : 511 2 513
303 513 ▶ $target = '/' . $target if substr($target, 0, 1) eq '?';
Branch: 1 branch
BranchTrueFalseTotal
if substr($target, 0, 1) eq "?" 1 512 513
304 } else {
305 15 my $uri = URI->new($url);
306 15 ▶ $scheme = lc($uri->scheme || '');
Condition50%1/2
$uri->scheme || ''
l!l
150
MC/DC0%0/1
$uri->scheme || ''
$uri->scheme
Truth table50%1/2
A
A= $uri->scheme
Aresult
11
00
307 15 ▶ croak 'request(): URL scheme must be http or https'
Branch: 1 branch
BranchTrueFalseTotal
unless $scheme eq "http" or $scheme eq "https" 2 13 15
Condition100%3/3
$scheme eq "http" or $scheme eq "https"
l!l&&r!l&&!r
3102
MC/DC100%2/2
$scheme eq "http" or $scheme eq "https"
$scheme eq "http" $scheme eq "https"
Truth table100%3/3
A or B
A= $scheme eq "http"B= $scheme eq "https"
ABresult
1X1
011
000
308 unless $scheme eq 'http' || $scheme eq 'https';
309 13 ▶ croak 'request(): URL must not contain userinfo or a fragment'
Branch: 1 branch
BranchTrueFalseTotal
if defined $uri->userinfo or defined $uri->fragment 4 9 13
Condition100%3/3
defined $uri->userinfo or defined $uri->fragment
l!l&&r!l&&!r
229
MC/DC100%2/2
defined $uri->userinfo or defined $uri->fragment
defined $uri->userinfo defined $uri->fragment
Truth table100%3/3
A or B
A= defined $uri->userinfoB= defined $uri->fragment
ABresult
1X1
011
000
310 if defined($uri->userinfo) || defined($uri->fragment);
311 9 $host = $uri->host;
312 9 ▶ croak 'request(): URL must include a host'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host and length $host 0 9 9
Condition33%1/3
defined $host and length $host
!ll&&!rl&&r
009
MC/DC0%0/2
defined $host and length $host
defined $host length $host
Truth table33%1/3
A and B
A= defined $hostB= length $host
ABresult
0X0
100
111
313 unless defined($host) && length($host);
314 9 $port = $uri->port;
315 9 ▶ croak 'request(): invalid URL port'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $port and $port =~ /\A[0-9]+\z/ and $port > 0 and $port <= 65535 2 7 9
Condition66%6/9
defined $port and $port =~ /\A[0-9]+\z/ and $port > 0 and $port <= 65535
!ll&&!rl&&r
117
defined $port and $port =~ /\A[0-9]+\z/ and $port > 0
!ll&&!rl&&r
018
defined $port and $port =~ /\A[0-9]+\z/
!ll&&!rl&&r
009
MC/DC50%2/4
defined $port and $port =~ /\A[0-9]+\z/ and $port > 0 and $port <= 65535
defined $port $port =~ /\A[0-9]+\z/ $port > 0 $port <= 65535
Truth table60%3/5
A and B and C and D
A= defined $portB= $port =~ /\A[0-9]+\z/C= $port > 0D= $port <= 65535
ABCDresult
0XXX0
10XX0
110X0
11100
11111
316 unless defined($port) && $port =~ /\A[0-9]+\z/
317 && $port > 0 && $port <= 65535;
318 7 $authority = $uri->authority;
319 7 $target = $uri->path_query;
320 7 ▶ $target = '/' unless defined($target) && length($target);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $target and length $target 0 7 7
Condition33%1/3
defined $target and length $target
!ll&&!rl&&r
007
MC/DC0%0/2
defined $target and length $target
defined $target length $target
Truth table33%1/3
A and B
A= defined $targetB= length $target
ABresult
0X0
100
111
321 7 ▶ $target = '/' . $target if substr($target, 0, 1) eq '?';
Branch: 1 branch
BranchTrueFalseTotal
if substr($target, 0, 1) eq "?" 0 7 7
322 }
323  
324 520 my $version = delete $field{http_version};
325 520 ▶ my $strict_version = defined($version) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $version ? : 43 477 520
326 520 ▶ if (defined $version) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $version) { } 43 477 520
327 43 ▶ croak 'request(): http_version must be 1.1, 2 or 3'
Branch: 1 branch
BranchTrueFalseTotal
if ref $version or not $version =~ /\A(?:1\.1|2|3)\z/ 1 42 43
Condition66%2/3
ref $version or not $version =~ /\A(?:1\.1|2|3)\z/
l!l&&r!l&&!r
0142
MC/DC50%1/2
ref $version or not $version =~ /\A(?:1\.1|2|3)\z/
ref $version not $version =~ /\A(?:1\.1|2|3)\z/
Truth table66%2/3
A or not(B)
A= ref $versionB= not $version =~ /\A(?:1\.1|2|3)\z/
ABresult
1X1
011
000
328 if ref($version) || $version !~ /\A(?:1\.1|2|3)\z/;
329 42 $version = { '1.1' => 'http/1.1', '2' => 'h2', '3' => 'h3' }->{$version};
330 croak "request(): required protocol '$version' is disabled"
331 42 ▶ unless $self->{policy}->enabled($version);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"policy"}->enabled($version) 1 41 42
332 41 ▶ croak 'request(): HTTP/3 requires https'
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "h3" and $scheme ne "https" 0 41 41
Condition66%2/3
$version eq "h3" and $scheme ne "https"
!ll&&!rl&&r
25160
MC/DC0%0/2
$version eq "h3" and $scheme ne "https"
$version eq "h3" $scheme ne "https"
Truth table66%2/3
A and B
A= $version eq "h3"B= $scheme ne "https"
ABresult
0X0
100
111
333 if $version eq 'h3' && $scheme ne 'https';
334 } else {
335 $version = ($self->{policy}->enabled('h2')
336 477 ▶ || $self->{policy}->enabled('http/1.1')) ? 'tcp' : 'h3';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'policy'}->enabled('h2') || $self->{'policy'}->enabled('http/1.1') ? : 344 133 477
Condition100%3/3
$self->{"policy"}->enabled("h2") or $self->{"policy"}->enabled("http/1.1")
l!l&&r!l&&!r
162182133
MC/DC100%2/2
$self->{"policy"}->enabled("h2") or $self->{"policy"}->enabled("http/1.1")
$self->{"policy"}->enabled("h2") $self->{"policy"}->enabled("http/1.1")
Truth table100%3/3
A or B
A= $self->{"policy"}->enabled("h2")B= $self->{"policy"}->enabled("http/1.1")
ABresult
1X1
011
000
337 477 ▶ croak 'request(): HTTP/3 requires https'
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "h3" and $scheme ne "https" 1 476 477
Condition100%3/3
$version eq "h3" and $scheme ne "https"
!ll&&!rl&&r
3441321
MC/DC100%2/2
$version eq "h3" and $scheme ne "https"
$version eq "h3" $scheme ne "https"
Truth table100%3/3
A and B
A= $version eq "h3"B= $scheme ne "https"
ABresult
0X0
100
111
338 if $version eq 'h3' && $scheme ne 'https';
339 }
340  
341 517 my %callbacks;
342 517 for my $name (qw(
343 on_response on_data on_end on_error on_finish on_informational on_drain on_transaction on_handoff
344 )) {
345 4653 ▶ next unless exists $field{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $field{$name} 4601 52 4653
346 52 my $cb = delete $field{$name};
347 52 ▶ croak "request(): $name must be a coderef" unless ref($cb) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cb eq "CODE" 0 52 52
348 52 $callbacks{$name} = $cb;
349 }
350 517 my $timeout = delete $field{timeout};
351 517 ▶ if (defined $timeout) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $timeout) 13 504 517
352 13 ▶ croak 'request(): timeout must be a positive number of seconds'
Branch: 1 branch
BranchTrueFalseTotal
if ref $timeout or not $timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/ or $timeout <= 0 4 9 13
Condition100%6/6
ref $timeout or not $timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/ or $timeout <= 0
l!l&&r!l&&!r
319
ref $timeout or not $timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/
l!l&&r!l&&!r
1210
MC/DC100%3/3
ref $timeout or not $timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/ or $timeout <= 0
ref $timeout not $timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/ $timeout <= 0
Truth table100%4/4
A or not(B) or C
A= ref $timeoutB= not $timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/C= $timeout <= 0
ABCresult
1XX1
01X1
0011
0000
353 if ref($timeout) || $timeout !~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/
354 || $timeout <= 0;
355 croak 'request(): timeout requires schedule_timer callback'
356 9 ▶ unless $self->{factory}{schedule_timer};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"factory"}{"schedule_timer"} 1 8 9
357 }
358 512 ▶ my $stream_body = delete($field{stream_body}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
delete $field{'stream_body'} ? : 3 509 512
359 croak 'request(): on_drain requires stream_body'
360 512 ▶ if $callbacks{on_drain} && !$stream_body;
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks{"on_drain"} and not $stream_body 0 512 512
Condition33%1/3
$callbacks{"on_drain"} and not $stream_body
!ll&&!rl&&r
51200
MC/DC0%0/2
$callbacks{"on_drain"} and not $stream_body
$callbacks{"on_drain"} not $stream_body
Truth table33%1/3
A and not(B)
A= $callbacks{"on_drain"}B= not $stream_body
ABresult
0X0
100
111
361 croak 'request(): on_handoff requires explicit http_version'
362 512 ▶ if $callbacks{on_handoff} && !$strict_version;
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks{"on_handoff"} and not $strict_version 0 512 512
Condition33%1/3
$callbacks{"on_handoff"} and not $strict_version
!ll&&!rl&&r
51200
MC/DC0%0/2
$callbacks{"on_handoff"} and not $strict_version
$callbacks{"on_handoff"} not $strict_version
Truth table33%1/3
A and not(B)
A= $callbacks{"on_handoff"}B= not $strict_version
ABresult
0X0
100
111
363 croak 'request(): multiplexed on_handoff requires CONNECT'
364 if $callbacks{on_handoff} && $version ne 'http/1.1'
365 512 ▶ && (($field{method} || 'GET') ne 'CONNECT');
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks{"on_handoff"} and $version ne "http/1.1" and ($field{"method"} || "GET") ne "CONNECT" 0 512 512
Condition25%2/8
$callbacks{"on_handoff"} and $version ne "http/1.1" and ($field{"method"} || "GET") ne "CONNECT"
!ll&&!rl&&r
51200
$callbacks{"on_handoff"} and $version ne "http/1.1"
!ll&&!rl&&r
51200
$field{'method'} || 'GET'
l!l
00
MC/DC0%0/3
$callbacks{"on_handoff"} and $version ne "http/1.1" and ($field{"method"} || "GET") ne "CONNECT"
$callbacks{"on_handoff"} $version ne "http/1.1" $field{'method'}
Truth table25%1/4
A and B and C
A= $callbacks{"on_handoff"}B= $version ne "http/1.1"C= $field{'method'}
ABCresult
0XX0
10X0
1100
1111
366 croak 'request(): on_handoff cannot be combined with WebSocket'
367 512 ▶ if $callbacks{on_handoff} && $ws_spec;
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks{"on_handoff"} and $ws_spec 0 512 512
Condition33%1/3
$callbacks{"on_handoff"} and $ws_spec
!ll&&!rl&&r
51200
MC/DC0%0/2
$callbacks{"on_handoff"} and $ws_spec
$callbacks{"on_handoff"} $ws_spec
Truth table33%1/3
A and B
A= $callbacks{"on_handoff"}B= $ws_spec
ABresult
0X0
100
111
368 croak 'request(): pending queue is full'
369 512 ▶ if $self->{pending_count} >= $self->{limit}{max_pending_requests};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"pending_count"} >= $self->{"limit"}{"max_pending_requests"} 2 510 512
370 croak 'request(): do not pass scheme, authority or target with url'
371 510 ▶ if grep { exists($field{$_}) } qw(scheme authority target);
Branch: 1 branch
BranchTrueFalseTotal
if grep {exists $field{$_};} "scheme", "authority", "target" 0 510 510
372 510 ▶ $field{method} = 'GET' unless exists $field{method};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $field{"method"} 488 22 510
373 510 ▶ croak 'request(): internal WebSocket request cannot override HTTP fields'
Branch: 1 branch
BranchTrueFalseTotal
if $ws_request and keys %field > 1 0 510 510
Condition33%1/3
$ws_request and keys %field > 1
!ll&&!rl&&r
51000
MC/DC0%0/2
$ws_request and keys %field > 1
$ws_request keys %field > 1
Truth table33%1/3
A and B
A= $ws_requestB= keys %field > 1
ABresult
0X0
100
111
374 if $ws_request && keys %field > 1;
375 510 ▶ my $request = $ws_request || Uniform::HTTP::Request->new(
Condition33%1/3
$ws_request || 'Uniform::HTTP::Request'->new(%field, 'scheme', $scheme, 'authority', $authority, 'target', $target)
l!l&&r!l&&!r
05100
MC/DC0%0/2
$ws_request || 'Uniform::HTTP::Request'->new(%field, 'scheme', $scheme, 'authority', $authority, 'target', $target)
$ws_request 'Uniform::HTTP::Request'->new(%field, 'scheme', $scheme, 'authority', $authority, 'target', $target)
Truth table33%1/3
A || B
A= $ws_requestB= 'Uniform::HTTP::Request'->new(%field, 'scheme', $scheme, 'authority', $authority, 'target', $target)
ABresult
1X1
011
000
376 %field, scheme => $scheme, authority => $authority, target => $target,
377 );
378 510 ▶ if ($ws_request) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ws_request) 0 510 510
379 0 ▶ croak 'request(): WebSocket protocol and handshake version disagree'
Branch: 1 branch
BranchTrueFalseTotal
unless $version eq "http/1.1" and $request->version eq "1.1" or $version eq "h2" and $request->version eq 2 or $version eq "h3" and $request->version eq 3 0 0 0
Condition0%0/15
$version eq "http/1.1" and $request->version eq "1.1" or $version eq "h2" and $request->version eq 2 or $version eq "h3" and $request->version eq 3
l!l&&r!l&&!r
000
$version eq "http/1.1" and $request->version eq "1.1" or $version eq "h2" and $request->version eq 2
l!l&&r!l&&!r
000
$version eq "http/1.1" and $request->version eq "1.1"
!ll&&!rl&&r
000
$version eq "h2" and $request->version eq 2
!ll&&!rl&&r
000
$version eq "h3" and $request->version eq 3
!ll&&!rl&&r
000
MC/DC0%0/6
$version eq "http/1.1" and $request->version eq "1.1" or $version eq "h2" and $request->version eq 2 or $version eq "h3" and $request->version eq 3
$version eq "http/1.1" $request->version eq "1.1" $version eq "h2" $request->version eq 2 $version eq "h3" $request->version eq 3
Truth table0%0/15
A and B or C and D or E and F
A= $version eq "http/1.1"B= $request->version eq "1.1"C= $version eq "h2"D= $request->version eq 2E= $version eq "h3"F= $request->version eq 3
ABCDEFresult
11XXXX1
0X11XX1
1011XX1
0X0X111
0X10111
100X111
1010111
0X0X0X0
0X0X100
0X100X0
0X10100
100X0X0
100X100
10100X0
1010100
380 unless ($version eq 'http/1.1' && $request->version eq '1.1')
381 || ($version eq 'h2' && $request->version eq '2')
382 || ($version eq 'h3' && $request->version eq '3');
383 0 ▶ croak 'request(): WebSocket URL and handshake request disagree'
Branch: 1 branch
BranchTrueFalseTotal
unless $request->scheme eq $scheme and $request->authority eq $authority and $request->target eq $target 0 0 0
Condition0%0/6
$request->scheme eq $scheme and $request->authority eq $authority and $request->target eq $target
!ll&&!rl&&r
000
$request->scheme eq $scheme and $request->authority eq $authority
!ll&&!rl&&r
000
MC/DC0%0/3
$request->scheme eq $scheme and $request->authority eq $authority and $request->target eq $target
$request->scheme eq $scheme $request->authority eq $authority $request->target eq $target
Truth table0%0/4
A and B and C
A= $request->scheme eq $schemeB= $request->authority eq $authorityC= $request->target eq $target
ABCresult
0XX0
10X0
1100
1111
384 unless $request->scheme eq $scheme
385 && $request->authority eq $authority
386 && $request->target eq $target;
387 }
388 510 my $key = join('|', $scheme, lc($host), $port);
389 510 ▶ my $origin = $self->{pools}{$key} ||= {
Condition100%2/2
$self->{"pools"}{$key} ||= {"info", {"scheme", $scheme, "host", $host, "port", 0 + $port, "authority", $authority, "key", $key}, "pending", [], "connections", [], "connecting", 0, "pumping", 0, "scheduled", 0}
l!l
43971
MC/DC100%1/1
$self->{"pools"}{$key} ||= {"info", {"scheme", $scheme, "host", $host, "port", 0 + $port, "authority", $authority, "key", $key}, "pending", [], "connections", [], "connecting", 0, "pumping", 0, "scheduled", 0}
$self->{"pools"}{$key}
Truth table100%2/2
A
A= $self->{"pools"}{$key}
Aresult
11
00
390 info => {
391 scheme => $scheme, host => $host, port => 0 + $port,
392 authority => $authority,
393 key => $key,
394 },
395 pending => [],
396 connections => [],
397 connecting => 0,
398 pumping => 0,
399 scheduled => 0,
400 };
401 510 my $op = Unblock::HTTP::_ClientOperation->new(
402 $self, $request, \%callbacks, $version, $origin,
403 );
404 $op->{stream_body} = ($ws_spec || $callbacks{on_handoff})
405 510 ▶ && ($version eq 'h2' || $version eq 'h3') ? 1 : $stream_body;
Branch: 1 branch
BranchTrueFalseTotal
($ws_spec || $callbacks{'on_handoff'}) && ($version eq 'h2' || $version eq 'h3') ? : 0 510 510
Condition22%2/9
$ws_spec || $callbacks{"on_handoff"} and $version eq "h2" || $version eq "h3"
!ll&&!rl&&r
51000
$ws_spec or $callbacks{"on_handoff"}
l!l&&r!l&&!r
00510
$version eq "h2" or $version eq "h3"
l!l&&r!l&&!r
000
MC/DC0%0/4
$ws_spec || $callbacks{"on_handoff"} and $version eq "h2" || $version eq "h3"
$ws_spec $callbacks{"on_handoff"} $version eq "h2" $version eq "h3"
Truth table14%1/7
A or B and C or D
A= $ws_specB= $callbacks{"on_handoff"}C= $version eq "h2"D= $version eq "h3"
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
406 510 ▶ $op->{websocket_connect} = $ws_spec if $ws_spec;
Branch: 1 branch
BranchTrueFalseTotal
if $ws_spec 0 510 510
407 510 ▶ if (!$strict_version && $scheme eq 'https'
Branch: 1 branch
BranchTrueFalseTotal
if (not $strict_version and $scheme eq "https" and $version eq "tcp" and $self->{"policy"}->enabled("h3")) 14 496 510
Condition100%9/9
not $strict_version and $scheme eq "https" and $version eq "tcp" and $self->{"policy"}->enabled("h3")
!ll&&!rl&&r
21128514
not $strict_version and $scheme eq "https" and $version eq "tcp"
!ll&&!rl&&r
79132299
not $strict_version and $scheme eq "https"
!ll&&!rl&&r
4138431
MC/DC100%4/4
not $strict_version and $scheme eq "https" and $version eq "tcp" and $self->{"policy"}->enabled("h3")
not $strict_version $scheme eq "https" $version eq "tcp" $self->{"policy"}->enabled("h3")
Truth table100%5/5
not(A) and B and C and D
A= not $strict_versionB= $scheme eq "https"C= $version eq "tcp"D= $self->{"policy"}->enabled("h3")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
408 && $version eq 'tcp' && $self->{policy}->enabled('h3')) {
409 14 my $advertised = $self->{alt_svc}->lookup($key);
410 14 ▶ if ($advertised) {
Branch: 1 branch
BranchTrueFalseTotal
if ($advertised) 5 9 14
411 5 $op->{alt_svc} = $advertised;
412 5 $op->{version} = 'h3';
413 }
414 }
415 510 ▶ if (defined $timeout) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $timeout) 8 502 510
416 my $cancel = $self->{factory}{schedule_timer}->(
417 6 ▶ 0 + $timeout, sub { $self->_request_timeout($op, $timeout) },
Subroutine __ANON__: called CC=1 SCAR=0.0
418 8 );
419 7 ▶ croak 'request(): schedule_timer must return a cancellation coderef'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cancel eq "CODE" 0 7 7
420 unless ref($cancel) eq 'CODE';
421 7 $op->{timer_cancel} = $cancel;
422 }
423 # A healthy, immediately admissible pooled connection needs no
424 # queue insertion, full pool scan or scheduler allocation. This is
425 # strictly an application-request path, never the per-byte path.
426 # Keep the general pump for pending work, reentrant callbacks,
427 # connecting factories and idle-expiration lifecycle management.
428 509 ▶ if (!defined($self->{idle_timeout})
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"idle_timeout"} || @{$origin->{"pending"};} || $origin->{"connecting"} || $origin->{"pumping"} || $origin->{"callback_depth"} || $origin->{"scheduled"} and @{$origin->{"connections"};} == 1) 418 91 509
Condition83%15/18
not defined $self->{"idle_timeout"} || @{$origin->{"pending"};} || $origin->{"connecting"} || $origin->{"pumping"} || $origin->{"callback_depth"} || $origin->{"scheduled"} and @{$origin->{"connections"};} == 1
!ll&&!rl&&r
2665418
defined $self->{'idle_timeout'} || @{$origin->{'pending'};} || $origin->{'connecting'} || $origin->{'pumping'} || $origin->{'callback_depth'} || $origin->{'scheduled'}
l!l&&r!l&&!r
260483
defined $self->{"idle_timeout"} or @{$origin->{"pending"};} or $origin->{"connecting"} or $origin->{"pumping"} or $origin->{"callback_depth"}
l!l&&r!l&&!r
251483
defined $self->{"idle_timeout"} or @{$origin->{"pending"};} or $origin->{"connecting"} or $origin->{"pumping"}
l!l&&r!l&&!r
250484
defined $self->{"idle_timeout"} or @{$origin->{"pending"};} or $origin->{"connecting"}
l!l&&r!l&&!r
250484
defined $self->{"idle_timeout"} or @{$origin->{"pending"};}
l!l&&r!l&&!r
1114484
MC/DC57%4/7
not defined $self->{"idle_timeout"} || @{$origin->{"pending"};} || $origin->{"connecting"} || $origin->{"pumping"} || $origin->{"callback_depth"} || $origin->{"scheduled"} and @{$origin->{"connections"};} == 1
defined $self->{"idle_timeout"} @{$origin->{"pending"};} $origin->{"connecting"} $origin->{"pumping"} $origin->{"callback_depth"} $origin->{'scheduled'} @{$origin->{"connections"};} == 1
Truth table62%5/8
not(A or B or C or D or E || F) and G
A= defined $self->{"idle_timeout"}B= @{$origin->{"pending"};}C= $origin->{"connecting"}D= $origin->{"pumping"}E= $origin->{"callback_depth"}F= $origin->{'scheduled'}G= @{$origin->{"connections"};} == 1
ABCDEFGresult
1XXXXXX0
01XXXXX0
001XXXX0
0001XXX0
00001XX0
000001X0
00000000
00000011
429 498 && !@{ $origin->{pending} }
430 && !$origin->{connecting}
431 && !$origin->{pumping}
432 && !$origin->{callback_depth}
433 && !$origin->{scheduled}
434 483 && @{ $origin->{connections} } == 1) {
435 418 my $conn = $origin->{connections}[0];
436 418 ▶ if ($self->_usable($conn, $op->{version}, $op)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_usable($conn, $op->{"version"}, $op)) 405 13 418
437 405 $self->_dispatch($origin, $conn, $op);
438 405 return $op;
439 }
440 }
441 104 push @{ $origin->{pending} }, $op;
442 104 $self->{pending_count}++;
443 104 $self->_pump($origin);
444 104 return $op;
445 }
446  
447 616 ▶sub _compatible {
Subroutine _compatible: called CC=3 SCAR=11.0
448 616 my ($version, $protocol) = @_;
449 616 ▶ return $protocol eq $version if $version ne 'tcp';
Branch: 1 branch
BranchTrueFalseTotal
if $version ne "tcp" 223 393 616
450 393 ▶ return $protocol eq 'h2' || $protocol eq 'http/1.1';
Condition100%3/3
$protocol eq 'h2' || $protocol eq 'http/1.1'
l!l&&r!l&&!r
1912011
MC/DC100%2/2
$protocol eq 'h2' || $protocol eq 'http/1.1'
$protocol eq 'h2' $protocol eq 'http/1.1'
Truth table100%3/3
A || B
A= $protocol eq 'h2'B= $protocol eq 'http/1.1'
ABresult
1X1
011
000
451 }
452  
453 # Connection retirement and temporary peer stream exhaustion are different.
454 # A SETTINGS limit of zero can later increase; do not close an idle H2
455 # connection merely because it cannot currently open a request.
456 1095 ▶sub _retired {
Subroutine _retired: called CC=13 SCAR=25.8
457 1095 my ($conn) = @_;
458 1095 my $engine = $conn->{engine};
459 1095 ▶ return 1 if $conn->{stale};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"stale"} 3 1092 1095
460 1092 ▶ return 1 if $conn->{protocol} eq 'http/1.1'
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"protocol"} eq "http/1.1" and $engine->can("is_switched") and $engine->is_switched 0 1092 1092
Condition83%5/6
$conn->{"protocol"} eq "http/1.1" and $engine->can("is_switched") and $engine->is_switched
!ll&&!rl&&r
108570
$conn->{"protocol"} eq "http/1.1" and $engine->can("is_switched")
!ll&&!rl&&r
6834027
MC/DC0%0/3
$conn->{"protocol"} eq "http/1.1" and $engine->can("is_switched") and $engine->is_switched
$conn->{"protocol"} eq "http/1.1" $engine->can("is_switched") $engine->is_switched
Truth table75%3/4
A and B and C
A= $conn->{"protocol"} eq "http/1.1"B= $engine->can("is_switched")C= $engine->is_switched
ABCresult
0XX0
10X0
1100
1111
461 && $engine->can('is_switched') && $engine->is_switched;
462 1092 ▶ if ($conn->{protocol} eq 'h2') {
Branch: 1 branch
BranchTrueFalseTotal
if ($conn->{"protocol"} eq "h2") 363 729 1092
463 363 ▶ return $engine->can('draining') && $engine->draining ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$engine->can('draining') && $engine->draining ? : 8 355 363
Condition100%3/3
$engine->can("draining") and $engine->draining
!ll&&!rl&&r
327288
MC/DC100%2/2
$engine->can("draining") and $engine->draining
$engine->can("draining") $engine->draining
Truth table100%3/3
A and B
A= $engine->can("draining")B= $engine->draining
ABresult
0X0
100
111
464 }
465 729 ▶ if ($conn->{protocol} eq 'h3') {
Branch: 1 branch
BranchTrueFalseTotal
if ($conn->{"protocol"} eq "h3") 320 409 729
466 320 ▶ return 1 if $engine->can('shutdown_started') && $engine->shutdown_started;
Branch: 1 branch
BranchTrueFalseTotal
if $engine->can("shutdown_started") and $engine->shutdown_started 0 320 320
Condition66%2/3
$engine->can("shutdown_started") and $engine->shutdown_started
!ll&&!rl&&r
287330
MC/DC0%0/2
$engine->can("shutdown_started") and $engine->shutdown_started
$engine->can("shutdown_started") $engine->shutdown_started
Truth table66%2/3
A and B
A= $engine->can("shutdown_started")B= $engine->shutdown_started
ABresult
0X0
100
111
467 320 ▶ return 1 if $engine->can('remote_shutdown_id')
Branch: 1 branch
BranchTrueFalseTotal
if $engine->can("remote_shutdown_id") and defined $engine->remote_shutdown_id 2 318 320
Condition100%3/3
$engine->can("remote_shutdown_id") and defined $engine->remote_shutdown_id
!ll&&!rl&&r
287312
MC/DC100%2/2
$engine->can("remote_shutdown_id") and defined $engine->remote_shutdown_id
$engine->can("remote_shutdown_id") defined $engine->remote_shutdown_id
Truth table100%3/3
A and B
A= $engine->can("remote_shutdown_id")B= defined $engine->remote_shutdown_id
ABresult
0X0
100
111
468 && defined $engine->remote_shutdown_id;
469 }
470 727 return 0;
471 }
472  
473 1101 ▶sub _closed {
Subroutine _closed: called CC=3 SCAR=11.7
474 1101 my ($conn) = @_;
475 return $conn->{protocol} eq 'h3'
476 ? ($conn->{engine}->failed || $conn->{host}->closed)
477 1101 ▶ : $conn->{engine}->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
$conn->{'protocol'} eq 'h3' ? : 320 781 1101
Condition33%1/3
$conn->{"engine"}->failed or $conn->{"host"}->closed
l!l&&r!l&&!r
00320
MC/DC0%0/2
$conn->{"engine"}->failed or $conn->{"host"}->closed
$conn->{"engine"}->failed $conn->{"host"}->closed
Truth table33%1/3
A or B
A= $conn->{"engine"}->failedB= $conn->{"host"}->closed
ABresult
1X1
011
000
478 }
479  
480 549 ▶sub _usable {
Subroutine _usable: called CC=21 SCAR=41.9
481 549 my ($self, $conn, $version, $op) = @_;
482 549 ▶ return 0 unless _compatible($version, $conn->{protocol});
Branch: 1 branch
BranchTrueFalseTotal
unless _compatible($version, $conn->{"protocol"}) 20 529 549
483 return 0 if $conn->{released} || _closed($conn) || _retired($conn)
484 529 ▶ || $conn->{credit_blocked};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"released"} or _closed($conn) or _retired($conn) or $conn->{"credit_blocked"} 11 518 529
Condition66%6/9
$conn->{"released"} or _closed($conn) or _retired($conn) or $conn->{"credit_blocked"}
l!l&&r!l&&!r
83518
$conn->{"released"} or _closed($conn) or _retired($conn)
l!l&&r!l&&!r
08521
$conn->{"released"} or _closed($conn)
l!l&&r!l&&!r
00529
MC/DC50%2/4
$conn->{"released"} or _closed($conn) or _retired($conn) or $conn->{"credit_blocked"}
$conn->{"released"} _closed($conn) _retired($conn) $conn->{"credit_blocked"}
Truth table60%3/5
A or B or C or D
A= $conn->{"released"}B= _closed($conn)C= _retired($conn)D= $conn->{"credit_blocked"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
485 518 ▶ if ($op && ($op->{websocket_connect}
Branch: 1 branch
BranchTrueFalseTotal
if ($op and $op->{"websocket_connect"} || $op->{"callbacks"}{"on_handoff"} && $version ne "http/1.1") 0 518 518
Condition33%3/9
$op and $op->{"websocket_connect"} || $op->{"callbacks"}{"on_handoff"} && $version ne "http/1.1"
!ll&&!rl&&r
05180
$op->{"websocket_connect"} or $op->{"callbacks"}{"on_handoff"} and $version ne "http/1.1"
l!l&&r!l&&!r
00518
$op->{"callbacks"}{"on_handoff"} and $version ne "http/1.1"
!ll&&!rl&&r
51800
MC/DC0%0/4
$op and $op->{"websocket_connect"} || $op->{"callbacks"}{"on_handoff"} && $version ne "http/1.1"
$op $op->{"websocket_connect"} $op->{"callbacks"}{"on_handoff"} $version ne "http/1.1"
Truth table20%1/5
A and B or C and D
A= $opB= $op->{"websocket_connect"}C= $op->{"callbacks"}{"on_handoff"}D= $version ne "http/1.1"
ABCDresult
0XXX0
100X0
10100
11XX1
10111
486 || ($op->{callbacks}{on_handoff} && $version ne 'http/1.1'))) {
487 return 0 if $version eq 'h2'
488 && (!$conn->{h2_settings_seen}
489 0 ▶ || $conn->{engine}->peer_setting('enable_connect_protocol') != 1);
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "h2" and !$conn->{"h2_settings_seen"} || $conn->{"engine"}->peer_setting("enable_connect_protocol") != 1 0 0 0
Condition0%0/6
$version eq "h2" and !$conn->{"h2_settings_seen"} || $conn->{"engine"}->peer_setting("enable_connect_protocol") != 1
!ll&&!rl&&r
000
not $conn->{"h2_settings_seen"} or $conn->{"engine"}->peer_setting("enable_connect_protocol") != 1
l!l&&r!l&&!r
000
MC/DC0%0/3
$version eq "h2" and !$conn->{"h2_settings_seen"} || $conn->{"engine"}->peer_setting("enable_connect_protocol") != 1
$version eq "h2" not $conn->{"h2_settings_seen"} $conn->{"engine"}->peer_setting("enable_connect_protocol") != 1
Truth table0%0/4
A and not(B) or C
A= $version eq "h2"B= not $conn->{"h2_settings_seen"}C= $conn->{"engine"}->peer_setting("enable_connect_protocol") != 1
ABCresult
0XX0
1000
11X1
1011
490 return 0 if $version eq 'h3'
491 && (!$conn->{engine}->peer_settings_received
492 0 ▶ || !$conn->{engine}->peer_extended_connect_enabled);
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "h3" and not $conn->{"engine"}->peer_settings_received && $conn->{"engine"}->peer_extended_connect_enabled 0 0 0
Condition0%0/6
$version eq "h3" and not $conn->{"engine"}->peer_settings_received && $conn->{"engine"}->peer_extended_connect_enabled
!ll&&!rl&&r
000
$conn->{'engine'}->peer_settings_received && $conn->{'engine'}->peer_extended_connect_enabled
!ll&&!rl&&r
000
MC/DC0%0/3
$version eq "h3" and not $conn->{"engine"}->peer_settings_received && $conn->{"engine"}->peer_extended_connect_enabled
$version eq "h3" $conn->{'engine'}->peer_settings_received $conn->{'engine'}->peer_extended_connect_enabled
Truth table0%0/4
A and not(B && C)
A= $version eq "h3"B= $conn->{'engine'}->peer_settings_receivedC= $conn->{'engine'}->peer_extended_connect_enabled
ABCresult
0XX0
1110
10X1
1101
493 }
494 my $capacity = $conn->{protocol} eq 'http/1.1'
495 518 ▶ ? 1 : $self->{limit}{max_streams_per_connection};
Branch: 1 branch
BranchTrueFalseTotal
$conn->{'protocol'} eq 'http/1.1' ? : 197 321 518
496 518 ▶ return 0 if $conn->{active} >= $capacity;
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"active"} >= $capacity 14 504 518
497 return 0 if $conn->{protocol} eq 'h2'
498 && $conn->{engine}->can('can_open_transaction')
499 504 ▶ && !$conn->{engine}->can_open_transaction;
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"protocol"} eq "h2" and $conn->{"engine"}->can("can_open_transaction") and not $conn->{"engine"}->can_open_transaction 4 500 504
Condition83%5/6
$conn->{"protocol"} eq "h2" and $conn->{"engine"}->can("can_open_transaction") and not $conn->{"engine"}->can_open_transaction
!ll&&!rl&&r
3391614
$conn->{"protocol"} eq "h2" and $conn->{"engine"}->can("can_open_transaction")
!ll&&!rl&&r
3390165
MC/DC66%2/3
$conn->{"protocol"} eq "h2" and $conn->{"engine"}->can("can_open_transaction") and not $conn->{"engine"}->can_open_transaction
$conn->{"protocol"} eq "h2" $conn->{"engine"}->can("can_open_transaction") not $conn->{"engine"}->can_open_transaction
Truth table75%3/4
A and B and not(C)
A= $conn->{"protocol"} eq "h2"B= $conn->{"engine"}->can("can_open_transaction")C= not $conn->{"engine"}->can_open_transaction
ABCresult
0XX0
10X0
1100
1111
500 500 return 1;
501 }
502  
503 # A pooled transport is released once. The framework may own the socket
504 # and its close semantics, so allow its adapter to perform final cleanup.
505 24 ▶sub _cancel_idle {
Subroutine _cancel_idle: called CC=3 SCAR=11.0
506 24 my ($self, $conn) = @_;
507 24 $conn->{idle_generation}++;
508 24 ▶ my $cancel = delete $conn->{idle_cancel} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $cancel = delete $conn->{"idle_cancel"} or return 3 21 24
509 3 ▶ eval { $cancel->(); 1 } or warn "idle timer cancellation failed: $@";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { &$cancel(); 1 } } or warn "idle timer cancellation failed: $@" 3 0 3
510 3 return;
511 }
512  
513 21 ▶sub _release_connection {
Subroutine _release_connection: called CC=6 SCAR=18.2
514 21 my ($self, $conn, $reason) = @_;
515 21 ▶ return if $conn->{released};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"released"} 0 21 21
516 21 $conn->{released} = 1;
517 21 $self->_cancel_idle($conn);
518 21 my $release = $self->{factory}{release_connection};
519 21 my $ok = eval {
520 21 ▶ if ($release) {
Branch: 3 branches
BranchTrueFalseTotal
if ($release) { } 11 10 21
elsif ($conn->{'engine'}->can('close')) { } 9 1 10
elsif ($conn->{'host'}->can('close')) { } 0 1 1
521 11 $release->($conn->{host}, $conn->{engine}, $conn->{protocol}, $reason);
522 } elsif ($conn->{engine}->can('close')) {
523 9 $conn->{engine}->close;
524 } elsif ($conn->{host}->can('close')) {
525 # Current HTTP/3 Client has no close(), but Net::QUIC does.
526 0 $conn->{host}->close;
527 }
528 21 1;
529 };
530 21 ▶ warn "connection release failed: $@" unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 21 21
531 21 return;
532 }
533  
534 7 ▶sub _drop_connection {
Subroutine _drop_connection: called CC=2 SCAR=7.0
535 7 my ($self, $pool, $conn, $reason) = @_;
536 7 ▶ return if $conn->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"active"} 0 7 7
537 $pool->{connections} = [
538 7 grep { $_ != $conn } @{ $pool->{connections} }
539 ];
540 7 $self->_release_connection($conn, $reason);
541 7 $self->_delete_empty_pool($pool);
542 7 return;
543 }
544  
545 203 ▶sub _delete_empty_pool {
Subroutine _delete_empty_pool: called CC=6 SCAR=18.1
546 203 my ($self, $pool) = @_;
547 return if $pool->{connecting}
548 203 ▶ || @{ $pool->{pending} } || @{ $pool->{connections} };
Branch: 1 branch
BranchTrueFalseTotal
if $pool->{"connecting"} or @{$pool->{"pending"};} or @{$pool->{"connections"};} 185 18 203
Condition100%6/6
$pool->{"connecting"} or @{$pool->{"pending"};} or @{$pool->{"connections"};}
l!l&&r!l&&!r
909518
$pool->{"connecting"} or @{$pool->{"pending"};}
l!l&&r!l&&!r
6426113
MC/DC100%3/3
$pool->{"connecting"} or @{$pool->{"pending"};} or @{$pool->{"connections"};}
$pool->{"connecting"} @{$pool->{"pending"};} @{$pool->{"connections"};}
Truth table100%4/4
A or B or C
A= $pool->{"connecting"}B= @{$pool->{"pending"};}C= @{$pool->{"connections"};}
ABCresult
1XX1
01X1
0011
0000
549 18 my $key = $pool->{info}{key};
550 delete $self->{pools}{$key}
551 if exists $self->{pools}{$key}
552 18 ▶ && $self->{pools}{$key} == $pool;
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"pools"}{$key} and $self->{"pools"}{$key} == $pool 18 0 18
Condition33%1/3
exists $self->{"pools"}{$key} and $self->{"pools"}{$key} == $pool
!ll&&!rl&&r
0018
MC/DC0%0/2
exists $self->{"pools"}{$key} and $self->{"pools"}{$key} == $pool
exists $self->{"pools"}{$key} $self->{"pools"}{$key} == $pool
Truth table33%1/3
A and B
A= exists $self->{"pools"}{$key}B= $self->{"pools"}{$key} == $pool
ABresult
0X0
100
111
553 18 return;
554 }
555  
556 366 ▶sub _sync_idle {
Subroutine _sync_idle: called CC=11 SCAR=24.5
557 366 my ($self, $pool) = @_;
558 366 my $idle_timeout = $self->{idle_timeout};
559 366 ▶ return unless defined $idle_timeout;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $idle_timeout 324 42 366
560 42 ▶ my $waiting = $pool->{connecting} || @{ $pool->{pending} };
Condition100%3/3
$pool->{'connecting'} || @{$pool->{'pending'};}
l!l&&r!l&&!r
11328
MC/DC100%2/2
$pool->{'connecting'} || @{$pool->{'pending'};}
$pool->{'connecting'} @{$pool->{'pending'};}
Truth table100%3/3
A || B
A= $pool->{'connecting'}B= @{$pool->{'pending'};}
ABresult
1X1
011
000
561 42 for my $conn (@{ $pool->{connections} }) {
562 33 ▶ if ($waiting || $conn->{active} || $conn->{released}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($waiting or $conn->{"active"} or $conn->{"released"}) 17 16 33
Condition83%5/6
$waiting or $conn->{"active"} or $conn->{"released"}
l!l&&r!l&&!r
17016
$waiting or $conn->{"active"}
l!l&&r!l&&!r
51216
MC/DC66%2/3
$waiting or $conn->{"active"} or $conn->{"released"}
$waiting $conn->{"active"} $conn->{"released"}
Truth table75%3/4
A or B or C
A= $waitingB= $conn->{"active"}C= $conn->{"released"}
ABCresult
1XX1
01X1
0011
0000
563 17 ▶ $self->_cancel_idle($conn) if $conn->{idle_cancel};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"idle_cancel"} 1 16 17
564 17 next;
565 }
566 16 ▶ next if $conn->{idle_cancel};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"idle_cancel"} 8 8 16
567 8 my $generation = ++$conn->{idle_generation};
568 8 my $weak_self = $self;
569 8 my $weak_pool = $pool;
570 8 my $weak_conn = $conn;
571 8 weaken($weak_self);
572 8 weaken($weak_pool);
573 8 weaken($weak_conn);
574 8 my $ok = eval {
575 my $cancel = $self->{factory}{schedule_timer}->(
576 $idle_timeout,
577 9 ▶ sub {
Subroutine __ANON__: called CC=9 SCAR=24.8
578 9 ▶ return unless $weak_self && $weak_pool && $weak_conn;
Branch: 1 branch
BranchTrueFalseTotal
unless $weak_self and $weak_pool and $weak_conn 3 6 9
Condition66%4/6
$weak_self and $weak_pool and $weak_conn
!ll&&!rl&&r
306
$weak_self and $weak_pool
!ll&&!rl&&r
036
MC/DC33%1/3
$weak_self and $weak_pool and $weak_conn
$weak_self $weak_pool $weak_conn
Truth table50%2/4
A and B and C
A= $weak_selfB= $weak_poolC= $weak_conn
ABCresult
0XX0
10X0
1100
1111
579 6 ▶ return unless $weak_conn->{idle_generation} == $generation;
Branch: 1 branch
BranchTrueFalseTotal
unless $weak_conn->{"idle_generation"} == $generation 1 5 6
580 5 delete $weak_conn->{idle_cancel};
581 return if $weak_conn->{released}
582 || $weak_conn->{active}
583 || $weak_pool->{connecting}
584 5 ▶ || @{ $weak_pool->{pending} };
Branch: 1 branch
BranchTrueFalseTotal
if $weak_conn->{"released"} or $weak_conn->{"active"} or $weak_pool->{"connecting"} or @{$weak_pool->{"pending"};} 0 5 5
Condition33%3/9
$weak_conn->{"released"} or $weak_conn->{"active"} or $weak_pool->{"connecting"} or @{$weak_pool->{"pending"};}
l!l&&r!l&&!r
005
$weak_conn->{"released"} or $weak_conn->{"active"} or $weak_pool->{"connecting"}
l!l&&r!l&&!r
005
$weak_conn->{"released"} or $weak_conn->{"active"}
l!l&&r!l&&!r
005
MC/DC0%0/4
$weak_conn->{"released"} or $weak_conn->{"active"} or $weak_pool->{"connecting"} or @{$weak_pool->{"pending"};}
$weak_conn->{"released"} $weak_conn->{"active"} $weak_pool->{"connecting"} @{$weak_pool->{"pending"};}
Truth table20%1/5
A or B or C or D
A= $weak_conn->{"released"}B= $weak_conn->{"active"}C= $weak_pool->{"connecting"}D= @{$weak_pool->{"pending"};}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
585 5 $weak_self->_drop_connection(
586 $weak_pool, $weak_conn, 'idle_timeout',
587 );
588 },
589 8 );
590 8 ▶ die "schedule_timer must return cancellation coderef\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cancel eq "CODE" 0 8 8
591 unless ref($cancel) eq 'CODE';
592 8 $conn->{idle_cancel} = $cancel;
593 8 1;
594 };
595 8 ▶ warn "idle timer setup failed: $@" unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 8 8
596 }
597 42 return;
598 }
599  
600 220 ▶sub _pump {
Subroutine _pump: called CC=39 SCAR=48.1
601 220 my ($self, $pool) = @_;
602 220 ▶ return if $self->{shutdown};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"shutdown"} 0 220 220
603 # Application on_finish can synchronously enqueue another request.
604 # Wait for the engine terminal callback to unwind before reusing H1.
605 220 ▶ return if $pool->{pumping} || $pool->{callback_depth};
Branch: 1 branch
BranchTrueFalseTotal
if $pool->{"pumping"} or $pool->{"callback_depth"} 37 183 220
Condition100%3/3
$pool->{"pumping"} or $pool->{"callback_depth"}
l!l&&r!l&&!r
361183
MC/DC100%2/2
$pool->{"pumping"} or $pool->{"callback_depth"}
$pool->{"pumping"} $pool->{"callback_depth"}
Truth table100%3/3
A or B
A= $pool->{"pumping"}B= $pool->{"callback_depth"}
ABresult
1X1
011
000
606 183 local $pool->{pumping} = 1;
607 183 my $attempt_budget = $self->{limit}{max_connections_per_origin};
608 183 my @kept;
609 183 for my $conn (@{ $pool->{connections} }) {
610 101 ▶ if ($conn->{active} || (!_closed($conn) && !_retired($conn))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conn->{'active'} or not _closed($conn) || _retired($conn)) { } 95 6 101
Condition100%6/6
$conn->{"active"} or not _closed($conn) || _retired($conn)
l!l&&r!l&&!r
10856
_closed($conn) || _retired($conn)
l!l&&r!l&&!r
2485
MC/DC100%3/3
$conn->{"active"} or not _closed($conn) || _retired($conn)
$conn->{"active"} _closed($conn) _retired($conn)
Truth table100%4/4
A or not(B || C)
A= $conn->{"active"}B= _closed($conn)C= _retired($conn)
ABCresult
1XX1
0001
01X0
0010
611 95 push @kept, $conn;
612 } else {
613 $self->_release_connection($conn,
614 _closed($conn) ? 'closed'
615 6 ▶ : $conn->{stale} ? 'network_changed' : 'draining');
Branch: 2 branches
BranchTrueFalseTotal
_closed($conn) ? : 2 4 6
$conn->{'stale'} ? : 1 3 4
616 }
617 }
618 183 $pool->{connections} = \@kept;
619 # Pending demand is not idle, even if the peer temporarily offers no
620 # H2/H3 request stream credit.
621 183 $self->_sync_idle($pool);
622 183 ▶ while (@{ $pool->{pending} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$pool->{"pending"};}) 213 97 310
623 213 my $op = $pool->{pending}[0];
624 213 ▶ if ($op->is_terminal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op->is_terminal) 0 213 213
625 0 shift @{ $pool->{pending} };
626 0 $self->{pending_count}--;
627 0 next;
628 }
629 # Extended CONNECT is only legal after current peer SETTINGS.
630 # Wait on an existing protocol connection without opening more
631 # sockets. If its peer explicitly disables Extended CONNECT,
632 # reject this unsent operation rather than downgrading/replaying.
633 213 ▶ if (($op->{websocket_connect}
Branch: 1 branch
BranchTrueFalseTotal
if ($op->{"websocket_connect"} || $op->{"callbacks"}{"on_handoff"} and $op->{"version"} eq "h2" || $op->{"version"} eq "h3") 0 213 213
Condition22%2/9
$op->{"websocket_connect"} || $op->{"callbacks"}{"on_handoff"} and $op->{"version"} eq "h2" || $op->{"version"} eq "h3"
!ll&&!rl&&r
21300
$op->{"websocket_connect"} or $op->{"callbacks"}{"on_handoff"}
l!l&&r!l&&!r
00213
$op->{"version"} eq "h2" or $op->{"version"} eq "h3"
l!l&&r!l&&!r
000
MC/DC0%0/4
$op->{"websocket_connect"} || $op->{"callbacks"}{"on_handoff"} and $op->{"version"} eq "h2" || $op->{"version"} eq "h3"
$op->{"websocket_connect"} $op->{"callbacks"}{"on_handoff"} $op->{"version"} eq "h2" $op->{"version"} eq "h3"
Truth table14%1/7
A or B and C or D
A= $op->{"websocket_connect"}B= $op->{"callbacks"}{"on_handoff"}C= $op->{"version"} eq "h2"D= $op->{"version"} eq "h3"
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
634 || $op->{callbacks}{on_handoff})
635 && ($op->{version} eq 'h2' || $op->{version} eq 'h3')) {
636 0 my $version = $op->{version};
637 my @existing = grep {
638 $_->{protocol} eq $version && !$_->{released}
639 0 ▶ && !_closed($_) && !_retired($_)
Condition0%0/9
$_->{'protocol'} eq $version && !$_->{'released'} && !_closed($_) && !_retired($_)
!ll&&!rl&&r
000
$_->{"protocol"} eq $version and not $_->{"released"} and not _closed($_)
!ll&&!rl&&r
000
$_->{"protocol"} eq $version and not $_->{"released"}
!ll&&!rl&&r
000
MC/DC0%0/4
$_->{'protocol'} eq $version && !$_->{'released'} && !_closed($_) && !_retired($_)
$_->{"protocol"} eq $version not $_->{"released"} not _closed($_) !_retired($_)
Truth table0%0/5
A and not(B) and not(C) && not(D)
A= $_->{"protocol"} eq $versionB= not $_->{"released"}C= not _closed($_)D= !_retired($_)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
640 0 } @{ $pool->{connections} };
641 0 ▶ my $ready = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
642 0 my ($conn) = @_;
643 return $version eq 'h2'
644 ? ($conn->{h2_settings_seen}
645 && $conn->{engine}->peer_setting(
646 'enable_connect_protocol') == 1)
647 : ($conn->{engine}->peer_settings_received
648 0 ▶ && $conn->{engine}->peer_extended_connect_enabled);
Branch: 1 branch
BranchTrueFalseTotal
$version eq 'h2' ? : 0 0 0
Condition0%0/6
$conn->{"h2_settings_seen"} and $conn->{"engine"}->peer_setting("enable_connect_protocol") == 1
!ll&&!rl&&r
000
$conn->{"engine"}->peer_settings_received and $conn->{"engine"}->peer_extended_connect_enabled
!ll&&!rl&&r
000
MC/DC0%0/2
$conn->{"h2_settings_seen"} and $conn->{"engine"}->peer_setting("enable_connect_protocol") == 1
$conn->{"h2_settings_seen"} $conn->{"engine"}->peer_setting("enable_connect_protocol") == 1
MC/DC0%0/2
$conn->{"engine"}->peer_settings_received and $conn->{"engine"}->peer_extended_connect_enabled
$conn->{"engine"}->peer_settings_received $conn->{"engine"}->peer_extended_connect_enabled
Truth table0%0/3
A and B
A= $conn->{"h2_settings_seen"}B= $conn->{"engine"}->peer_setting("enable_connect_protocol") == 1
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $conn->{"engine"}->peer_settings_receivedB= $conn->{"engine"}->peer_extended_connect_enabled
ABresult
0X0
100
111
649 0 };
650 0 ▶ if (@existing && !grep { $ready->($_) } @existing) {
Branch: 1 branch
BranchTrueFalseTotal
if (@existing and not grep({&$ready($_);} @existing)) 0 0 0
Condition0%0/3
@existing and not grep({&$ready($_);} @existing)
!ll&&!rl&&r
000
MC/DC0%0/2
@existing and not grep({&$ready($_);} @existing)
@existing not grep({&$ready($_);} @existing)
Truth table0%0/3
A and not(B)
A= @existingB= not grep({&$ready($_);} @existing)
ABresult
0X0
100
111
651 last if grep {
652 0 ▶ $version eq 'h2' ? !$_->{h2_settings_seen}
Branch: 1 branch
BranchTrueFalseTotal
if grep {$version eq "h2" ? !$_->{"h2_settings_seen"} : !$_->{"engine"}->peer_settings_received;} @existing 0 0 0
653 : !$_->{engine}->peer_settings_received
654 0 ▶ } @existing;
Branch: 1 branch
BranchTrueFalseTotal
$version eq 'h2' ? : 0 0 0
655 0 shift @{ $pool->{pending} };
656 0 $self->{pending_count}--;
657 $self->_fail_pending(
658 $pool, $op, 'peer has not enabled HTTP/'
659 . ($version eq 'h2' ? '2' : '3')
660 . ($op->{websocket_connect}
661 0 ▶ ? ' WebSocket Extended CONNECT'
Branch: 2 branches
BranchTrueFalseTotal
$version eq 'h2' ? : 0 0 0
$op->{'websocket_connect'} ? : 0 0 0
662 : ' generic Extended CONNECT'),
663 );
664 0 next;
665 }
666 }
667 131 my ($conn) = grep { $self->_usable($_, $op->{version}, $op) }
668 213 @{ $pool->{connections} };
669 213 ▶ if ($conn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conn) 95 118 213
670 # Existing stream credit can recover while another connector
671 # is still negotiating for this same queued request. Release
672 # the now-unneeded factory before dispatching the request.
673 $self->_abandon_connect($pool, $op)
674 95 ▶ if $pool->{attempt} && $pool->{attempt}{op} == $op;
Branch: 1 branch
BranchTrueFalseTotal
if $pool->{"attempt"} and $pool->{"attempt"}{"op"} == $op 2 93 95
Condition66%2/3
$pool->{"attempt"} and $pool->{"attempt"}{"op"} == $op
!ll&&!rl&&r
9302
MC/DC50%1/2
$pool->{"attempt"} and $pool->{"attempt"}{"op"} == $op
$pool->{"attempt"} $pool->{"attempt"}{"op"} == $op
Truth table66%2/3
A and B
A= $pool->{"attempt"}B= $pool->{"attempt"}{"op"} == $op
ABresult
0X0
100
111
675 95 shift @{ $pool->{pending} };
676 95 $self->{pending_count}--;
677 95 ▶ last unless $self->_dispatch($pool, $conn, $op);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_dispatch($pool, $conn, $op) 4 91 95
678 91 next;
679 }
680 118 ▶ last if $pool->{connecting};
Branch: 1 branch
BranchTrueFalseTotal
if $pool->{"connecting"} 12 106 118
681 106 ▶ if (@{ $pool->{connections} } >= $self->{limit}{max_connections_per_origin}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$pool->{"connections"};} >= $self->{"limit"}{"max_connections_per_origin"}) 20 86 106
682 # Never strand a strict request behind an idle, unusable engine.
683 20 ▶ for (my $i = 0; $i < @{ $pool->{connections} }; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$pool->{"connections"};}) 20 17 37
684 20 my $idle = $pool->{connections}[$i];
685 20 ▶ next if $idle->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $idle->{"active"} 13 7 20
686 my $unusable = !_compatible($op->{version}, $idle->{protocol})
687 7 ▶ || _closed($idle) || _retired($idle);
Condition83%5/6
!_compatible($op->{'version'}, $idle->{'protocol'}) || _closed($idle) || _retired($idle)
l!l&&r!l&&!r
214
not _compatible($op->{"version"}, $idle->{"protocol"}) or _closed($idle)
l!l&&r!l&&!r
205
MC/DC66%2/3
!_compatible($op->{'version'}, $idle->{'protocol'}) || _closed($idle) || _retired($idle)
not _compatible($op->{"version"}, $idle->{"protocol"}) _closed($idle) _retired($idle)
Truth table75%3/4
not(A) or B || C
A= not _compatible($op->{"version"}, $idle->{"protocol"})B= _closed($idle)C= _retired($idle)
ABCresult
1XX1
01X1
0011
0000
688 7 ▶ next unless $unusable;
Branch: 1 branch
BranchTrueFalseTotal
unless $unusable 4 3 7
689 3 splice @{ $pool->{connections} }, $i, 1;
690 3 $self->_release_connection($idle, 'evicted');
691 3 last;
692 }
693 }
694 106 ▶ last if @{ $pool->{connections} } >= $self->{limit}{max_connections_per_origin};
Branch: 1 branch
BranchTrueFalseTotal
if @{$pool->{"connections"};} >= $self->{"limit"}{"max_connections_per_origin"} 17 89 106
695 # A synchronous factory can produce a connection that immediately
696 # refuses streams. Never spin forever creating/replacing engines.
697 89 ▶ last unless $attempt_budget--;
Branch: 1 branch
BranchTrueFalseTotal
unless $attempt_budget-- 1 88 89
698 88 $self->_connect($pool, $op);
699 88 ▶ last if $pool->{connecting};
Branch: 1 branch
BranchTrueFalseTotal
if $pool->{"connecting"} 52 36 88
700 }
701 183 $self->_sync_idle($pool);
702 183 $self->_delete_empty_pool($pool);
703 }
704  
705 88 ▶sub _connect {
Subroutine _connect: called CC=13 SCAR=26.3
706 88 my ($self, $pool, $op) = @_;
707 88 my $version = $op->{version};
708 88 my $quic = $version eq 'h3';
709 88 my $alt = $op->{alt_svc};
710 88 ▶ my $factory = $self->{factory}{ $quic ? 'connect_quic' : 'connect_stream' };
Branch: 1 branch
BranchTrueFalseTotal
$quic ? : 19 69 88
711 88 my $attempt = { op => $op, cancelled => 0, completed => 0 };
712 88 $pool->{connecting} = 1;
713 88 $pool->{attempt} = $attempt;
714 88 $op->{state} = 'connecting';
715 88 my $called = 0;
716 86 ▶ my $ready = sub {
Subroutine __ANON__: called CC=8 SCAR=20.9
717 86 ▶ return if $called++;
Branch: 1 branch
BranchTrueFalseTotal
if $called++ 1 85 86
718 # A cancelled/timed-out factory must not attach its late transport.
719 85 ▶ return unless $pool->{attempt} && $pool->{attempt} == $attempt;
Branch: 1 branch
BranchTrueFalseTotal
unless $pool->{"attempt"} and $pool->{"attempt"} == $attempt 8 77 85
Condition100%3/3
$pool->{"attempt"} and $pool->{"attempt"} == $attempt
!ll&&!rl&&r
4477
MC/DC100%2/2
$pool->{"attempt"} and $pool->{"attempt"} == $attempt
$pool->{"attempt"} $pool->{"attempt"} == $attempt
Truth table100%3/3
A and B
A= $pool->{"attempt"}B= $pool->{"attempt"} == $attempt
ABresult
0X0
100
111
720 77 $attempt->{completed} = 1;
721 77 delete $pool->{attempt};
722 77 $pool->{connecting} = 0;
723 77 my %result = @_;
724 77 my $engine;
725 77 my $ok = eval { $engine = $self->_connected($pool, $op, $version, \%result); 1 };
726 77 ▶ if (!$ok) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $ok) { } 3 74 77
elsif (not $op->is_terminal || $op->{'transaction'}) { } 74 0 74
727 3 my $error = "$@";
728 3 ▶ if (!$self->_fallback_alternative($pool, $op, $error)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_fallback_alternative($pool, $op, $error)) 1 2 3
729 1 $self->_fail_pending($pool, $op, $error);
730 }
731 ▶ } elsif (!$op->is_terminal && !$op->{transaction}) {
Condition33%1/3
$op->is_terminal || $op->{'transaction'}
l!l&&r!l&&!r
0074
MC/DC0%0/2
$op->is_terminal || $op->{'transaction'}
$op->is_terminal $op->{'transaction'}
Truth table33%1/3
A || B
A= $op->is_terminalB= $op->{'transaction'}
ABresult
1X1
011
000
732 # Connection establishment is complete. Waiting for peer stream
733 # credit is queued work, not another connection in progress.
734 74 $op->{state} = 'queued';
735 }
736 77 $self->_pump($pool);
737 77 return $engine;
738 88 };
739 88 ▶ my @alpn = $version eq 'tcp'
Branch: 2 branches
BranchTrueFalseTotal
$version eq 'tcp' ? : 51 37 88
$version eq 'h3' ? : 19 18 37
740 ? $self->alpn_protocols : ($version eq 'h3' ? ('h3') : ($version));
741 88 my $cancel;
742 88 my $ok = eval {
743 88 ▶ if ($quic) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quic) { } 19 69 88
744 19 my $info = $pool->{info};
745 19 ▶ if ($alt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($alt) 5 14 19
746 # The HTTP origin is unchanged. Only the UDP target differs.
747 $info = { %$info,
748 alternative_host => $info->{host},
749 alternative_port => $alt->{port},
750 5 };
751 }
752 19 $cancel = $factory->($info, $ready);
753 } else {
754 69 $cancel = $factory->($pool->{info}, \@alpn, $ready);
755 }
756 88 1;
757 };
758 88 ▶ if (ref($cancel) eq 'CODE' && !$attempt->{completed}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cancel eq "CODE" and not $attempt->{"completed"}) 15 73 88
Condition66%2/3
ref $cancel eq "CODE" and not $attempt->{"completed"}
!ll&&!rl&&r
73015
MC/DC50%1/2
ref $cancel eq "CODE" and not $attempt->{"completed"}
ref $cancel eq "CODE" not $attempt->{"completed"}
Truth table66%2/3
A and not(B)
A= ref $cancel eq "CODE"B= not $attempt->{"completed"}
ABresult
0X0
100
111
759 15 ▶ if ($attempt->{cancelled}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attempt->{'cancelled'}) { } 0 15 15
760 0 ▶ eval { $cancel->(); 1 } or warn "connection cancellation failed: $@";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { &$cancel(); 1 } } or warn "connection cancellation failed: $@" 0 0 0
761 } else {
762 15 $attempt->{cancel} = $cancel;
763 }
764 }
765 88 ▶ $ready->(error => "$@") unless $ok || $called || $attempt->{cancelled};
Branch: 1 branch
BranchTrueFalseTotal
unless $ok or $called or $attempt->{"cancelled"} 0 88 88
Condition33%2/6
$ok or $called or $attempt->{"cancelled"}
l!l&&r!l&&!r
8800
$ok or $called
l!l&&r!l&&!r
8800
MC/DC0%0/3
$ok or $called or $attempt->{"cancelled"}
$ok $called $attempt->{"cancelled"}
Truth table25%1/4
A or B or C
A= $okB= $calledC= $attempt->{"cancelled"}
ABCresult
1XX1
01X1
0011
0000
766 }
767  
768 # A pending request may abandon its own factory without holding the origin
769 # hostage. The framework may return a cancellation callback from the factory.
770 19 ▶sub _abandon_connect {
Subroutine _abandon_connect: called CC=5 SCAR=16.2
771 19 my ($self, $pool, $op) = @_;
772 19 ▶ my $attempt = $pool->{attempt} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $attempt = $pool->{"attempt"} or return 11 8 19
773 11 ▶ return unless $attempt->{op} == $op;
Branch: 1 branch
BranchTrueFalseTotal
unless $attempt->{"op"} == $op 0 11 11
774 11 delete $pool->{attempt};
775 11 $pool->{connecting} = 0;
776 11 $attempt->{cancelled} = 1;
777 11 ▶ if (my $cancel = delete $attempt->{cancel}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cancel = delete $attempt->{"cancel"}) 9 2 11
778 9 ▶ eval { $cancel->(); 1 } or warn "connection cancellation failed: $@";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { &$cancel(); 1 } } or warn "connection cancellation failed: $@" 9 0 9
779 }
780 11 return;
781 }
782  
783 6 ▶sub _request_timeout {
Subroutine _request_timeout: called CC=3 SCAR=11.0
784 6 my ($self, $op, $seconds) = @_;
785 6 ▶ return if $op->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $op->is_terminal 2 4 6
786 4 my $error = "request timed out after $seconds seconds";
787 4 ▶ if (my $tx = $op->{transaction}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tx = $op->{"transaction"}) 1 3 4
788 # Engine cancellation preserves protocol-specific stream isolation.
789 # The operation separately reports expiration as a timeout error.
790 1 $op->{timeout_error} = $error;
791 1 $tx->cancel;
792 1 return;
793 }
794 3 $self->_fail_pending($op->{origin}, $op, $error);
795 3 $self->_schedule($op->{origin});
796 3 return;
797 }
798  
799 77 ▶sub _connected {
Subroutine _connected: called CC=31 SCAR=43.7
800 77 my ($self, $pool, $op, $version, $result) = @_;
801 77 ▶ die "$result->{error}" if defined($result->{error}) && length($result->{error});
Branch: 1 branch
BranchTrueFalseTotal
if defined $result->{"error"} and length $result->{"error"} 2 75 77
Condition66%2/3
defined $result->{"error"} and length $result->{"error"}
!ll&&!rl&&r
7502
MC/DC50%1/2
defined $result->{"error"} and length $result->{"error"}
defined $result->{"error"} length $result->{"error"}
Truth table66%2/3
A and B
A= defined $result->{"error"}B= length $result->{"error"}
ABresult
0X0
100
111
802 75 my ($protocol, $host, %arg);
803 75 ▶ if ($version eq 'h3') {
Branch: 1 branch
BranchTrueFalseTotal
if ($version eq 'h3') { } 15 60 75
804 15 $protocol = 'h3';
805 15 $host = $result->{connection};
806 15 ▶ die "connect_quic: expected a ready QUIC connection\n"
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($host) and $host->can("ready") and $host->can("closed") and $host->ready and not $host->closed 0 15 15
Condition33%4/12
builtin::blessed($host) and $host->can("ready") and $host->can("closed") and $host->ready and not $host->closed
!ll&&!rl&&r
0015
builtin::blessed($host) and $host->can("ready") and $host->can("closed") and $host->ready
!ll&&!rl&&r
0015
builtin::blessed($host) and $host->can("ready") and $host->can("closed")
!ll&&!rl&&r
0015
builtin::blessed($host) and $host->can("ready")
!ll&&!rl&&r
0015
MC/DC0%0/5
builtin::blessed($host) and $host->can("ready") and $host->can("closed") and $host->ready and not $host->closed
builtin::blessed($host) $host->can("ready") $host->can("closed") $host->ready not $host->closed
Truth table16%1/6
A and B and C and D and not(E)
A= builtin::blessed($host)B= $host->can("ready")C= $host->can("closed")D= $host->readyE= not $host->closed
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
807 unless blessed($host) && $host->can('ready') && $host->can('closed')
808 && $host->ready && !$host->closed;
809 die "connect_quic: alternative must authenticate the original HTTPS origin\n"
810 if $op->{alt_svc}
811 && !(defined($result->{verified_origin})
812 && !ref($result->{verified_origin})
813 15 ▶ && $result->{verified_origin} eq '1');
Branch: 1 branch
BranchTrueFalseTotal
if $op->{"alt_svc"} and not defined $result->{"verified_origin"} && !ref($result->{"verified_origin"}) && $result->{"verified_origin"} eq 1 1 14 15
Condition77%7/9
$op->{"alt_svc"} and not defined $result->{"verified_origin"} && !ref($result->{"verified_origin"}) && $result->{"verified_origin"} eq 1
!ll&&!rl&&r
1221
defined $result->{'verified_origin'} && !ref($result->{'verified_origin'}) && $result->{'verified_origin'} eq '1'
!ll&&!rl&&r
102
defined $result->{"verified_origin"} and not ref $result->{"verified_origin"}
!ll&&!rl&&r
102
MC/DC50%2/4
$op->{"alt_svc"} and not defined $result->{"verified_origin"} && !ref($result->{"verified_origin"}) && $result->{"verified_origin"} eq 1
$op->{"alt_svc"} defined $result->{"verified_origin"} not ref $result->{"verified_origin"} $result->{'verified_origin'} eq '1'
Truth table60%3/5
A and not(B and not(C) && D)
A= $op->{"alt_svc"}B= defined $result->{"verified_origin"}C= not ref $result->{"verified_origin"}D= $result->{'verified_origin'} eq '1'
ABCDresult
0XXX0
11110
10XX1
110X1
11101
814 14 %arg = (quic => $host);
815 } else {
816 $protocol = defined($result->{alpn}) && length($result->{alpn})
817 60 ▶ ? $result->{alpn} : 'http/1.1';
Branch: 1 branch
BranchTrueFalseTotal
defined $result->{'alpn'} && length $result->{'alpn'} ? : 40 20 60
Condition66%2/3
defined $result->{"alpn"} and length $result->{"alpn"}
!ll&&!rl&&r
20040
MC/DC50%1/2
defined $result->{"alpn"} and length $result->{"alpn"}
defined $result->{"alpn"} length $result->{"alpn"}
Truth table66%2/3
A and B
A= defined $result->{"alpn"}B= length $result->{"alpn"}
ABresult
0X0
100
111
818 die "connect_stream: negotiated unsupported or disabled protocol\n"
819 unless ($protocol eq 'h2' || $protocol eq 'http/1.1')
820 60 ▶ && $self->{policy}->enabled($protocol)
Branch: 1 branch
BranchTrueFalseTotal
unless $protocol eq "h2" || $protocol eq "http/1.1" and $self->{"policy"}->enabled($protocol) and _compatible($version, $protocol) 0 60 60
Condition44%4/9
$protocol eq "h2" || $protocol eq "http/1.1" and $self->{"policy"}->enabled($protocol) and _compatible($version, $protocol)
!ll&&!rl&&r
0060
$protocol eq "h2" || $protocol eq "http/1.1" and $self->{"policy"}->enabled($protocol)
!ll&&!rl&&r
0060
$protocol eq "h2" or $protocol eq "http/1.1"
l!l&&r!l&&!r
21390
MC/DC0%0/4
$protocol eq "h2" || $protocol eq "http/1.1" and $self->{"policy"}->enabled($protocol) and _compatible($version, $protocol)
$protocol eq "h2" $protocol eq "http/1.1" $self->{"policy"}->enabled($protocol) _compatible($version, $protocol)
Truth table28%2/7
A or B and C and D
A= $protocol eq "h2"B= $protocol eq "http/1.1"C= $self->{"policy"}->enabled($protocol)D= _compatible($version, $protocol)
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
821 && _compatible($version, $protocol);
822 60 $host = $result->{transport};
823 60 ▶ die "connect_stream: transport must implement unblock_send, unblock_finish and unblock_abort\n"
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($host) and $host->can("unblock_send") and $host->can("unblock_finish") and $host->can("unblock_abort") 0 60 60
Condition33%3/9
builtin::blessed($host) and $host->can("unblock_send") and $host->can("unblock_finish") and $host->can("unblock_abort")
!ll&&!rl&&r
0060
builtin::blessed($host) and $host->can("unblock_send") and $host->can("unblock_finish")
!ll&&!rl&&r
0060
builtin::blessed($host) and $host->can("unblock_send")
!ll&&!rl&&r
0060
MC/DC0%0/4
builtin::blessed($host) and $host->can("unblock_send") and $host->can("unblock_finish") and $host->can("unblock_abort")
builtin::blessed($host) $host->can("unblock_send") $host->can("unblock_finish") $host->can("unblock_abort")
Truth table20%1/5
A and B and C and D
A= builtin::blessed($host)B= $host->can("unblock_send")C= $host->can("unblock_finish")D= $host->can("unblock_abort")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
824 unless blessed($host)
825 && $host->can('unblock_send')
826 && $host->can('unblock_finish')
827 && $host->can('unblock_abort');
828 60 %arg = (transport => $host);
829 }
830 74 my $options = $self->{policy}->options($protocol);
831 # These advertise Server capabilities; Client constructors reject them.
832 74 ▶ delete $options->{enable_connect_protocol} if $protocol eq 'h2';
Branch: 1 branch
BranchTrueFalseTotal
if $protocol eq "h2" 21 53 74
833 74 ▶ delete $options->{enable_extended_connect} if $protocol eq 'h3';
Branch: 1 branch
BranchTrueFalseTotal
if $protocol eq "h3" 14 60 74
834 my $conn = {
835 host => $host, protocol => $protocol, active => 0,
836 credit_blocked => 0,
837 verified_origin =>
838 (defined($result->{verified_origin})
839 && !ref($result->{verified_origin})
840 74 ▶ && $result->{verified_origin} eq '1') ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
defined $result->{'verified_origin'} && !ref($result->{'verified_origin'}) && $result->{'verified_origin'} eq '1' ? : 8 66 74
Condition66%4/6
defined $result->{"verified_origin"} and not ref $result->{"verified_origin"} and $result->{"verified_origin"} eq 1
!ll&&!rl&&r
6608
defined $result->{"verified_origin"} and not ref $result->{"verified_origin"}
!ll&&!rl&&r
6608
MC/DC33%1/3
defined $result->{"verified_origin"} and not ref $result->{"verified_origin"} and $result->{"verified_origin"} eq 1
defined $result->{"verified_origin"} not ref $result->{"verified_origin"} $result->{"verified_origin"} eq 1
Truth table50%2/4
A and not(B) and C
A= defined $result->{"verified_origin"}B= not ref $result->{"verified_origin"}C= $result->{"verified_origin"} eq 1
ABCresult
0XX0
10X0
1100
1111
841 };
842 74 my $weak_self = $self;
843 74 my $weak_pool = $pool;
844 74 my $weak_conn = $conn;
845 74 weaken($weak_self);
846 74 weaken($weak_pool);
847 74 weaken($weak_conn);
848 74 ▶ if ($protocol eq 'h2') {
Branch: 2 branches
BranchTrueFalseTotal
if ($protocol eq 'h2') { } 21 53 74
elsif ($protocol eq 'h3') { } 14 39 53
849 # A peer may raise its advertised stream limit later.
850 1 ▶ $options->{on_settings} = sub {
Subroutine __ANON__: called CC=4 SCAR=17.1
851 1 ▶ return unless $weak_self && $weak_pool && $weak_conn;
Branch: 1 branch
BranchTrueFalseTotal
unless $weak_self and $weak_pool and $weak_conn 0 1 1
Condition33%2/6
$weak_self and $weak_pool and $weak_conn
!ll&&!rl&&r
001
$weak_self and $weak_pool
!ll&&!rl&&r
001
MC/DC0%0/3
$weak_self and $weak_pool and $weak_conn
$weak_self $weak_pool $weak_conn
Truth table25%1/4
A and B and C
A= $weak_selfB= $weak_poolC= $weak_conn
ABCresult
0XX0
10X0
1100
1111
852 1 $weak_conn->{h2_settings_seen} = 1;
853 1 $weak_self->_schedule($weak_pool);
854 21 };
855 } elsif ($protocol eq 'h3') {
856 # The H3 engine exclusively owns Net::QUIC's availability callback.
857 # A failed-to-open bidi stream causes this one-shot notification.
858 4 ▶ $options->{on_request_available} = sub {
Subroutine __ANON__: called CC=4 SCAR=17.1
859 4 ▶ return unless $weak_self && $weak_pool && $weak_conn;
Branch: 1 branch
BranchTrueFalseTotal
unless $weak_self and $weak_pool and $weak_conn 0 4 4
Condition33%2/6
$weak_self and $weak_pool and $weak_conn
!ll&&!rl&&r
004
$weak_self and $weak_pool
!ll&&!rl&&r
004
MC/DC0%0/3
$weak_self and $weak_pool and $weak_conn
$weak_self $weak_pool $weak_conn
Truth table25%1/4
A and B and C
A= $weak_selfB= $weak_poolC= $weak_conn
ABCresult
0XX0
10X0
1100
1111
860 4 $weak_conn->{credit_blocked} = 0;
861 4 $weak_self->_schedule($weak_pool);
862 14 };
863 {
864 # All H3 Clients can submit protocol-neutral CONNECT requests.
865 # Notify queued operations after peer SETTINGS arrives, even
866 # without WebSocket policy. Do not enter the native callback.
867 14 ▶ $options->{on_extension_settings} = sub {
Subroutine __ANON__: not called CC=6 SCAR=36.0
868 0 ▶ return unless $weak_self && $weak_pool && $weak_conn;
Branch: 1 branch
BranchTrueFalseTotal
unless $weak_self and $weak_pool and $weak_conn 0 0 0
Condition0%0/6
$weak_self and $weak_pool and $weak_conn
!ll&&!rl&&r
000
$weak_self and $weak_pool
!ll&&!rl&&r
000
MC/DC0%0/3
$weak_self and $weak_pool and $weak_conn
$weak_self $weak_pool $weak_conn
Truth table0%0/4
A and B and C
A= $weak_selfB= $weak_poolC= $weak_conn
ABCresult
0XX0
10X0
1100
1111
869 # SETTINGS matters to CONNECT admission only. Do not
870 # spuriously pump ordinary H3 operations or launch an
871 # additional speculative connection during stream-credit
872 # recovery.
873 return unless grep {
874 $_->{websocket_connect}
875 || $_->{callbacks}{on_handoff}
876 0 ▶ } @{ $weak_pool->{pending} };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_->{"websocket_connect"} or $_->{"callbacks"}{"on_handoff"};} @{$$weak_pool{"pending"};} 0 0 0
Condition0%0/3
$_->{'websocket_connect'} || $_->{'callbacks'}{'on_handoff'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$_->{'websocket_connect'} || $_->{'callbacks'}{'on_handoff'}
$_->{'websocket_connect'} $_->{'callbacks'}{'on_handoff'}
Truth table0%0/3
A || B
A= $_->{'websocket_connect'}B= $_->{'callbacks'}{'on_handoff'}
ABresult
1X1
011
000
877 0 $weak_self->_schedule($weak_pool);
878 14 };
879 }
880 }
881 74 my $engine = Unblock::HTTP::_EngineFactory->create(
882 'Client', $protocol, %$options, %arg,
883 );
884 74 ▶ $engine->start if $protocol eq 'h3';
Branch: 1 branch
BranchTrueFalseTotal
if $protocol eq "h3" 14 60 74
885 74 $conn->{engine} = $engine;
886 74 push @{ $pool->{connections} }, $conn;
887 74 return $engine;
888 }
889  
890 # Alternative connection failure before dispatch is safe to recover from:
891 # the engine never saw this request. Once dispatched, no retry is automatic.
892 3 ▶sub _fallback_alternative {
Subroutine _fallback_alternative: called CC=9 SCAR=23.7
893 3 my ($self, $pool, $op, $error) = @_;
894 return 0 unless $op->{alt_svc} && !$op->{transaction}
895 && !$op->is_terminal
896 3 ▶ && ($self->{policy}->enabled('http/1.1') || $self->{policy}->enabled('h2'));
Branch: 1 branch
BranchTrueFalseTotal
unless $op->{"alt_svc"} and not $op->{"transaction"} and not $op->is_terminal and $self->{"policy"}->enabled("http/1.1") || $self->{"policy"}->enabled("h2") 1 2 3
Condition58%7/12
$op->{"alt_svc"} and not $op->{"transaction"} and not $op->is_terminal and $self->{"policy"}->enabled("http/1.1") || $self->{"policy"}->enabled("h2")
!ll&&!rl&&r
102
$op->{"alt_svc"} and not $op->{"transaction"} and not $op->is_terminal
!ll&&!rl&&r
102
$op->{"alt_svc"} and not $op->{"transaction"}
!ll&&!rl&&r
102
$self->{"policy"}->enabled("http/1.1") or $self->{"policy"}->enabled("h2")
l!l&&r!l&&!r
200
MC/DC20%1/5
$op->{"alt_svc"} and not $op->{"transaction"} and not $op->is_terminal and $self->{"policy"}->enabled("http/1.1") || $self->{"policy"}->enabled("h2")
$op->{"alt_svc"} not $op->{"transaction"} not $op->is_terminal $self->{"policy"}->enabled("http/1.1") $self->{"policy"}->enabled("h2")
Truth table33%2/6
A and not(B) and not(C) and D or E
A= $op->{"alt_svc"}B= not $op->{"transaction"}C= not $op->is_terminalD= $self->{"policy"}->enabled("http/1.1")E= $self->{"policy"}->enabled("h2")
ABCDEresult
0XXXX0
10XXX0
110XX0
111000
1111X1
111011
897 2 $self->{alt_svc}->invalidate($op->{origin}{info}{key});
898 2 for my $pending (@{ $pool->{pending} }) {
899 2 ▶ next unless $pending->{alt_svc} && !$pending->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
unless $pending->{"alt_svc"} and not $pending->is_terminal 0 2 2
Condition33%1/3
$pending->{"alt_svc"} and not $pending->is_terminal
!ll&&!rl&&r
002
MC/DC0%0/2
$pending->{"alt_svc"} and not $pending->is_terminal
$pending->{"alt_svc"} not $pending->is_terminal
Truth table33%1/3
A and not(B)
A= $pending->{"alt_svc"}B= not $pending->is_terminal
ABresult
0X0
100
111
900 2 delete $pending->{alt_svc};
901 2 $pending->{version} = 'tcp';
902 2 $pending->{state} = 'queued';
903 }
904 2 return 1;
905 }
906  
907 13 ▶sub _learn_alt_svc {
Subroutine _learn_alt_svc: called CC=5 SCAR=16.5
908 13 my ($self, $pool, $conn, $response) = @_;
909 13 ▶ return if $conn->{stale};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"stale"} 0 13 13
910 return unless $conn->{verified_origin}
911 && $pool->{info}{scheme} eq 'https'
912 13 ▶ && $self->{policy}->enabled('h3');
Branch: 1 branch
BranchTrueFalseTotal
unless $conn->{"verified_origin"} and $pool->{"info"}{"scheme"} eq "https" and $self->{"policy"}->enabled("h3") 3 10 13
Condition66%4/6
$conn->{"verified_origin"} and $pool->{"info"}{"scheme"} eq "https" and $self->{"policy"}->enabled("h3")
!ll&&!rl&&r
3010
$conn->{"verified_origin"} and $pool->{"info"}{"scheme"} eq "https"
!ll&&!rl&&r
3010
MC/DC33%1/3
$conn->{"verified_origin"} and $pool->{"info"}{"scheme"} eq "https" and $self->{"policy"}->enabled("h3")
$conn->{"verified_origin"} $pool->{"info"}{"scheme"} eq "https" $self->{"policy"}->enabled("h3")
Truth table50%2/4
A and B and C
A= $conn->{"verified_origin"}B= $pool->{"info"}{"scheme"} eq "https"C= $self->{"policy"}->enabled("h3")
ABCresult
0XX0
10X0
1100
1111
913 10 $self->{alt_svc}->observe($pool->{info}{key}, $response);
914 10 return;
915 }
916  
917 500 ▶sub _dispatch {
Subroutine _dispatch: called CC=50 SCAR=63.3
918 500 my ($self, $pool, $conn, $op) = @_;
919 500 ▶ $self->_cancel_idle($conn) if $conn->{idle_cancel};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"idle_cancel"} 0 500 500
920 500 $conn->{active}++;
921 500 $op->{state} = 'active';
922 # The Client owns in-flight operations even if the caller discards its
923 # handle. Transaction callbacks must not own the operation or pool:
924 # once terminal, that would retain the Transaction through a cycle.
925 500 my $op_id = refaddr($op);
926 500 $self->{active_operations}{$op_id} = $op;
927 500 my ($weak_self, $weak_pool, $weak_conn, $weak_op) =
928 ($self, $pool, $conn, $op);
929 500 weaken($weak_self);
930 500 weaken($weak_pool);
931 500 weaken($weak_conn);
932 500 weaken($weak_op);
933 500 my $callbacks = $op->{callbacks};
934 500 my $ws_spec = $op->{websocket_connect};
935 500 my %engine_callback;
936 500 ▶ $engine_callback{on_data} = $callbacks->{on_data} if $callbacks->{on_data};
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks->{"on_data"} 2 498 500
937 $engine_callback{on_informational} = $callbacks->{on_informational}
938 500 ▶ if $callbacks->{on_informational};
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks->{"on_informational"} 0 500 500
939 $engine_callback{on_drain} = $callbacks->{on_drain}
940 500 ▶ if $callbacks->{on_drain};
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks->{"on_drain"} 0 500 500
941  
942 # Alt-Svc discovery only affects later TCP-first requests. A Client
943 # configured for H3 alone can never consult the alternative cache;
944 # avoid allocating and running an unused per-response observer there.
945 500 ▶ if ($pool->{info}{scheme} eq 'https'
Branch: 2 branches
BranchTrueFalseTotal
if ($pool->{'info'}{'scheme'} eq 'https' and $self->{'policy'}->enabled('h3') and $self->{'policy'}->enabled('h2') || $self->{'policy'}->enabled('http/1.1')) { } 16 484 500
elsif ($callbacks->{'on_response'} and $callbacks->{'on_data'}) { } 2 961 963
Condition100%9/9
$pool->{"info"}{"scheme"} eq "https" and $self->{"policy"}->enabled("h3") and $self->{"policy"}->enabled("h2") || $self->{"policy"}->enabled("http/1.1")
!ll&&!rl&&r
33514916
$pool->{"info"}{"scheme"} eq "https" and $self->{"policy"}->enabled("h3")
!ll&&!rl&&r
39296165
$self->{"policy"}->enabled("h2") or $self->{"policy"}->enabled("http/1.1")
l!l&&r!l&&!r
142149
MC/DC100%4/4
$pool->{"info"}{"scheme"} eq "https" and $self->{"policy"}->enabled("h3") and $self->{"policy"}->enabled("h2") || $self->{"policy"}->enabled("http/1.1")
$pool->{"info"}{"scheme"} eq "https" $self->{"policy"}->enabled("h3") $self->{"policy"}->enabled("h2") $self->{"policy"}->enabled("http/1.1")
Truth table100%5/5
A and B and C or D
A= $pool->{"info"}{"scheme"} eq "https"B= $self->{"policy"}->enabled("h3")C= $self->{"policy"}->enabled("h2")D= $self->{"policy"}->enabled("http/1.1")
ABCDresult
0XXX0
10XX0
11000
111X1
11011
946 && $self->{policy}->enabled('h3')
947 && ($self->{policy}->enabled('h2')
948 || $self->{policy}->enabled('http/1.1'))) {
949 # Once per response headers, not on the body hot path.
950 13 ▶ $engine_callback{on_response} = sub {
Subroutine __ANON__: called CC=6 SCAR=23.5
951 13 my ($tx, $response) = @_;
952 13 ▶ $weak_self->_learn_alt_svc($weak_pool, $weak_conn, $response)
Branch: 1 branch
BranchTrueFalseTotal
if $weak_self and $weak_pool and $weak_conn 13 0 13
Condition33%2/6
$weak_self and $weak_pool and $weak_conn
!ll&&!rl&&r
0013
$weak_self and $weak_pool
!ll&&!rl&&r
0013
MC/DC0%0/3
$weak_self and $weak_pool and $weak_conn
$weak_self $weak_pool $weak_conn
Truth table25%1/4
A and B and C
A= $weak_selfB= $weak_poolC= $weak_conn
ABCresult
0XX0
10X0
1100
1111
953 if $weak_self && $weak_pool && $weak_conn;
954 $callbacks->{on_response}->($tx, $response)
955 13 ▶ if $callbacks->{on_data} && $callbacks->{on_response};
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks->{"on_data"} and $callbacks->{"on_response"} 0 13 13
Condition33%1/3
$callbacks->{"on_data"} and $callbacks->{"on_response"}
!ll&&!rl&&r
1300
MC/DC0%0/2
$callbacks->{"on_data"} and $callbacks->{"on_response"}
$callbacks->{"on_data"} $callbacks->{"on_response"}
Truth table33%1/3
A and B
A= $callbacks->{"on_data"}B= $callbacks->{"on_response"}
ABresult
0X0
100
111
956 16 };
957 ▶ } elsif ($callbacks->{on_response} && $callbacks->{on_data}) {
Condition100%3/3
$callbacks->{"on_response"} and $callbacks->{"on_data"}
!ll&&!rl&&r
47932
MC/DC100%2/2
$callbacks->{"on_response"} and $callbacks->{"on_data"}
$callbacks->{"on_response"} $callbacks->{"on_data"}
Truth table100%3/3
A and B
A= $callbacks->{"on_response"}B= $callbacks->{"on_data"}
ABresult
0X0
100
111
958 2 $engine_callback{on_response} = $callbacks->{on_response};
959 }
960 500 ▶ if ($callbacks->{on_response} || ($callbacks->{on_end} && $callbacks->{on_data})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($callbacks->{"on_response"} or $callbacks->{"on_end"} and $callbacks->{"on_data"}) 6 494 500
Condition50%3/6
$callbacks->{"on_response"} or $callbacks->{"on_end"} and $callbacks->{"on_data"}
l!l&&r!l&&!r
60494
$callbacks->{"on_end"} and $callbacks->{"on_data"}
!ll&&!rl&&r
49400
MC/DC33%1/3
$callbacks->{"on_response"} or $callbacks->{"on_end"} and $callbacks->{"on_data"}
$callbacks->{"on_response"} $callbacks->{"on_end"} $callbacks->{"on_data"}
Truth table50%2/4
A or B and C
A= $callbacks->{"on_response"}B= $callbacks->{"on_end"}C= $callbacks->{"on_data"}
ABCresult
1XX1
0111
00X0
0100
961 6 ▶ $engine_callback{on_complete} = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
962 6 my ($tx) = @_;
963 6 ▶ if ($callbacks->{on_data}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($callbacks->{'on_data'}) { } 2 4 6
964 2 ▶ $callbacks->{on_end}->($tx) if $callbacks->{on_end};
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks->{"on_end"} 1 1 2
965 } else {
966 $callbacks->{on_response}->($tx, $tx->response)
967 4 ▶ if $callbacks->{on_response};
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks->{"on_response"} 4 0 4
968 }
969 6 };
970 }
971 500 ▶ if ($callbacks->{on_error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($callbacks->{"on_error"}) 10 490 500
972 10 $engine_callback{on_error} = $callbacks->{on_error};
973 }
974 500 ▶ if ($ws_spec && ($conn->{protocol} eq 'h2'
Branch: 2 branches
BranchTrueFalseTotal
if ($ws_spec and $conn->{'protocol'} eq 'h2' || $conn->{'protocol'} eq 'h3') { } 0 500 500
elsif ($ws_spec) { } 0 500 500
Condition16%1/6
$ws_spec and $conn->{"protocol"} eq "h2" || $conn->{"protocol"} eq "h3"
!ll&&!rl&&r
50000
$conn->{"protocol"} eq "h2" or $conn->{"protocol"} eq "h3"
l!l&&r!l&&!r
000
MC/DC0%0/3
$ws_spec and $conn->{"protocol"} eq "h2" || $conn->{"protocol"} eq "h3"
$ws_spec $conn->{"protocol"} eq "h2" $conn->{"protocol"} eq "h3"
Truth table25%1/4
A and B or C
A= $ws_specB= $conn->{"protocol"} eq "h2"C= $conn->{"protocol"} eq "h3"
ABCresult
0XX0
1000
11X1
1011
975 || $conn->{protocol} eq 'h3')) {
976 # Unlike HTTP1, a WebSocket occupies one multiplexed H2/H3 stream.
977 # Its normal transaction lifetime remains active until END_STREAM.
978 # No host socket takeover or HTTP pool detachment is performed.
979 0 ▶ $engine_callback{on_response} = sub {
Subroutine __ANON__: not called CC=10 SCAR=47.0
980 0 my ($tx, $response) = @_;
981 # A rejected H3 handshake must not throw out of Net::QUIC's
982 # receive dispatch. Defer a reset of this stream only.
983 0 my $valid = eval {
984 0 $ws_spec->{handshake}->validate_client_response($response);
985 0 1;
986 };
987 0 ▶ if (!$valid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($valid) 0 0 0
988 0 ▶ die $@ if $conn->{protocol} ne 'h3';
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"protocol"} ne "h3" 0 0 0
989 0 ▶ my $active_op = $weak_op or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_op = $weak_op or return 0 0 0
990 $active_op->{websocket_handshake_error} =
991 0 ▶ "$@" || 'HTTP3 WebSocket handshake failed';
Condition0%0/2
"$@" || 'HTTP3 WebSocket handshake failed'
l!l
00
MC/DC0%0/1
"$@" || 'HTTP3 WebSocket handshake failed'
"$@"
Truth table0%0/2
A
A= "$@"
Aresult
11
00
992 0 ▶ my $active_self = $weak_self or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_self = $weak_self or return 0 0 0
993 0 ▶ $active_self->{factory}{defer}->(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
994 0 ▶ $tx->cancel unless $tx->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
unless $tx->is_terminal 0 0 0
995 0 });
996 0 return;
997 }
998 0 require Unblock::HTTP::_WebSocketH2Body;
999 0 require Unblock::WebSocket::Client;
1000 0 ▶ my $active_op = $weak_op or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_op = $weak_op or return 0 0 0
1001 0 ▶ my $active_self = $weak_self or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_self = $weak_self or return 0 0 0
1002 my $bridge = Unblock::HTTP::_WebSocketH2Body->new(
1003 transaction => $tx, defer => $active_self->{factory}{defer},
1004 0 );
1005 my $ws = Unblock::WebSocket::Client->new(
1006 0 %{ $ws_spec->{handshake}->connection_options },
1007 0 ▶ %{ $ws_spec->{options} },
Branch: 1 branch
BranchTrueFalseTotal
$callbacks->{'on_error'} ? : 0 0 0
1008 transport => $bridge,
1009 ($callbacks->{on_error}
1010 0 ? (on_error => $callbacks->{on_error}) : ()),
1011 );
1012 0 $bridge->websocket($ws);
1013 0 $active_op->{websocket} = $ws;
1014 0 $active_op->{websocket_bridge} = $bridge;
1015 $ws_spec->{on_open}->($ws, $tx)
1016 0 ▶ if $ws_spec->{on_open};
Branch: 1 branch
BranchTrueFalseTotal
if $ws_spec->{"on_open"} 0 0 0
1017 0 };
1018 0 ▶ $engine_callback{on_data} = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
1019 0 ▶ my $active_op = $weak_op or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_op = $weak_op or return 0 0 0
1020 # An H3 rejection may carry an ordinary HTTP error body.
1021 # Discard it after validation has failed; it is not framed
1022 # WebSocket DATA and must not unwind the QUIC receive call.
1023 0 ▶ return if $active_op->{websocket_handshake_error};
Branch: 1 branch
BranchTrueFalseTotal
if $active_op->{"websocket_handshake_error"} 0 0 0
1024 my $ws = $active_op->{websocket}
1025 0 ▶ or die 'multiplexed WebSocket DATA arrived before validated response';
Branch: 1 branch
BranchTrueFalseTotal
my $ws = $active_op->{"websocket"} or die "multiplexed WebSocket DATA arrived before validated response" 0 0 0
1026 0 $ws->input($_[1]);
1027 0 };
1028 0 ▶ $engine_callback{on_drain} = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
1029 0 ▶ my $active_op = $weak_op or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_op = $weak_op or return 0 0 0
1030 0 ▶ my $bridge = $active_op->{websocket_bridge} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $bridge = $active_op->{"websocket_bridge"} or return 0 0 0
1031 0 $bridge->resume;
1032 0 };
1033 0 ▶ $engine_callback{on_complete} = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
1034 0 ▶ my $active_op = $weak_op or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_op = $weak_op or return 0 0 0
1035 0 ▶ my $ws = $active_op->{websocket} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $ws = $active_op->{"websocket"} or return 0 0 0
1036 0 ▶ $ws->input_eof if !$ws->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if not $ws->is_closed 0 0 0
1037 0 };
1038 }
1039 elsif ($ws_spec) {
1040 # Validation must happen before HTTP1 yields its byte-stream.
1041 # Invalid 101 replies and ordinary HTTP rejection responses are
1042 # failed handshakes, not successful established WebSockets.
1043 0 ▶ $engine_callback{on_response} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1044 0 my ($tx, $response) = @_;
1045 0 $ws_spec->{handshake}->validate_client_response($response);
1046 0 };
1047 0 ▶ $engine_callback{on_switch} = sub {
Subroutine __ANON__: not called CC=11 SCAR=48.8
1048 0 my ($tx, $response) = @_;
1049 0 ▶ my $active_self = $weak_self or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_self = $weak_self or return 0 0 0
1050 0 ▶ my $active_pool = $weak_pool or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_pool = $weak_pool or return 0 0 0
1051 0 ▶ my $active_conn = $weak_conn or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_conn = $weak_conn or return 0 0 0
1052 0 ▶ my $active_op = $weak_op or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_op = $weak_op or return 0 0 0
1053 local $active_pool->{callback_depth} =
1054 0 ▶ ($active_pool->{callback_depth} || 0) + 1;
Condition0%0/2
$active_pool->{'callback_depth'} || 0
l!l
00
MC/DC0%0/1
$active_pool->{'callback_depth'} || 0
$active_pool->{'callback_depth'}
Truth table0%0/2
A
A= $active_pool->{'callback_depth'}
Aresult
11
00
1055 0 my $host = $active_conn->{host};
1056 0 ▶ croak 'connect_websocket(): transport must implement unblock_upgrade()'
Branch: 1 branch
BranchTrueFalseTotal
unless $host->can("unblock_upgrade") 0 0 0
1057 unless $host->can('unblock_upgrade');
1058  
1059 0 require Unblock::WebSocket::Client;
1060 my $ws = Unblock::WebSocket::Client->new(
1061 0 %{ $ws_spec->{handshake}->connection_options },
1062 0 ▶ %{ $ws_spec->{options} },
Branch: 1 branch
BranchTrueFalseTotal
$callbacks->{'on_error'} ? : 0 0 0
1063 transport => $host,
1064 ($callbacks->{on_error}
1065 0 ? (on_error => $callbacks->{on_error}) : ()),
1066 );
1067 # The framework changes the input owner synchronously, while
1068 # leaving its ordered write queue and the socket unchanged.
1069 0 $host->unblock_upgrade($ws);
1070 0 $active_op->{websocket} = $ws;
1071 # Keep the detached pool bookkeeping alive only until HTTP1
1072 # invokes on_finish immediately after this on_switch callback.
1073 # The ordinary callback closure intentionally holds weak refs.
1074 0 $active_op->{upgrade_retirement} = [$active_pool, $active_conn];
1075 0 $active_conn->{released} = 1; # transferred, never close by pool
1076 $active_self->_cancel_idle($active_conn)
1077 0 ▶ if $active_conn->{idle_cancel};
Branch: 1 branch
BranchTrueFalseTotal
if $active_conn->{"idle_cancel"} 0 0 0
1078 $active_pool->{connections} = [
1079 0 grep { $_ != $active_conn } @{ $active_pool->{connections} }
1080 ];
1081 $ws_spec->{on_open}->($ws, $tx)
1082 0 ▶ if $ws_spec->{on_open};
Branch: 1 branch
BranchTrueFalseTotal
if $ws_spec->{"on_open"} 0 0 0
1083 0 my $tail = $active_conn->{engine}->take_remainder;
1084 0 ▶ $ws->input($tail) if length $tail;
Branch: 1 branch
BranchTrueFalseTotal
if length $tail 0 0 0
1085 0 };
1086 }
1087 500 ▶ if ($callbacks->{on_handoff} && !$ws_spec
Branch: 1 branch
BranchTrueFalseTotal
if ($callbacks->{"on_handoff"} and not $ws_spec and $conn->{"protocol"} eq "h2" || $conn->{"protocol"} eq "h3") 0 500 500
Condition22%2/9
$callbacks->{"on_handoff"} and not $ws_spec and $conn->{"protocol"} eq "h2" || $conn->{"protocol"} eq "h3"
!ll&&!rl&&r
50000
$callbacks->{"on_handoff"} and not $ws_spec
!ll&&!rl&&r
50000
$conn->{"protocol"} eq "h2" or $conn->{"protocol"} eq "h3"
l!l&&r!l&&!r
000
MC/DC0%0/4
$callbacks->{"on_handoff"} and not $ws_spec and $conn->{"protocol"} eq "h2" || $conn->{"protocol"} eq "h3"
$callbacks->{"on_handoff"} not $ws_spec $conn->{"protocol"} eq "h2" $conn->{"protocol"} eq "h3"
Truth table20%1/5
A and not(B) and C or D
A= $callbacks->{"on_handoff"}B= not $ws_specC= $conn->{"protocol"} eq "h2"D= $conn->{"protocol"} eq "h3"
ABCDresult
0XXX0
10XX0
11000
111X1
11011
1088 && ($conn->{protocol} eq 'h2' || $conn->{protocol} eq 'h3')) {
1089 0 ▶ $engine_callback{on_response} = sub {
Subroutine __ANON__: not called CC=10 SCAR=47.0
1090 0 my ($tx, $response) = @_;
1091 0 ▶ if ($response->status < 200 || $response->status >= 300) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->status < 200 or $response->status >= 300) 0 0 0
Condition0%0/3
$response->status < 200 or $response->status >= 300
l!l&&r!l&&!r
000
MC/DC0%0/2
$response->status < 200 or $response->status >= 300
$response->status < 200 $response->status >= 300
Truth table0%0/3
A or B
A= $response->status < 200B= $response->status >= 300
ABresult
1X1
011
000
1092 $callbacks->{on_response}->($tx, $response)
1093 0 ▶ if $callbacks->{on_response};
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks->{"on_response"} 0 0 0
1094 # This request has an open producer for successful
1095 # full-duplex CONNECT. When the peer rejects it, send
1096 # request FIN on a later turn so the HTTP response can
1097 # complete normally. Never write from a receive callback.
1098 0 ▶ my $active_self = $weak_self or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_self = $weak_self or return 0 0 0
1099 0 ▶ $active_self->{factory}{defer}->(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1100 0 ▶ $tx->end unless $tx->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
unless $tx->is_terminal 0 0 0
1101 0 });
1102 0 return;
1103 }
1104 0 ▶ my $active_op = $weak_op or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_op = $weak_op or return 0 0 0
1105 0 ▶ my $active_self = $weak_self or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_self = $weak_self or return 0 0 0
1106 0 require Unblock::HTTP::_WebSocketH2Body;
1107 my $bridge = Unblock::HTTP::_WebSocketH2Body->new(
1108 transaction => $tx, defer => $active_self->{factory}{defer},
1109 0 );
1110 0 my $consumer = $callbacks->{on_handoff}->(
1111 $tx, $response, $bridge,
1112 );
1113 0 ▶ croak 'on_handoff must return a stream consumer'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($consumer) 0 0 0
1114 unless blessed($consumer);
1115 0 for my $method (qw(input input_eof transport_error resume_output)) {
1116 0 ▶ croak "on_handoff stream consumer must implement $method()"
Branch: 1 branch
BranchTrueFalseTotal
unless $consumer->can($method) 0 0 0
1117 unless $consumer->can($method);
1118 }
1119 0 $bridge->consumer($consumer);
1120 0 $active_op->{handoff_consumer} = $consumer;
1121 0 $active_op->{handoff_bridge} = $bridge;
1122 0 };
1123 0 ▶ $engine_callback{on_data} = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
1124 0 ▶ my $active_op = $weak_op or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_op = $weak_op or return 0 0 0
1125 0 ▶ my $consumer = $active_op->{handoff_consumer} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $consumer = $active_op->{"handoff_consumer"} or return 0 0 0
1126 0 $consumer->input($_[1]);
1127 0 };
1128 0 ▶ $engine_callback{on_drain} = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
1129 0 ▶ my $active_op = $weak_op or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_op = $weak_op or return 0 0 0
1130 0 ▶ my $bridge = $active_op->{handoff_bridge} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $bridge = $active_op->{"handoff_bridge"} or return 0 0 0
1131 0 $bridge->resume;
1132 0 };
1133 0 ▶ $engine_callback{on_complete} = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
1134 0 ▶ my $active_op = $weak_op or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_op = $weak_op or return 0 0 0
1135 0 my $consumer = $active_op->{handoff_consumer};
1136 0 ▶ $consumer->input_eof if $consumer;
Branch: 1 branch
BranchTrueFalseTotal
if $consumer 0 0 0
1137 0 ▶ $callbacks->{on_end}->($_[0]) if $callbacks->{on_end};
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks->{"on_end"} 0 0 0
1138 0 };
1139 }
1140 500 ▶ if ($callbacks->{on_handoff} && !$ws_spec
Branch: 1 branch
BranchTrueFalseTotal
if ($callbacks->{"on_handoff"} and not $ws_spec and $conn->{"protocol"} eq "http/1.1") 0 500 500
Condition33%2/6
$callbacks->{"on_handoff"} and not $ws_spec and $conn->{"protocol"} eq "http/1.1"
!ll&&!rl&&r
50000
$callbacks->{"on_handoff"} and not $ws_spec
!ll&&!rl&&r
50000
MC/DC0%0/3
$callbacks->{"on_handoff"} and not $ws_spec and $conn->{"protocol"} eq "http/1.1"
$callbacks->{"on_handoff"} not $ws_spec $conn->{"protocol"} eq "http/1.1"
Truth table25%1/4
A and not(B) and C
A= $callbacks->{"on_handoff"}B= not $ws_specC= $conn->{"protocol"} eq "http/1.1"
ABCresult
0XX0
10X0
1100
1111
1141 && $conn->{protocol} eq 'http/1.1') {
1142 # A generic H1 101/CONNECT transfer retires the entire socket from
1143 # the HTTP pool. The successor inherits the transport and remainder.
1144 0 ▶ $engine_callback{on_switch} = sub {
Subroutine __ANON__: not called CC=12 SCAR=50.5
1145 0 my ($tx, $response) = @_;
1146 0 ▶ my $active_self = $weak_self or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_self = $weak_self or return 0 0 0
1147 0 ▶ my $active_pool = $weak_pool or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_pool = $weak_pool or return 0 0 0
1148 0 ▶ my $active_conn = $weak_conn or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_conn = $weak_conn or return 0 0 0
1149 0 ▶ my $active_op = $weak_op or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_op = $weak_op or return 0 0 0
1150 local $active_pool->{callback_depth} =
1151 0 ▶ ($active_pool->{callback_depth} || 0) + 1;
Condition0%0/2
$active_pool->{'callback_depth'} || 0
l!l
00
MC/DC0%0/1
$active_pool->{'callback_depth'} || 0
$active_pool->{'callback_depth'}
Truth table0%0/2
A
A= $active_pool->{'callback_depth'}
Aresult
11
00
1152 0 my $host = $active_conn->{host};
1153 0 ▶ croak 'request(): on_handoff requires unblock_upgrade()'
Branch: 1 branch
BranchTrueFalseTotal
unless $host->can("unblock_upgrade") 0 0 0
1154 unless $host->can('unblock_upgrade');
1155 0 my $successor = $callbacks->{on_handoff}->($tx, $response, $host);
1156 0 ▶ croak 'request(): on_handoff must return a successor consumer'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($successor) 0 0 0
1157 unless blessed($successor);
1158 0 for my $method (qw(input input_eof transport_error resume_output)) {
1159 0 ▶ croak "request(): on_handoff successor must implement $method()"
Branch: 1 branch
BranchTrueFalseTotal
unless $successor->can($method) 0 0 0
1160 unless $successor->can($method);
1161 }
1162 0 $host->unblock_upgrade($successor);
1163 0 $active_op->{upgrade_retirement} = [$active_pool, $active_conn];
1164 0 $active_conn->{released} = 1;
1165 $active_self->_cancel_idle($active_conn)
1166 0 ▶ if $active_conn->{idle_cancel};
Branch: 1 branch
BranchTrueFalseTotal
if $active_conn->{"idle_cancel"} 0 0 0
1167 $active_pool->{connections} = [
1168 0 grep { $_ != $active_conn } @{ $active_pool->{connections} }
1169 ];
1170 0 my $tail = $active_conn->{engine}->take_remainder;
1171 0 ▶ $successor->input($tail) if length $tail;
Branch: 1 branch
BranchTrueFalseTotal
if length $tail 0 0 0
1172 0 };
1173 }
1174 495 ▶ $engine_callback{on_finish} = sub {
Subroutine __ANON__: called CC=41 SCAR=45.0
1175 495 my ($tx) = @_;
1176 495 ▶ my $active_op = $weak_op or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_op = $weak_op or return 495 0 495
1177 495 ▶ return if $active_op->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $active_op->is_terminal 0 495 495
1178 495 my $upgrade_retirement = delete $active_op->{upgrade_retirement};
1179 495 ▶ my ($active_self, $active_pool, $active_conn) =
Condition16%2/12
$weak_pool || $upgrade_retirement && $upgrade_retirement->[0]
l!l&&r!l&&!r
49500
$upgrade_retirement and $upgrade_retirement->[0]
!ll&&!rl&&r
000
$weak_conn || $upgrade_retirement && $upgrade_retirement->[1]
l!l&&r!l&&!r
49500
$upgrade_retirement and $upgrade_retirement->[1]
!ll&&!rl&&r
000
MC/DC0%0/3
$weak_pool || $upgrade_retirement && $upgrade_retirement->[0]
$weak_pool $upgrade_retirement $upgrade_retirement->[0]
MC/DC0%0/3
$weak_conn || $upgrade_retirement && $upgrade_retirement->[1]
$weak_conn $upgrade_retirement $upgrade_retirement->[1]
Truth table25%1/4
A || B and C
A= $weak_poolB= $upgrade_retirementC= $upgrade_retirement->[0]
ABCresult
1XX1
0111
00X0
0100
Truth table25%1/4
A || B and C
A= $weak_connB= $upgrade_retirementC= $upgrade_retirement->[1]
ABCresult
1XX1
0111
00X0
0100
1180 ($weak_self,
1181 $weak_pool || ($upgrade_retirement && $upgrade_retirement->[0]),
1182 $weak_conn || ($upgrade_retirement && $upgrade_retirement->[1]));
1183 495 ▶ return unless $active_self && $active_pool && $active_conn;
Branch: 1 branch
BranchTrueFalseTotal
unless $active_self and $active_pool and $active_conn 0 495 495
Condition33%2/6
$active_self and $active_pool and $active_conn
!ll&&!rl&&r
00495
$active_self and $active_pool
!ll&&!rl&&r
00495
MC/DC0%0/3
$active_self and $active_pool and $active_conn
$active_self $active_pool $active_conn
Truth table25%1/4
A and B and C
A= $active_selfB= $active_poolC= $active_conn
ABCresult
0XX0
10X0
1100
1111
1184 local $active_pool->{callback_depth} =
1185 495 ▶ ($active_pool->{callback_depth} || 0) + 1;
Condition100%2/2
$active_pool->{'callback_depth'} || 0
l!l
2493
MC/DC100%1/1
$active_pool->{'callback_depth'} || 0
$active_pool->{'callback_depth'}
Truth table100%2/2
A
A= $active_pool->{'callback_depth'}
Aresult
11
00
1186 495 ▶ $active_op->{transaction} ||= $tx;
Condition33%1/3
$active_op->{"transaction"} ||= $tx
l!l&&r!l&&!r
49500
MC/DC0%0/2
$active_op->{"transaction"} ||= $tx
$active_op->{"transaction"} $tx
Truth table33%1/3
A ||= B
A= $active_op->{"transaction"}B= $tx
ABresult
1X1
011
000
1187 495 ▶ if (my $bridge = delete $active_op->{websocket_bridge}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $bridge = delete $active_op->{"websocket_bridge"}) 0 495 495
1188 0 $bridge->detach;
1189 }
1190 495 ▶ if (my $bridge = delete $active_op->{handoff_bridge}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $bridge = delete $active_op->{"handoff_bridge"}) 0 495 495
1191 0 my $consumer = delete $active_op->{handoff_consumer};
1192 0 ▶ $consumer->transport_error($tx->error || 'CONNECT stream ended')
Branch: 1 branch
BranchTrueFalseTotal
if $consumer and not $tx->is_complete 0 0 0
Condition0%0/5
$consumer and not $tx->is_complete
!ll&&!rl&&r
000
$tx->error || 'CONNECT stream ended'
l!l
00
MC/DC0%0/2
$consumer and not $tx->is_complete
$consumer not $tx->is_complete
MC/DC0%0/1
$tx->error || 'CONNECT stream ended'
$tx->error
Truth table0%0/3
A and not(B)
A= $consumerB= not $tx->is_complete
ABresult
0X0
100
111
Truth table0%0/2
A
A= $tx->error
Aresult
11
00
1193 if $consumer && !$tx->is_complete;
1194 0 $bridge->detach;
1195 }
1196 $active_op->{state} = ($active_op->{admission_error} || $active_op->{timeout_error}
1197 495 ▶ || $active_op->{websocket_handshake_error}) ? 'error'
Branch: 3 branches
BranchTrueFalseTotal
$active_op->{'admission_error'} || $active_op->{'timeout_error'} || $active_op->{'websocket_handshake_error'} ? : 2 493 495
$tx->is_cancelled ? : 1 492 493
$tx->is_error ? : 1 491 492
Condition83%5/6
$active_op->{"admission_error"} or $active_op->{"timeout_error"} or $active_op->{"websocket_handshake_error"}
l!l&&r!l&&!r
20493
$active_op->{"admission_error"} or $active_op->{"timeout_error"}
l!l&&r!l&&!r
11493
MC/DC66%2/3
$active_op->{"admission_error"} or $active_op->{"timeout_error"} or $active_op->{"websocket_handshake_error"}
$active_op->{"admission_error"} $active_op->{"timeout_error"} $active_op->{"websocket_handshake_error"}
Truth table75%3/4
A or B or C
A= $active_op->{"admission_error"}B= $active_op->{"timeout_error"}C= $active_op->{"websocket_handshake_error"}
ABCresult
1XX1
01X1
0011
0000
1198 : $tx->is_cancelled ? 'cancelled'
1199 : $tx->is_error ? 'error' : 'complete';
1200 $active_op->{error} = $active_op->{admission_error} || $active_op->{timeout_error}
1201 || $active_op->{websocket_handshake_error}
1202 495 ▶ || ($tx->is_error ? $tx->error : undef);
Branch: 1 branch
BranchTrueFalseTotal
$tx->is_error ? : 1 492 493
Condition88%8/9
$active_op->{'admission_error'} || $active_op->{'timeout_error'} || $active_op->{'websocket_handshake_error'} || ($tx->is_error ? $tx->error : undef)
l!l&&r!l&&!r
21492
$active_op->{"admission_error"} or $active_op->{"timeout_error"} or $active_op->{"websocket_handshake_error"}
l!l&&r!l&&!r
20493
$active_op->{"admission_error"} or $active_op->{"timeout_error"}
l!l&&r!l&&!r
11493
MC/DC75%3/4
$active_op->{'admission_error'} || $active_op->{'timeout_error'} || $active_op->{'websocket_handshake_error'} || ($tx->is_error ? $tx->error : undef)
$active_op->{"admission_error"} $active_op->{"timeout_error"} $active_op->{"websocket_handshake_error"} ($tx->is_error ? $tx->error : undef)
Truth table80%4/5
A or B or C || D
A= $active_op->{"admission_error"}B= $active_op->{"timeout_error"}C= $active_op->{"websocket_handshake_error"}D= ($tx->is_error ? $tx->error : undef)
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1203 495 $active_op->_cancel_timer;
1204 495 $active_conn->{active}--;
1205 495 ▶ if (($active_op->{admission_error} || $active_op->{timeout_error}
Branch: 1 branch
BranchTrueFalseTotal
if ($active_op->{"admission_error"} || $active_op->{"timeout_error"} || $active_op->{"websocket_handshake_error"} and $callbacks->{"on_error"}) 2 493 495
Condition77%7/9
$active_op->{"admission_error"} || $active_op->{"timeout_error"} || $active_op->{"websocket_handshake_error"} and $callbacks->{"on_error"}
!ll&&!rl&&r
49302
$active_op->{"admission_error"} or $active_op->{"timeout_error"} or $active_op->{"websocket_handshake_error"}
l!l&&r!l&&!r
20493
$active_op->{"admission_error"} or $active_op->{"timeout_error"}
l!l&&r!l&&!r
11493
MC/DC50%2/4
$active_op->{"admission_error"} || $active_op->{"timeout_error"} || $active_op->{"websocket_handshake_error"} and $callbacks->{"on_error"}
$active_op->{"admission_error"} $active_op->{"timeout_error"} $active_op->{"websocket_handshake_error"} $callbacks->{"on_error"}
Truth table42%3/7
A or B or C and D
A= $active_op->{"admission_error"}B= $active_op->{"timeout_error"}C= $active_op->{"websocket_handshake_error"}D= $callbacks->{"on_error"}
ABCDresult
000X0
1XX00
01X00
00100
1XX11
01X11
00111
1206 || $active_op->{websocket_handshake_error})
1207 && $callbacks->{on_error}) {
1208 2 ▶ eval { $callbacks->{on_error}->($tx, $active_op->{error}); 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $callbacks->{"on_error"}->($tx, $active_op->{"error"}); 1 } } or warn $@ 2 0 2
1209 or warn $@;
1210 }
1211 495 my $ok = eval {
1212 495 ▶ $callbacks->{on_finish}->($tx) if $callbacks->{on_finish};
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks->{"on_finish"} 15 480 495
1213 495 1;
1214 };
1215 495 ▶ warn $@ unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 495 495
1216 # Keep the strong active ownership through application callbacks.
1217 # A caller-retained handle still owns the real engine Transaction.
1218 495 delete $active_self->{active_operations}{$op_id};
1219 # A quiet, reusable connection needs no additional loop turn.
1220 # Preserve deferred H1 reentrancy, pending queues, idle timers
1221 # and immediate cleanup of closed/draining/stale connections.
1222 495 ▶ if ($active_self->{shutdown}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($active_self->{"shutdown"}) 3 492 495
1223 $active_self->_drop_connection(
1224 $active_pool, $active_conn, 'shutdown',
1225 3 ▶ ) if !$active_conn->{active} && !$active_conn->{released};
Branch: 1 branch
BranchTrueFalseTotal
unless $active_conn->{"active"} or $active_conn->{"released"} 2 1 3
Condition66%2/3
$active_conn->{"active"} or $active_conn->{"released"}
l!l&&r!l&&!r
102
MC/DC50%1/2
$active_conn->{"active"} or $active_conn->{"released"}
$active_conn->{"active"} $active_conn->{"released"}
Truth table66%2/3
A or B
A= $active_conn->{"active"}B= $active_conn->{"released"}
ABresult
1X1
011
000
1226 3 return;
1227 }
1228 $active_self->_schedule($active_pool)
1229 492 if @{ $active_pool->{pending} }
1230 || defined($active_self->{idle_timeout})
1231 || $active_conn->{stale}
1232 492 ▶ || _closed($active_conn) || _retired($active_conn);
Branch: 1 branch
BranchTrueFalseTotal
if @{$active_pool->{"pending"};} or defined $active_self->{"idle_timeout"} or $active_conn->{"stale"} or _closed($active_conn) or _retired($active_conn) 26 466 492
Condition83%10/12
@{$active_pool->{"pending"};} or defined $active_self->{"idle_timeout"} or $active_conn->{"stale"} or _closed($active_conn) or _retired($active_conn)
l!l&&r!l&&!r
260466
@{$active_pool->{"pending"};} or defined $active_self->{"idle_timeout"} or $active_conn->{"stale"} or _closed($active_conn)
l!l&&r!l&&!r
242466
@{$active_pool->{"pending"};} or defined $active_self->{"idle_timeout"} or $active_conn->{"stale"}
l!l&&r!l&&!r
240468
@{$active_pool->{"pending"};} or defined $active_self->{"idle_timeout"}
l!l&&r!l&&!r
1410468
MC/DC60%3/5
@{$active_pool->{"pending"};} or defined $active_self->{"idle_timeout"} or $active_conn->{"stale"} or _closed($active_conn) or _retired($active_conn)
@{$active_pool->{"pending"};} defined $active_self->{"idle_timeout"} $active_conn->{"stale"} _closed($active_conn) _retired($active_conn)
Truth table66%4/6
A or B or C or D or E
A= @{$active_pool->{"pending"};}B= defined $active_self->{"idle_timeout"}C= $active_conn->{"stale"}D= _closed($active_conn)E= _retired($active_conn)
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
1233 500 };
1234 500 my $no_credit = 0;
1235 500 my $ok = eval {
1236 die "connect_websocket(): requires HTTP1, HTTP2 or HTTP3 transport\n"
1237 if $ws_spec && $conn->{protocol} ne 'http/1.1'
1238 500 ▶ && $conn->{protocol} ne 'h2' && $conn->{protocol} ne 'h3';
Branch: 1 branch
BranchTrueFalseTotal
if $ws_spec and $conn->{"protocol"} ne "http/1.1" and $conn->{"protocol"} ne "h2" and $conn->{"protocol"} ne "h3" 0 500 500
Condition33%3/9
$ws_spec and $conn->{"protocol"} ne "http/1.1" and $conn->{"protocol"} ne "h2" and $conn->{"protocol"} ne "h3"
!ll&&!rl&&r
50000
$ws_spec and $conn->{"protocol"} ne "http/1.1" and $conn->{"protocol"} ne "h2"
!ll&&!rl&&r
50000
$ws_spec and $conn->{"protocol"} ne "http/1.1"
!ll&&!rl&&r
50000
MC/DC0%0/4
$ws_spec and $conn->{"protocol"} ne "http/1.1" and $conn->{"protocol"} ne "h2" and $conn->{"protocol"} ne "h3"
$ws_spec $conn->{"protocol"} ne "http/1.1" $conn->{"protocol"} ne "h2" $conn->{"protocol"} ne "h3"
Truth table20%1/5
A and B and C and D
A= $ws_specB= $conn->{"protocol"} ne "http/1.1"C= $conn->{"protocol"} ne "h2"D= $conn->{"protocol"} ne "h3"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1239 die "connect_websocket(): HTTP1 requires unblock_upgrade()\n"
1240 if $ws_spec && $conn->{protocol} eq 'http/1.1'
1241 500 ▶ && !$conn->{host}->can('unblock_upgrade');
Branch: 1 branch
BranchTrueFalseTotal
if $ws_spec and $conn->{"protocol"} eq "http/1.1" and not $conn->{"host"}->can("unblock_upgrade") 0 500 500
Condition33%2/6
$ws_spec and $conn->{"protocol"} eq "http/1.1" and not $conn->{"host"}->can("unblock_upgrade")
!ll&&!rl&&r
50000
$ws_spec and $conn->{"protocol"} eq "http/1.1"
!ll&&!rl&&r
50000
MC/DC0%0/3
$ws_spec and $conn->{"protocol"} eq "http/1.1" and not $conn->{"host"}->can("unblock_upgrade")
$ws_spec $conn->{"protocol"} eq "http/1.1" not $conn->{"host"}->can("unblock_upgrade")
Truth table25%1/4
A and B and not(C)
A= $ws_specB= $conn->{"protocol"} eq "http/1.1"C= not $conn->{"host"}->can("unblock_upgrade")
ABCresult
0XX0
10X0
1100
1111
1242 $op->{transaction} = $conn->{engine}->request(
1243 $op->{request},
1244 stream_body => $op->{stream_body},
1245 500 %engine_callback,
1246 );
1247 # HTTP/3 returns undef before opening a QUIC bidi stream.
1248 # Defer the SAME unsent operation until the engine signals credit.
1249 $no_credit = 1 if !defined($op->{transaction})
1250 500 ▶ && !$op->is_terminal && $conn->{protocol} eq 'h3';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $op->{"transaction"} || $op->is_terminal and $conn->{"protocol"} eq "h3" 5 495 500
Condition66%4/6
not defined $op->{"transaction"} || $op->is_terminal and $conn->{"protocol"} eq "h3"
!ll&&!rl&&r
49505
defined $op->{'transaction'} || $op->is_terminal
l!l&&r!l&&!r
49505
MC/DC33%1/3
not defined $op->{"transaction"} || $op->is_terminal and $conn->{"protocol"} eq "h3"
defined $op->{'transaction'} $op->is_terminal $conn->{"protocol"} eq "h3"
Truth table50%2/4
not(A || B) and C
A= defined $op->{'transaction'}B= $op->is_terminalC= $conn->{"protocol"} eq "h3"
ABCresult
1XX0
01X0
0000
0011
1251 die "$conn->{protocol} request was not admitted by its engine\n"
1252 500 ▶ unless $no_credit || defined($op->{transaction}) || $op->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
unless $no_credit or defined $op->{"transaction"} or $op->is_terminal 0 500 500
Condition50%3/6
$no_credit or defined $op->{"transaction"} or $op->is_terminal
l!l&&r!l&&!r
50000
$no_credit or defined $op->{"transaction"}
l!l&&r!l&&!r
54950
MC/DC0%0/3
$no_credit or defined $op->{"transaction"} or $op->is_terminal
$no_credit defined $op->{"transaction"} $op->is_terminal
Truth table50%2/4
A or B or C
A= $no_creditB= defined $op->{"transaction"}C= $op->is_terminal
ABCresult
1XX1
01X1
0011
0000
1253 500 1;
1254 };
1255 500 ▶ if ($ok && $no_credit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok and $no_credit) 5 495 500
Condition66%2/3
$ok and $no_credit
!ll&&!rl&&r
04955
MC/DC50%1/2
$ok and $no_credit
$ok $no_credit
Truth table66%2/3
A and B
A= $okB= $no_credit
ABresult
0X0
100
111
1256 5 delete $self->{active_operations}{$op_id};
1257 5 $conn->{active}--;
1258 5 $conn->{credit_blocked} = 1;
1259 5 $op->{state} = 'queued';
1260 5 unshift @{ $pool->{pending} }, $op;
1261 5 $self->{pending_count}++;
1262 5 return 0;
1263 }
1264 495 ▶ if ($ok && !$op->is_terminal && $callbacks->{on_transaction}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok and not $op->is_terminal and $callbacks->{"on_transaction"}) 4 491 495
Condition50%3/6
$ok and not $op->is_terminal and $callbacks->{"on_transaction"}
!ll&&!rl&&r
04914
$ok and not $op->is_terminal
!ll&&!rl&&r
00495
MC/DC33%1/3
$ok and not $op->is_terminal and $callbacks->{"on_transaction"}
$ok not $op->is_terminal $callbacks->{"on_transaction"}
Truth table50%2/4
A and not(B) and C
A= $okB= not $op->is_terminalC= $callbacks->{"on_transaction"}
ABCresult
0XX0
10X0
1100
1111
1265 # Admission is a one-shot boundary, outside engine request(). The
1266 # operation already exposes the real transaction, so callers may
1267 # write/end a streamed body or cancel without a provisional buffer.
1268 4 ▶ local $pool->{callback_depth} = ($pool->{callback_depth} || 0) + 1;
Condition50%1/2
$pool->{'callback_depth'} || 0
l!l
04
MC/DC0%0/1
$pool->{'callback_depth'} || 0
$pool->{'callback_depth'}
Truth table50%1/2
A
A= $pool->{'callback_depth'}
Aresult
11
00
1269 4 my $admitted = eval { $callbacks->{on_transaction}->($op->{transaction}); 1 };
1270 4 ▶ if (!$admitted && !$op->is_terminal) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($admitted or $op->is_terminal) 1 3 4
Condition66%2/3
$admitted or $op->is_terminal
l!l&&r!l&&!r
301
MC/DC50%1/2
$admitted or $op->is_terminal
$admitted $op->is_terminal
Truth table66%2/3
A or B
A= $admittedB= $op->is_terminal
ABresult
1X1
011
000
1271 1 ▶ $op->{admission_error} = "$@" || 'on_transaction callback failed';
Condition50%1/2
"$@" || 'on_transaction callback failed'
l!l
10
MC/DC0%0/1
"$@" || 'on_transaction callback failed'
"$@"
Truth table50%1/2
A
A= "$@"
Aresult
11
00
1272 1 $op->{transaction}->cancel;
1273 }
1274 }
1275 495 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 495 495
1276 0 delete $self->{active_operations}{$op_id};
1277 0 ▶ if (!$op->is_terminal) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($op->is_terminal) 0 0 0
1278 0 $conn->{active}--;
1279 0 $self->_fail_active($op, "$@");
1280 }
1281 0 $self->_schedule($pool);
1282 }
1283 495 return 1;
1284 }
1285  
1286 47 ▶sub _schedule {
Subroutine _schedule: called CC=4 SCAR=14.1
1287 47 my ($self, $pool) = @_;
1288 47 ▶ return if $self->{shutdown};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"shutdown"} 2 45 47
1289 45 ▶ return if $pool->{scheduled}++;
Branch: 1 branch
BranchTrueFalseTotal
if $pool->{"scheduled"}++ 4 41 45
1290 41 my $ok = eval {
1291 38 ▶ $self->{factory}{defer}->(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1292 38 $pool->{scheduled} = 0;
1293 38 $self->_pump($pool);
1294 41 });
1295 41 1;
1296 };
1297 41 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ok) 0 41 41
1298 0 $pool->{scheduled} = 0;
1299 0 warn "Client defer callback failed: $@";
1300 }
1301 }
1302  
1303 0 ▶sub _fail_active {
Subroutine _fail_active: not called CC=2 SCAR=17.9
1304 0 my ($self, $op, $error) = @_;
1305 0 ▶ return if $op->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $op->is_terminal 0 0 0
1306 0 $op->{state} = 'error';
1307 0 $op->{error} = $error;
1308 0 $op->_cancel_timer;
1309 0 $self->_pending_callbacks($op, 1);
1310 }
1311  
1312 4 ▶sub _fail_pending {
Subroutine _fail_pending: called CC=4 SCAR=14.0
1313 4 my ($self, $pool, $op, $error) = @_;
1314 4 $self->_abandon_connect($pool, $op);
1315 4 ▶ for (my $i = 0; $i < @{ $pool->{pending} }; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$pool->{"pending"};}) 4 0 4
1316 4 ▶ next unless $pool->{pending}[$i] == $op;
Branch: 1 branch
BranchTrueFalseTotal
unless $pool->{"pending"}[$i] == $op 0 4 4
1317 4 splice @{ $pool->{pending} }, $i, 1;
1318 4 $self->{pending_count}--;
1319 4 last;
1320 }
1321 4 ▶ return if $op->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $op->is_terminal 0 4 4
1322 4 $op->{state} = 'error';
1323 4 $op->{error} = $error;
1324 4 $op->_cancel_timer;
1325 4 $self->_pending_callbacks($op, 1);
1326 }
1327  
1328 13 ▶sub _pending_callbacks {
Subroutine _pending_callbacks: called CC=6 SCAR=18.1
1329 13 my ($self, $op, $failed) = @_;
1330 13 my $callbacks = $op->{callbacks};
1331 13 ▶ if ($failed && $callbacks->{on_error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($failed and $callbacks->{"on_error"}) 4 9 13
Condition66%2/3
$failed and $callbacks->{"on_error"}
!ll&&!rl&&r
904
MC/DC50%1/2
$failed and $callbacks->{"on_error"}
$failed $callbacks->{"on_error"}
Truth table66%2/3
A and B
A= $failedB= $callbacks->{"on_error"}
ABresult
0X0
100
111
1332 4 ▶ eval { $callbacks->{on_error}->($op, $op->{error}); 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $callbacks->{"on_error"}->($op, $op->{"error"}); 1 } } or warn $@ 4 0 4
1333 or warn $@;
1334 }
1335 13 ▶ if ($callbacks->{on_finish}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($callbacks->{"on_finish"}) 8 5 13
1336 8 ▶ eval { $callbacks->{on_finish}->($op); 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $callbacks->{"on_finish"}->($op); 1 } } or warn $@ 8 0 8
1337 or warn $@;
1338 }
1339 }
1340  
1341 9 ▶sub _cancel_queued {
Subroutine _cancel_queued: called CC=3 SCAR=11.0
1342 9 my ($self, $op) = @_;
1343 9 my $pool = $op->{origin};
1344 9 $self->_abandon_connect($pool, $op);
1345 9 ▶ for (my $i = 0; $i < @{ $pool->{pending} }; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$pool->{"pending"};}) 9 0 9
1346 9 ▶ next unless $pool->{pending}[$i] == $op;
Branch: 1 branch
BranchTrueFalseTotal
unless $pool->{"pending"}[$i] == $op 0 9 9
1347 9 splice @{ $pool->{pending} }, $i, 1;
1348 9 $self->{pending_count}--;
1349 9 last;
1350 }
1351 9 $self->_pending_callbacks($op, 0);
1352 9 $self->_schedule($pool);
1353 }
1354  
1355 12 1;
1356  
1357 __END__
↑ Summary HTTP/Server.pm »