blib/lib/Unblock/HTTP1/_Engine.pm

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