blib/lib/Unblock/HTTP2/Transaction.pm

filter: Statementstmt 99.4% 171 / 172 Branchbran 62.1% 77 / 124 Conditioncond 44.0% 22 / 50 MC/DCmcdc 15.3% 4 / 26 Subroutinesub 100% 37 / 37 Podpod 0.0% 0 / 22 totaltotal 72.1% 311 / 431 CC 81 SCAR 19.0
CC
81
Cov
78%
auto_consume
15.3
_new
12.6
consume
9.9
CRAP 6.7
« blib/lib/Unblock/HTTP2/_Connection.pm ↑ Summary blib/lib/Unblock/HTTP2.pm »
1 package Unblock::HTTP2::Transaction;
2  
3 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 28 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 28 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 28 ▶use Scalar::Util qw(blessed weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 28 ▶use Uniform::HTTP::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 28 our $VERSION = '0.11';
10  
11 28 my %TERMINAL = map { $_ => 1 } qw(complete cancelled error);
12  
13 68 ▶sub _new {
Subroutine _new: called CC=9 SCAR=25.4
14 68 my ($class, %args) = @_;
15  
16 68 my $connection = delete $args{connection};
17 68 my $stream_id = delete $args{stream_id};
18 68 my $request = delete $args{request};
19 68 ▶ my $callbacks = delete($args{callbacks}) || {};
Condition50%1/2
delete $args{'callbacks'} || {}
l!l
680
MC/DC0%0/1
delete $args{'callbacks'} || {}
delete $args{'callbacks'}
Truth table50%1/2
A
A= delete $args{'callbacks'}
Aresult
11
00
20  
21 68 ▶ croak 'Transaction requires a connection object'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($connection) 0 68 68
22 unless blessed($connection);
23 68 ▶ croak 'Transaction stream id must be a positive integer'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stream_id and not ref $stream_id and $stream_id =~ /\A[0-9]+\z/ and $stream_id > 0 0 68 68
Condition33%3/9
defined $stream_id and not ref $stream_id and $stream_id =~ /\A[0-9]+\z/ and $stream_id > 0
!ll&&!rl&&r
0068
defined $stream_id and not ref $stream_id and $stream_id =~ /\A[0-9]+\z/
!ll&&!rl&&r
0068
defined $stream_id and not ref $stream_id
!ll&&!rl&&r
0068
MC/DC0%0/4
defined $stream_id and not ref $stream_id and $stream_id =~ /\A[0-9]+\z/ and $stream_id > 0
defined $stream_id not ref $stream_id $stream_id =~ /\A[0-9]+\z/ $stream_id > 0
Truth table20%1/5
A and not(B) and C and D
A= defined $stream_idB= not ref $stream_idC= $stream_id =~ /\A[0-9]+\z/D= $stream_id > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
24 unless defined($stream_id) && !ref($stream_id)
25 && $stream_id =~ /\A[0-9]+\z/ && $stream_id > 0;
26 68 ▶ croak 'Transaction callbacks must be a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $callbacks eq "HASH" 0 68 68
27 unless ref($callbacks) eq 'HASH';
28 68 ▶ croak 'unknown Transaction option: ' . join(', ', sort keys %args)
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 68 68
29 if %args;
30  
31 68 my $self = bless {
32 connection => $connection,
33 stream_id => 0 + $stream_id,
34 request => $request,
35 response => undef,
36 callbacks => { %$callbacks },
37 state => 'active',
38 error => undef,
39 error_code => undef,
40 reset_by_peer => undef,
41 auto_consume => 1,
42 unconsumed_bytes => 0,
43 }, $class;
44  
45 68 weaken($self->{connection});
46 68 return $self;
47 }
48  
49 205 ▶sub stream_id { return $_[0]{stream_id} }
Subroutine stream_id: called CC=1 SCAR=0.0
Pod undocumented
50 112 ▶sub request { return $_[0]{request} }
Subroutine request: called CC=1 SCAR=0.0
Pod undocumented
51 34 ▶sub response { return $_[0]{response} }
Subroutine response: called CC=1 SCAR=0.0
Pod undocumented
52 1 ▶sub state { return $_[0]{state} }
Subroutine state: called CC=1 SCAR=0.0
Pod undocumented
53 2 ▶sub error { return $_[0]{error} }
Subroutine error: called CC=1 SCAR=0.0
Pod undocumented
54 4 ▶sub error_code { return $_[0]{error_code} }
Subroutine error_code: called CC=1 SCAR=0.0
Pod undocumented
55 4 ▶sub reset_by_peer { return $_[0]{reset_by_peer} }
Subroutine reset_by_peer: called CC=1 SCAR=0.0
Pod undocumented
56 2 ▶sub error_name {
Subroutine error_name: called CC=2 SCAR=7.0
Pod undocumented
57 2 my ($self) = @_;
58 2 ▶ return unless defined $self->{error_code};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"error_code"} 0 2 2
59 2 require Unblock::HTTP2;
60 2 return Unblock::HTTP2->error_name($self->{error_code});
61 }
62 8 ▶sub unconsumed_bytes { return $_[0]{unconsumed_bytes} }
Subroutine unconsumed_bytes: called CC=1 SCAR=0.0
Pod undocumented
63 13 ▶sub is_complete { return $_[0]{state} eq 'complete' ? 1 : 0 }
Subroutine is_complete: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'state'} eq 'complete' ? : 12 1 13
64 3 ▶sub is_cancelled { return $_[0]{state} eq 'cancelled' ? 1 : 0 }
Subroutine is_cancelled: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'state'} eq 'cancelled' ? : 3 0 3
65 6 ▶sub is_error { return $_[0]{state} eq 'error' ? 1 : 0 }
Subroutine is_error: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'state'} eq 'error' ? : 2 4 6
66 253 ▶sub is_terminal { return $TERMINAL{$_[0]{state}} ? 1 : 0 }
Subroutine is_terminal: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$TERMINAL{$_[0]{'state'}} ? : 11 242 253
67  
68 8 ▶sub write {
Subroutine write: called CC=3 SCAR=11.4
Pod undocumented
69 8 my ($self, $bytes) = @_;
70 8 ▶ croak 'write(): Transaction is already terminal' if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 8 8
71  
72 my $connection = $self->{connection}
73 8 ▶ or croak 'write(): HTTP/2 connection is no longer available';
Branch: 1 branch
BranchTrueFalseTotal
my $connection = $self->{"connection"} or croak("write(): HTTP/2 connection is no longer available") 8 0 8
74  
75 8 return $connection->_write_stream_body($self, $bytes, 0, 'write');
76 }
77  
78 8 ▶sub end {
Subroutine end: called CC=5 SCAR=16.5
Pod undocumented
79 8 my ($self, @args) = @_;
80 8 ▶ croak 'end(): accepts at most one final byte string' if @args > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args > 1 0 8 8
81 8 ▶ croak 'end(): Transaction is already terminal' if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 8 8
82  
83 my $connection = $self->{connection}
84 8 ▶ or croak 'end(): HTTP/2 connection is no longer available';
Branch: 1 branch
BranchTrueFalseTotal
my $connection = $self->{"connection"} or croak("end(): HTTP/2 connection is no longer available") 8 0 8
85  
86 8 ▶ my $bytes = @args ? $args[0] : '';
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 4 4 8
87 8 $connection->_write_stream_body($self, $bytes, 1, 'end');
88 8 return $self;
89 }
90  
91 3 ▶sub send_informational {
Subroutine send_informational: called CC=6 SCAR=18.3
Pod undocumented
92 3 my ($self, @arg) = @_;
93 3 my $response;
94 3 ▶ if (@arg == 1 && ref($arg[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (@arg == 1 and ref $arg[0]) { } 2 1 3
Condition66%2/3
@arg == 1 and ref $arg[0]
!ll&&!rl&&r
102
MC/DC50%1/2
@arg == 1 and ref $arg[0]
@arg == 1 ref $arg[0]
Truth table66%2/3
A and B
A= @arg == 1B= ref $arg[0]
ABresult
0X0
100
111
95 2 $response = $arg[0];
96 }
97 else {
98 1 ▶ croak 'send_informational(): fields must be key/value pairs' if @arg % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @arg % 2 0 1 1
99 1 $response = Uniform::HTTP::Response->new(@arg);
100 }
101 3 ▶ croak 'send_informational(): Transaction is already terminal' if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 3 3
102  
103 my $connection = $self->{connection}
104 3 ▶ or croak 'send_informational(): HTTP/2 connection is no longer available';
Branch: 1 branch
BranchTrueFalseTotal
my $connection = $self->{"connection"} or croak("send_informational(): HTTP/2 connection is no longer available") 3 0 3
105  
106 3 $connection->_send_informational_stream($self, $response);
107 3 return $self;
108 }
109  
110 25 ▶sub respond {
Subroutine respond: called CC=9 SCAR=22.7
Pod undocumented
111 25 my ($self, @arg) = @_;
112 25 my ($response, %option);
113 25 ▶ if (@arg && ref($arg[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (@arg and ref $arg[0]) { } 23 2 25
Condition66%2/3
@arg and ref $arg[0]
!ll&&!rl&&r
0223
MC/DC50%1/2
@arg and ref $arg[0]
@arg ref $arg[0]
Truth table66%2/3
A and B
A= @argB= ref $arg[0]
ABresult
0X0
100
111
114 23 $response = shift @arg;
115 23 ▶ croak 'respond(): options must be key/value pairs' if @arg % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @arg % 2 0 23 23
116 23 %option = @arg;
117 }
118 else {
119 2 ▶ croak 'respond(): fields must be key/value pairs' if @arg % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @arg % 2 0 2 2
120 2 my %field = @arg;
121 2 for my $name (qw(stream_body on_drain on_error)) {
122 6 ▶ $option{$name} = delete $field{$name} if exists $field{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $field{$name} 0 6 6
123 }
124 2 $response = Uniform::HTTP::Response->new(%field);
125 }
126 25 ▶ croak 'respond(): Transaction is already terminal' if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 25 25
127  
128 my $connection = $self->{connection}
129 25 ▶ or croak 'respond(): HTTP/2 connection is no longer available';
Branch: 1 branch
BranchTrueFalseTotal
my $connection = $self->{"connection"} or croak("respond(): HTTP/2 connection is no longer available") 25 0 25
130  
131 25 $connection->_respond_stream($self, $response, %option);
132 25 return $self;
133 }
134  
135 4 ▶sub update_priority {
Subroutine update_priority: called CC=3 SCAR=11.3
Pod undocumented
136 4 my ($self, $field_value) = @_;
137 4 ▶ croak 'update_priority(): Transaction is already terminal' if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 4 4
138  
139 my $connection = $self->{connection}
140 4 ▶ or croak 'update_priority(): HTTP/2 connection is no longer available';
Branch: 1 branch
BranchTrueFalseTotal
my $connection = $self->{"connection"} or croak("update_priority(): HTTP/2 connection is no longer available") 4 0 4
141  
142 4 $connection->_update_stream_priority($self, $field_value);
143 1 return $self;
144 }
145  
146 4 ▶sub reset {
Subroutine reset: called CC=7 SCAR=21.8
Pod undocumented
147 4 my ($self, $error_code) = @_;
148 4 ▶ croak 'reset(): Transaction is already terminal' if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 4 4
149 4 ▶ croak 'reset(): error code must be an unsigned 32-bit integer'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $error_code and not ref $error_code and "$error_code" =~ /\A[0-9]+\z/ and $error_code <= 4294967295 1 3 4
Condition44%4/9
defined $error_code and not ref $error_code and "$error_code" =~ /\A[0-9]+\z/ and $error_code <= 4294967295
!ll&&!rl&&r
013
defined $error_code and not ref $error_code and "$error_code" =~ /\A[0-9]+\z/
!ll&&!rl&&r
004
defined $error_code and not ref $error_code
!ll&&!rl&&r
004
MC/DC25%1/4
defined $error_code and not ref $error_code and "$error_code" =~ /\A[0-9]+\z/ and $error_code <= 4294967295
defined $error_code not ref $error_code "$error_code" =~ /\A[0-9]+\z/ $error_code <= 4294967295
Truth table40%2/5
A and not(B) and C and D
A= defined $error_codeB= not ref $error_codeC= "$error_code" =~ /\A[0-9]+\z/D= $error_code <= 4294967295
ABCDresult
0XXX0
10XX0
110X0
11100
11111
150 unless defined($error_code) && !ref($error_code)
151 && "$error_code" =~ /\A[0-9]+\z/
152 && $error_code <= 4_294_967_295;
153  
154 my $connection = $self->{connection}
155 3 ▶ or croak 'reset(): HTTP/2 connection is no longer available';
Branch: 1 branch
BranchTrueFalseTotal
my $connection = $self->{"connection"} or croak("reset(): HTTP/2 connection is no longer available") 3 0 3
156  
157 3 $connection->_reset_stream($self, 0 + $error_code);
158 3 return $self;
159 }
160  
161 2 ▶sub cancel {
Subroutine cancel: called CC=2 SCAR=7.1
Pod undocumented
162 2 my ($self) = @_;
163 2 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 2 2
164 2 return $self->reset(8);
165 }
166  
167 6 ▶sub auto_consume {
Subroutine auto_consume: called CC=13 SCAR=27.3
Pod undocumented
168 6 my ($self, @args) = @_;
169  
170 6 ▶ return $self->{auto_consume} ? 1 : 0 unless @args;
Branch: 2 branches
BranchTrueFalseTotal
unless @args 3 3 6
$self->{'auto_consume'} ? : 1 2 3
171  
172 3 ▶ croak 'auto_consume(): accepts exactly one zero-or-one value'
Branch: 1 branch
BranchTrueFalseTotal
unless @args == 1 0 3 3
173 unless @args == 1;
174 3 ▶ croak 'auto_consume(): Transaction is already terminal'
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 3 3
175 if $self->is_terminal;
176  
177 3 my $value = $args[0];
178 3 ▶ croak 'auto_consume(): value must be zero or one'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or ref $value or not "$value" =~ /\A[01]\z/ 0 3 3
Condition33%2/6
not defined $value or ref $value or not "$value" =~ /\A[01]\z/
l!l&&r!l&&!r
003
not defined $value or ref $value
l!l&&r!l&&!r
003
MC/DC0%0/3
not defined $value or ref $value or not "$value" =~ /\A[01]\z/
not defined $value ref $value not "$value" =~ /\A[01]\z/
Truth table25%1/4
not(A) or B or not(C)
A= not defined $valueB= ref $valueC= not "$value" =~ /\A[01]\z/
ABCresult
1XX1
01X1
0011
0000
179 if !defined($value) || ref($value) || "$value" !~ /\A[01]\z/;
180 3 ▶ $value = $value ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 1 2 3
181  
182 3 ▶ if ($value && !$self->{auto_consume} && $self->{unconsumed_bytes}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value and not $self->{"auto_consume"} and $self->{"unconsumed_bytes"}) 1 2 3
Condition66%4/6
$value and not $self->{"auto_consume"} and $self->{"unconsumed_bytes"}
!ll&&!rl&&r
201
$value and not $self->{"auto_consume"}
!ll&&!rl&&r
201
MC/DC33%1/3
$value and not $self->{"auto_consume"} and $self->{"unconsumed_bytes"}
$value not $self->{"auto_consume"} $self->{"unconsumed_bytes"}
Truth table50%2/4
A and not(B) and C
A= $valueB= not $self->{"auto_consume"}C= $self->{"unconsumed_bytes"}
ABCresult
0XX0
10X0
1100
1111
183 my $connection = $self->{connection}
184 1 ▶ or croak 'auto_consume(): HTTP/2 connection is no longer available';
Branch: 1 branch
BranchTrueFalseTotal
my $connection = $self->{"connection"} or croak("auto_consume(): HTTP/2 connection is no longer available") 1 0 1
185  
186 1 my $bytes = $self->{unconsumed_bytes};
187 1 $connection->_consume_stream_body($self, $bytes);
188 1 $self->{unconsumed_bytes} -= $bytes;
189 }
190  
191 3 $self->{auto_consume} = $value;
192 3 return $self;
193 }
194  
195 6 ▶sub consume {
Subroutine consume: called CC=8 SCAR=22.9
Pod undocumented
196 6 my ($self, $bytes) = @_;
197  
198 6 ▶ croak 'consume(): Transaction is already terminal' if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 6 6
199 6 ▶ croak 'consume(): bytes must be a non-negative integer'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes and not ref $bytes and "$bytes" =~ /\A[0-9]+\z/ 0 6 6
Condition33%2/6
defined $bytes and not ref $bytes and "$bytes" =~ /\A[0-9]+\z/
!ll&&!rl&&r
006
defined $bytes and not ref $bytes
!ll&&!rl&&r
006
MC/DC0%0/3
defined $bytes and not ref $bytes and "$bytes" =~ /\A[0-9]+\z/
defined $bytes not ref $bytes "$bytes" =~ /\A[0-9]+\z/
Truth table25%1/4
A and not(B) and C
A= defined $bytesB= not ref $bytesC= "$bytes" =~ /\A[0-9]+\z/
ABCresult
0XX0
10X0
1100
1111
200 unless defined($bytes) && !ref($bytes) && "$bytes" =~ /\A[0-9]+\z/;
201  
202 6 $bytes = 0 + $bytes;
203 croak 'consume(): cannot consume more bytes than have been delivered'
204 6 ▶ if $bytes > $self->{unconsumed_bytes};
Branch: 1 branch
BranchTrueFalseTotal
if $bytes > $self->{"unconsumed_bytes"} 1 5 6
205 5 ▶ return $self unless $bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless $bytes 0 5 5
206  
207 my $connection = $self->{connection}
208 5 ▶ or croak 'consume(): HTTP/2 connection is no longer available';
Branch: 1 branch
BranchTrueFalseTotal
my $connection = $self->{"connection"} or croak("consume(): HTTP/2 connection is no longer available") 5 0 5
209  
210 5 $connection->_consume_stream_body($self, $bytes);
211 5 $self->{unconsumed_bytes} -= $bytes;
212 5 return $self;
213 }
214  
215 53 ▶sub _receive_body_bytes {
Subroutine _receive_body_bytes: called CC=2 SCAR=7.1
216 53 my ($self, $bytes) = @_;
217 53 ▶ $self->{unconsumed_bytes} += $bytes if $bytes;
Branch: 1 branch
BranchTrueFalseTotal
if $bytes 53 0 53
218 53 return $self;
219 }
220  
221 53 ▶sub _auto_consume_body {
Subroutine _auto_consume_body: called CC=5 SCAR=16.4
222 53 my ($self) = @_;
223 53 ▶ return $self unless $self->{auto_consume};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"auto_consume"} 7 46 53
224 46 ▶ return $self unless $self->{unconsumed_bytes};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"unconsumed_bytes"} 0 46 46
225 46 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 46 46
226  
227 46 ▶ my $connection = $self->{connection} or return $self;
Branch: 1 branch
BranchTrueFalseTotal
my $connection = $self->{"connection"} or return $self 46 0 46
228 46 my $bytes = $self->{unconsumed_bytes};
229 46 $connection->_consume_stream_body($self, $bytes);
230 46 $self->{unconsumed_bytes} -= $bytes;
231 46 return $self;
232 }
233  
234 2 ▶sub _set_callback {
Subroutine _set_callback: called CC=4 SCAR=15.9
235 2 my ($self, $name, $callback) = @_;
236 2 ▶ croak "_set_callback(): callback must be a coderef"
Branch: 1 branch
BranchTrueFalseTotal
if defined $callback and ref $callback ne "CODE" 0 2 2
Condition33%1/3
defined $callback and ref $callback ne "CODE"
!ll&&!rl&&r
020
MC/DC0%0/2
defined $callback and ref $callback ne "CODE"
defined $callback ref $callback ne "CODE"
Truth table33%1/3
A and B
A= defined $callbackB= ref $callback ne "CODE"
ABresult
0X0
100
111
237 if defined($callback) && ref($callback) ne 'CODE';
238  
239 2 ▶ if ($callback) {
Branch: 1 branch
BranchTrueFalseTotal
if ($callback) { } 2 0 2
240 2 $self->{callbacks}{$name} = $callback;
241 }
242 else {
243 0 delete $self->{callbacks}{$name};
244 }
245  
246 2 return $self;
247 }
248  
249 50 ▶sub _set_response {
Subroutine _set_response: called CC=2 SCAR=7.0
250 50 my ($self, $response) = @_;
251 50 ▶ croak 'Transaction already has a Response' if $self->{response};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"response"} 0 50 50
252 50 $self->{response} = $response;
253 50 return $response;
254 }
255  
256 49 ▶sub _mark_complete {
Subroutine _mark_complete: called CC=2 SCAR=7.0
257 49 my ($self) = @_;
258 49 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 49 49
259 49 $self->{state} = 'complete';
260 49 return $self;
261 }
262  
263 3 ▶sub _mark_cancelled {
Subroutine _mark_cancelled: called CC=4 SCAR=14.3
264 3 my ($self, $error_code, $by_peer) = @_;
265 3 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 3 3
266 3 $self->{state} = 'cancelled';
267 3 ▶ if (defined $error_code) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error_code) 3 0 3
268 3 $self->{error_code} = 0 + $error_code;
269 3 ▶ $self->{reset_by_peer} = $by_peer ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$by_peer ? : 0 3 3
270 }
271 3 return $self;
272 }
273  
274 11 ▶sub _fail {
Subroutine _fail: called CC=6 SCAR=18.8
275 11 my ($self, $error, $error_code, $by_peer) = @_;
276 11 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 11 11
277  
278 11 ▶ $error = 'HTTP/2 stream failed'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $error and length $error 0 11 11
Condition33%1/3
defined $error and length $error
!ll&&!rl&&r
0011
MC/DC0%0/2
defined $error and length $error
defined $error length $error
Truth table33%1/3
A and B
A= defined $errorB= length $error
ABresult
0X0
100
111
279 unless defined($error) && length($error);
280  
281 11 $self->{state} = 'error';
282 11 $self->{error} = "$error";
283 11 ▶ if (defined $error_code) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error_code) 6 5 11
284 6 $self->{error_code} = 0 + $error_code;
285 6 ▶ $self->{reset_by_peer} = $by_peer ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$by_peer ? : 6 0 6
286 }
287 11 return $self;
288 }
289  
290 100 ▶sub _invoke {
Subroutine _invoke: called CC=3 SCAR=11.0
291 100 my ($self, $name, @args) = @_;
292 100 ▶ my $callback = $self->{callbacks}{$name} or return 1;
Branch: 1 branch
BranchTrueFalseTotal
my $callback = $self->{"callbacks"}{$name} or return 1 67 33 100
293  
294 67 my $ok = eval {
295 67 $callback->($self, @args);
296 67 1;
297 };
298  
299 67 ▶ return $ok ? 1 : $@;
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 67 0 67
300 }
301  
302 3 ▶sub _drain {
Subroutine _drain: called CC=1 SCAR=0.0
303 3 my ($self) = @_;
304 3 my $result = $self->_invoke('on_drain');
305 3 return $result;
306 }
307  
308 28 1;
309  
310 __END__
« blib/lib/Unblock/HTTP2/_Connection.pm ↑ Summary blib/lib/Unblock/HTTP2.pm »