blib/lib/Unblock/HTTP1/_Engine.pm

filter: Statementstmt 87.5% 233 / 266 Branchbran 65.6% 130 / 198 Conditioncond 47.0% 47 / 100 MC/DCmcdc 27.5% 16 / 58 Subroutinesub 81.0% 30 / 37 Podpod 0.0% 0 / 11 totaltotal 68.0% 456 / 670 CC 137 SCAR 31.2
CC
137
Cov
73%
_init_engine
52.6
_input_borrowed
51.6
close
30.0
CRAP 22.7
« blib/lib/Unblock/HTTP1/Server.pm ↑ Summary blib/lib/Unblock/HTTP1/Transaction.pm »
1 package Unblock::HTTP1::_Engine;
2  
3 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 35 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 35 ▶use utf8 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 35 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 158 ▶sub _init_engine {
Subroutine _init_engine: called CC=34 SCAR=39.6
10 158 my ($self, %option) = @_;
11 $self->{receive_body} = exists $option{receive_body}
12 158 ▶ ? delete $option{receive_body} : 'stream';
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'receive_body'} ? : 26 132 158
13 croak 'new(): receive_body must be buffered or stream'
14 unless defined($self->{receive_body}) && !ref($self->{receive_body})
15 158 ▶ && $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 158 158
Condition33%2/6
defined $self->{"receive_body"} and not ref $self->{"receive_body"} and $self->{"receive_body"} =~ /\A(?:buffered|stream)\z/
!ll&&!rl&&r
00158
defined $self->{"receive_body"} and not ref $self->{"receive_body"}
!ll&&!rl&&r
00158
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 158 ▶ ? delete $option{max_buffered_body_bytes} : 64 * 1024 * 1024;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'max_buffered_body_bytes'} ? : 19 139 158
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 158 ▶ && $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 158 158
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
00158
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
00158
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
00158
defined $self->{"max_buffered_body_bytes"} and not ref $self->{"max_buffered_body_bytes"}
!ll&&!rl&&r
00158
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 158 ▶ 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 158 158
Condition66%2/3
$self->{"receive_body"} eq "buffered" and $self->{"callbacks"}{"on_body"}
!ll&&!rl&&r
132260
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 158 my $transport = delete $option{transport};
27 158 ▶ if (defined $transport) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $transport) 29 129 158
28 29 ▶ croak 'new(): transport must be an object' unless ref $transport;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $transport 0 29 29
29 29 for my $method (qw(unblock_send unblock_finish unblock_abort)) {
30 87 ▶ croak "new(): transport must implement $method()"
Branch: 1 branch
BranchTrueFalseTotal
unless $transport->can($method) 0 87 87
31 unless $transport->can($method);
32 }
33 }
34 158 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 158 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 157 ▶ $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 154 157
45 157 ▶ $self->{max_headers} = exists $option{max_headers} ? $option{max_headers} : 100;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'max_headers'} ? : 1 156 157
46 $self->{max_chunk_extension_size} = exists $option{max_chunk_extension_size}
47 157 ▶ ? $option{max_chunk_extension_size} : 16_384;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'max_chunk_extension_size'} ? : 2 155 157
48 157 ▶ $self->{high_water} = exists $option{high_water} ? $option{high_water} : 65_536;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'high_water'} ? : 2 155 157
49 157 ▶ $self->{low_water} = exists $option{low_water} ? $option{low_water} : 32_768;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'low_water'} ? : 2 155 157
50 157 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 785 ▶ 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 785 785
Condition33%2/6
defined $self->{$key} and not ref $self->{$key} and $self->{$key} =~ /\A[0-9]+\z/
!ll&&!rl&&r
00785
defined $self->{$key} and not ref $self->{$key}
!ll&&!rl&&r
00785
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 157 ▶ 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 157 157
55 croak 'new(): max_headers must be between 1 and 256'
56 157 ▶ unless $self->{max_headers} >= 1 && $self->{max_headers} <= 256;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"max_headers"} >= 1 and $self->{"max_headers"} <= 256 0 157 157
Condition33%1/3
$self->{"max_headers"} >= 1 and $self->{"max_headers"} <= 256
!ll&&!rl&&r
00157
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 157 ▶ if $self->{low_water} > $self->{high_water};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"low_water"} > $self->{"high_water"} 0 157 157
59 157 $self->{transport} = $transport;
60 157 ▶ weaken($self->{transport}) if defined $transport;
Branch: 1 branch
BranchTrueFalseTotal
if defined $transport 29 128 157
61 157 ▶ $self->{transport_attached} = defined($transport) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $transport ? : 29 128 157
62 157 $self->{transport_blocked} = 0;
63 157 $self->{transport_syncing} = 0;
64 157 $self->{transport_finished} = 0;
65 157 $self->{transport_aborted} = 0;
66 157 $self->{switch_notice} = undef;
67 157 $self->{input} = '';
68 157 $self->{output} = '';
69 157 $self->{closed} = 0;
70 157 $self->{switched} = 0;
71 157 $self->{remainder} = '';
72 157 $self->{driving} = 0;
73 157 $self->{eof} = 0;
74 157 return $self;
75 }
76  
77 36 ▶sub is_closed { $_[0]{closed} ? 1 : 0 }
Subroutine is_closed: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'closed'} ? : 29 7 36
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 2 ▶sub want_read { !$_[0]{closed} && !$_[0]{switched} && !$_[0]{eof} ? 1 : 0 }
Subroutine want_read: called CC=4 SCAR=19.1
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
!($_[0]{'closed'} || $_[0]{'switched'} || $_[0]{'eof'}) ? : 2 0 2
Condition33%2/6
$_[0]{'closed'} || $_[0]{'switched'} || $_[0]{'eof'}
l!l&&r!l&&!r
002
$_[0]{"closed"} or $_[0]{"switched"}
l!l&&r!l&&!r
002
MC/DC0%0/3
$_[0]{'closed'} || $_[0]{'switched'} || $_[0]{'eof'}
$_[0]{"closed"} $_[0]{"switched"} $_[0]{'eof'}
Truth table25%1/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 492 ▶sub input {
Subroutine input: called CC=11 SCAR=25.2
Pod undocumented
83 492 my ($self, $bytes) = @_;
84 492 ▶ croak 'input(): bytes must be a scalar' if ref($bytes);
Branch: 1 branch
BranchTrueFalseTotal
if ref $bytes 0 492 492
85 492 ▶ $bytes = '' unless defined $bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes 0 492 492
86 492 my $copy = "$bytes";
87 492 ▶ croak 'input(): bytes must be a byte string' unless utf8::downgrade($copy, 1);
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::downgrade($copy, 1) 0 492 492
88 492 ▶ return 0 unless length $copy;
Branch: 1 branch
BranchTrueFalseTotal
unless length $copy 0 492 492
89 croak 'input(): cannot be called recursively from an engine callback or host send'
90 492 ▶ if $self->{driving} || $self->{transport_syncing};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"driving"} or $self->{"transport_syncing"} 3 489 492
Condition100%3/3
$self->{"driving"} or $self->{"transport_syncing"}
l!l&&r!l&&!r
21489
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 489 ▶ croak 'input(): read side is already at EOF' if $self->{eof};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"eof"} 0 489 489
92 489 ▶ if ($self->{switched}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"switched"}) 0 489 489
93 0 $self->{remainder} .= $copy;
94 0 return length $copy;
95 }
96 489 ▶ croak 'input(): connection is closed' if $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} 0 489 489
97 489 $self->{input} .= $copy;
98 {
99 489 local $self->{driving} = 1;
100 489 $self->_drive;
101 }
102 489 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 26 463 489
103 489 return length $copy;
104 }
105  
106 16 ▶sub _input_borrowed {
Subroutine _input_borrowed: called CC=17 SCAR=39.4
107 16 my ($self, $window, $length, $head, $message) = @_;
108 croak '_input_borrowed(): cannot be called recursively from an engine callback or host send'
109 16 ▶ if $self->{driving} || $self->{transport_syncing};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"driving"} or $self->{"transport_syncing"} 0 16 16
Condition33%1/3
$self->{"driving"} or $self->{"transport_syncing"}
l!l&&r!l&&!r
0016
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 16 ▶ return (4, 0, 0) if $self->{switched};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"switched"} 0 16 16
111 16 ▶ return (3, 0, 0) if $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} 0 16 16
112 16 ▶ if (length $self->{input}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"input"}) 0 16 16
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 16 my ($status, $consumed, $head_ready);
128 {
129 16 local $self->{borrowed_input} = $window;
130 16 local $self->{borrowed_length} = $length;
131 16 local $self->{borrowed_offset} = 0;
132 16 local $self->{borrowed_head} = $head;
133 16 local $self->{borrowed_message} = $message;
134 16 local $self->{driving} = 1;
135 16 $self->_drive;
136  
137 16 my $remaining = $self->_input_length;
138 16 ▶ if ($self->{closed}) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->{'closed'}) { } 0 16 16
elsif ($self->{'switched'}) { } 3 13 16
elsif ($remaining and $self->_borrowed_should_buffer_tail) { } 0 13 13
elsif ($remaining) { } 0 13 13
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
1300
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 13 $status = 0;
149 }
150 16 $consumed = $self->{borrowed_offset};
151 16 $head_ready = $self->_borrowed_native_head_ready;
152 }
153 16 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 4 12 16
154 16 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 895 ▶sub _input_length {
Subroutine _input_length: called CC=2 SCAR=6.9
166 895 my ($self) = @_;
167 895 ▶ if (exists $self->{borrowed_input}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"borrowed_input"}) 50 845 895
168 50 return $self->{borrowed_length} - $self->{borrowed_offset};
169 }
170 845 return length $self->{input};
171 }
172  
173 521 ▶sub _input_window {
Subroutine _input_window: called CC=2 SCAR=6.9
174 521 my ($self) = @_;
175 return ($self->{borrowed_input}, $self->{borrowed_offset})
176 521 ▶ if exists $self->{borrowed_input};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"borrowed_input"} 7 514 521
177 514 return ($self->{input}, 0);
178 }
179  
180 54 ▶sub _input_take {
Subroutine _input_take: called CC=3 SCAR=11.0
181 54 my ($self, $length) = @_;
182 54 ▶ return '' unless $length;
Branch: 1 branch
BranchTrueFalseTotal
unless $length 0 54 54
183 54 ▶ if (exists $self->{borrowed_input}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"borrowed_input"}) 9 45 54
184 9 my $offset = $self->{borrowed_offset};
185 9 my $bytes = $self->{borrowed_input}->slice($offset, $length);
186 9 $self->{borrowed_offset} += $length;
187 9 return $bytes;
188 }
189 45 return substr($self->{input}, 0, $length, '');
190 }
191  
192 215 ▶sub _input_discard {
Subroutine _input_discard: called CC=3 SCAR=11.0
193 215 my ($self, $length) = @_;
194 215 ▶ return unless $length;
Branch: 1 branch
BranchTrueFalseTotal
unless $length 0 215 215
195 215 ▶ if (exists $self->{borrowed_input}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"borrowed_input"}) 19 196 215
196 19 $self->{borrowed_offset} += $length;
197 19 return;
198 }
199 196 substr($self->{input}, 0, $length, '');
200 196 return;
201 }
202  
203 65 ▶sub _input_clear {
Subroutine _input_clear: called CC=2 SCAR=6.9
204 65 my ($self) = @_;
205 65 ▶ if (exists $self->{borrowed_input}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'borrowed_input'}) { } 1 64 65
206 1 $self->{borrowed_offset} = $self->{borrowed_length};
207 } else {
208 64 $self->{input} = '';
209 }
210 65 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 116 ▶sub output {
Subroutine output: called CC=9 SCAR=29.0
Pod undocumented
241 116 my ($self, $max) = @_;
242 croak 'output(): manual output is unavailable with an attached transport'
243 116 ▶ if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 1 115 116
244 115 ▶ croak 'output(): cannot be called recursively from an engine callback' if $self->{driving};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"driving"} 0 115 115
245 115 ▶ return '' unless length $self->{output};
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"output"} 7 108 115
246 108 my $take = length $self->{output};
247 108 ▶ if (defined $max) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max) 0 108 108
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 108 my $bytes = substr($self->{output}, 0, $take, '');
253 108 $self->_after_output;
254 108 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 196 ▶sub _queue_output {
Subroutine _queue_output: called CC=7 SCAR=19.5
276 196 my ($self, $bytes) = @_;
277 196 ▶ return unless defined $bytes && length $bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes and length $bytes 7 189 196
Condition66%2/3
defined $bytes and length $bytes
!ll&&!rl&&r
07189
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 189 ▶ if $self->{transport_syncing};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_syncing"} 0 189 189
280 # Preserve Perl's copy-on-write buffer when starting a new batch. Only
281 # coalescing an existing batch requires appending the serialized bytes.
282 189 ▶ if (length $self->{output}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{'output'}) { } 20 169 189
283 20 $self->{output} .= $bytes;
284 } else {
285 169 $self->{output} = $bytes;
286 }
287 189 ▶ $self->_transport_sync if $self->{transport_attached} && !$self->{driving};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} and not $self->{"driving"} 18 171 189
Condition100%3/3
$self->{"transport_attached"} and not $self->{"driving"}
!ll&&!rl&&r
1502118
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
288 189 return;
289 }
290  
291 # Only a whole-buffer acceptance transfers ownership to the host. A false
292 # return indicates congestion, not rejection. The host later resumes us.
293 82 ▶sub _transport_sync {
Subroutine _transport_sync: called CC=21 SCAR=30.8
294 82 my ($self) = @_;
295 82 ▶ return unless $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"transport_attached"} 0 82 82
296 82 ▶ return if $self->{transport_syncing} || $self->{driving};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_syncing"} or $self->{"driving"} 0 82 82
Condition33%1/3
$self->{"transport_syncing"} or $self->{"driving"}
l!l&&r!l&&!r
0082
MC/DC0%0/2
$self->{"transport_syncing"} or $self->{"driving"}
$self->{"transport_syncing"} $self->{"driving"}
Truth table33%1/3
A or B
A= $self->{"transport_syncing"}B= $self->{"driving"}
ABresult
1X1
011
000
297 82 ▶ return if $self->{transport_aborted} || $self->{transport_finished};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_aborted"} or $self->{"transport_finished"} 5 77 82
Condition100%3/3
$self->{"transport_aborted"} or $self->{"transport_finished"}
l!l&&r!l&&!r
1477
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
298 77 my $host = $self->{transport};
299 77 ▶ return $self->transport_error('HTTP/1 transport was destroyed') unless $host;
Branch: 1 branch
BranchTrueFalseTotal
unless $host 1 76 77
300  
301 {
302 76 local $self->{transport_syncing} = 1;
303 76 ▶ while (!$self->{transport_blocked} && length $self->{output}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"transport_blocked"} and length $self->{"output"}) 33 73 106
Condition100%3/3
not $self->{"transport_blocked"} and length $self->{"output"}
!ll&&!rl&&r
304333
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
304 # No producer may re-enter during host send. Move this complete
305 # buffer out once; a thrown send aborts rather than retransmits.
306 33 my $bytes = $self->{output};
307 33 $self->{output} = '';
308 33 my ($accepted, $ready);
309 33 $accepted = eval { $ready = $host->unblock_send($bytes); 1 };
310 33 ▶ if (!$accepted) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($accepted) 3 30 33
311 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
312 3 $self->_transport_abort($error);
313 3 return;
314 }
315 30 ▶ $self->{transport_blocked} = 1 if defined($ready) && !$ready;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ready and not $ready 9 21 30
Condition100%3/3
defined $ready and not $ready
!ll&&!rl&&r
1569
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
316 }
317 }
318  
319 73 ▶ if (!length($self->{output}) && $self->{switch_notice}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not length $self->{"output"} and $self->{"switch_notice"}) 3 70 73
Condition100%3/3
not length $self->{"output"} and $self->{"switch_notice"}
!ll&&!rl&&r
19513
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
320 3 my $notice = delete $self->{switch_notice};
321 3 $self->_deliver_switch_notice(@$notice);
322 }
323 73 ▶ return if $self->{transport_aborted};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_aborted"} 1 72 73
324 72 ▶ if ($self->{closed} && !length($self->{output}) && !$self->{switched}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"closed"} and not length $self->{"output"} and not $self->{"switched"}) 8 64 72
Condition83%5/6
$self->{"closed"} and not length $self->{"output"} and not $self->{"switched"}
!ll&&!rl&&r
6408
$self->{"closed"} and not length $self->{"output"}
!ll&&!rl&&r
5868
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
325 8 $self->{transport_finished} = 1;
326 8 my $ok = eval { $self->_transport_finish($host); 1 };
327 8 ▶ $self->_transport_abort("$@" || 'unblock_finish() failed') unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 8 8
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
328 }
329 72 return;
330 }
331  
332 8 ▶sub _transport_finish {
Subroutine _transport_finish: called CC=1 SCAR=0.0
333 8 my ($self, $host) = @_;
334 8 $host->unblock_finish;
335 8 return;
336 }
337  
338 7 ▶sub _transport_abort {
Subroutine _transport_abort: called CC=4 SCAR=13.9
339 7 my ($self, $reason) = @_;
340 7 ▶ return if $self->{transport_aborted};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_aborted"} 0 7 7
341 7 $self->{transport_aborted} = 1;
342 7 $self->{output} = '';
343 7 $self->{closed} = 1;
344 7 my $notice = delete $self->{switch_notice};
345 7 $self->_fail_all($reason);
346 7 ▶ $notice->[0]->_notify_finish if $notice;
Branch: 1 branch
BranchTrueFalseTotal
if $notice 0 7 7
347 7 ▶ if (my $host = $self->{transport}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $host = $self->{"transport"}) 6 1 7
348 6 eval { $host->unblock_abort($reason) };
349 }
350 7 return;
351 }
352  
353 2 ▶sub transport_error {
Subroutine transport_error: called CC=3 SCAR=12.0
Pod undocumented
354 2 my ($self, $reason) = @_;
355 2 ▶ $reason = 'transport error' unless defined($reason) && length($reason);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $reason and length $reason 0 2 2
Condition33%1/3
defined $reason and length $reason
!ll&&!rl&&r
002
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
356 2 $self->_transport_abort("$reason");
357 2 return $self;
358 }
359  
360 9 ▶sub resume_output {
Subroutine resume_output: called CC=9 SCAR=23.9
Pod undocumented
361 9 my ($self) = @_;
362 9 ▶ croak 'resume_output(): no attached transport' unless $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"transport_attached"} 0 9 9
363 croak 'resume_output(): cannot be called recursively from host send'
364 9 ▶ if $self->{transport_syncing};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_syncing"} 0 9 9
365 9 ▶ return $self if $self->{transport_finished} || $self->{transport_aborted};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_finished"} or $self->{"transport_aborted"} 2 7 9
Condition66%2/3
$self->{"transport_finished"} or $self->{"transport_aborted"}
l!l&&r!l&&!r
207
MC/DC50%1/2
$self->{"transport_finished"} or $self->{"transport_aborted"}
$self->{"transport_finished"} $self->{"transport_aborted"}
Truth table66%2/3
A or B
A= $self->{"transport_finished"}B= $self->{"transport_aborted"}
ABresult
1X1
011
000
366 7 $self->{transport_blocked} = 0;
367 7 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 7 0 7
368 7 ▶ 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"}) 7 0 7
Condition33%1/3
not $self->{"transport_blocked"} and length $self->{"output"} <= $self->{"low_water"}
!ll&&!rl&&r
007
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
369 7 $self->_maybe_drain;
370 7 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 7 0 7
371 }
372 7 return $self;
373 }
374  
375 0 ▶sub _deliver_switch_notice { return }
Subroutine _deliver_switch_notice: not called CC=1 SCAR=6.9
376  
377 12 ▶sub _mark_switched {
Subroutine _mark_switched: called CC=3 SCAR=11.0
378 12 my ($self) = @_;
379 12 ▶ return if $self->{switched};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"switched"} 0 12 12
380 12 $self->{switched} = 1;
381 12 ▶ if (!exists $self->{borrowed_input}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"borrowed_input"}) 9 3 12
382 9 $self->{remainder} .= $self->{input};
383 9 $self->{input} = '';
384 }
385 12 return;
386 }
387  
388 108 ▶sub _after_output {
Subroutine _after_output: called CC=2 SCAR=7.1
389 108 my ($self) = @_;
390 108 ▶ $self->_maybe_drain if length($self->{output}) <= $self->{low_water};
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"output"} <= $self->{"low_water"} 108 0 108
391 108 return;
392 }
393  
394 21 ▶sub _stream_ok {
Subroutine _stream_ok: called CC=3 SCAR=11.0
395 21 my ($self) = @_;
396 21 ▶ return 0 if $self->{transport_blocked};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_blocked"} 5 16 21
397 16 ▶ return length($self->{output}) < $self->{high_water} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
length $self->{'output'} < $self->{'high_water'} ? : 14 2 16
398 }
399  
400 0 ▶sub _maybe_drain { return }
Subroutine _maybe_drain: not called CC=1 SCAR=6.9
401 0 ▶sub _fail_all { return }
Subroutine _fail_all: not called CC=1 SCAR=6.9
402  
403 35 1;
« blib/lib/Unblock/HTTP1/Server.pm ↑ Summary blib/lib/Unblock/HTTP1/Transaction.pm »