blib/lib/Unblock/HTTP2/Transaction.pm

filter: Statementstmt 98.3% 233 / 237 Branchbran 66.0% 107 / 162 Conditioncond 50.0% 39 / 78 MC/DCmcdc 21.4% 9 / 42 Subroutinesub 100% 42 / 42 Podpod 0.0% 0 / 24 totaltotal 73.5% 430 / 585 CC 110 SCAR 19.9
CC
110
Cov
79%
_new
17.0
auto_consume
15.3
on_data
11.4
CRAP 7.3
« blib/lib/Unblock/HTTP2/_Connection.pm ↑ Summary blib/lib/Unblock/HTTP2.pm »
1 package Unblock::HTTP2::Transaction;
2  
3 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 30 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 30 ▶use Scalar::Util qw(blessed weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 30 ▶use Uniform::HTTP::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 30 our $VERSION = '0.13';
10  
11 30 my %TERMINAL = map { $_ => 1 } qw(complete cancelled error);
12  
13 7367 ▶sub _new {
Subroutine _new: called CC=12 SCAR=28.3
14 7367 my ($class, %args) = @_;
15  
16 7367 my $connection = delete $args{connection};
17 7367 my $stream_id = delete $args{stream_id};
18 7367 my $request = delete $args{request};
19 7367 ▶ my $callbacks = delete($args{callbacks}) || {};
Condition50%1/2
delete $args{'callbacks'} || {}
l!l
73670
MC/DC0%0/1
delete $args{'callbacks'} || {}
delete $args{'callbacks'}
Truth table50%1/2
A
A= delete $args{'callbacks'}
Aresult
11
00
20  
21 7367 ▶ croak 'Transaction requires a connection object'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($connection) 0 7367 7367
22 unless blessed($connection);
23 7367 ▶ 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 7367 7367
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
007367
defined $stream_id and not ref $stream_id and $stream_id =~ /\A[0-9]+\z/
!ll&&!rl&&r
007367
defined $stream_id and not ref $stream_id
!ll&&!rl&&r
007367
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 7367 ▶ croak 'Transaction callbacks must be a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $callbacks eq "HASH" 0 7367 7367
27 unless ref($callbacks) eq 'HASH';
28 7367 ▶ croak 'unknown Transaction option: ' . join(', ', sort keys %args)
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 7367 7367
29 if %args;
30  
31 7367 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 7367 $self->{receive_body} = $connection->{receive_body};
46 7367 $self->{max_buffered_body_bytes} = $connection->{max_buffered_body_bytes};
47 7367 my $on_data = delete $self->{callbacks}{on_data};
48 7367 ▶ $self->on_data($on_data) if $on_data;
Branch: 1 branch
BranchTrueFalseTotal
if $on_data 0 7367 7367
49 croak 'buffered reception cannot be combined with on_body'
50 7367 ▶ 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 7367 7367
Condition66%2/3
$self->{"receive_body"} eq "buffered" and $self->{"callbacks"}{"on_body"}
!ll&&!rl&&r
7344230
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
51 7367 weaken($self->{connection});
52 7367 return $self;
53 }
54  
55 23651 ▶sub stream_id { return $_[0]{stream_id} }
Subroutine stream_id: called CC=1 SCAR=0.0
Pod undocumented
56 28990 ▶sub request { return $_[0]{request} }
Subroutine request: called CC=1 SCAR=0.0
Pod undocumented
57 7232 ▶sub response { return $_[0]{response} }
Subroutine response: called CC=1 SCAR=0.0
Pod undocumented
58 23 ▶sub state { return $_[0]{state} }
Subroutine state: called CC=1 SCAR=0.0
Pod undocumented
59 2 ▶sub error { return $_[0]{error} }
Subroutine error: called CC=1 SCAR=0.0
Pod undocumented
60 4 ▶sub error_code { return $_[0]{error_code} }
Subroutine error_code: called CC=1 SCAR=0.0
Pod undocumented
61 4 ▶sub reset_by_peer { return $_[0]{reset_by_peer} }
Subroutine reset_by_peer: called CC=1 SCAR=0.0
Pod undocumented
62 2 ▶sub error_name {
Subroutine error_name: called CC=2 SCAR=7.0
Pod undocumented
63 2 my ($self) = @_;
64 2 ▶ return unless defined $self->{error_code};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"error_code"} 0 2 2
65 2 require Unblock::HTTP2;
66 2 return Unblock::HTTP2->error_name($self->{error_code});
67 }
68 8 ▶sub unconsumed_bytes { return $_[0]{unconsumed_bytes} }
Subroutine unconsumed_bytes: called CC=1 SCAR=0.0
Pod undocumented
69 21 ▶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' ? : 20 1 21
70 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
71 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
72 36887 ▶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'}} ? : 7440 29447 36887
73  
74 5 ▶sub on_data {
Subroutine on_data: called CC=9 SCAR=24.4
Pod undocumented
75 5 my ($self, $cb) = @_;
76 5 ▶ croak 'on_data(): callback must be a coderef' unless ref($cb) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cb eq "CODE" 0 5 5
77 croak 'on_data(): receive body has already started or finished'
78 5 ▶ if $self->{receive_started} || $self->{receive_done} || $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"receive_started"} or $self->{"receive_done"} or $self->is_terminal 2 3 5
Condition66%4/6
$self->{"receive_started"} or $self->{"receive_done"} or $self->is_terminal
l!l&&r!l&&!r
203
$self->{"receive_started"} or $self->{"receive_done"}
l!l&&r!l&&!r
203
MC/DC33%1/3
$self->{"receive_started"} or $self->{"receive_done"} or $self->is_terminal
$self->{"receive_started"} $self->{"receive_done"} $self->is_terminal
Truth table50%2/4
A or B or C
A= $self->{"receive_started"}B= $self->{"receive_done"}C= $self->is_terminal
ABCresult
1XX1
01X1
0011
0000
79 3 my $owner = $self->{connection};
80 croak 'on_data(): cannot be combined with on_body'
81 3 ▶ if $self->{callbacks}{on_body} || ($owner && $owner->{callbacks}{on_body});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"callbacks"}{"on_body"} or $owner and $owner->{"callbacks"}{"on_body"} 0 3 3
Condition33%2/6
$self->{"callbacks"}{"on_body"} or $owner and $owner->{"callbacks"}{"on_body"}
l!l&&r!l&&!r
003
$owner and $owner->{"callbacks"}{"on_body"}
!ll&&!rl&&r
030
MC/DC0%0/3
$self->{"callbacks"}{"on_body"} or $owner and $owner->{"callbacks"}{"on_body"}
$self->{"callbacks"}{"on_body"} $owner $owner->{"callbacks"}{"on_body"}
Truth table25%1/4
A or B and C
A= $self->{"callbacks"}{"on_body"}B= $ownerC= $owner->{"callbacks"}{"on_body"}
ABCresult
1XX1
0111
00X0
0100
82 3 ▶ croak 'on_data(): callback is already registered' if $self->{callbacks}{on_data};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"callbacks"}{"on_data"} 0 3 3
83 3 $self->{callbacks}{on_data} = $cb;
84 3 $self->{receive_body} = 'stream';
85 3 return $self;
86 }
87  
88 13 ▶sub on_finish {
Subroutine on_finish: called CC=4 SCAR=14.5
Pod undocumented
89 13 my ($self, $cb) = @_;
90 13 ▶ croak 'on_finish(): callback must be a coderef' unless ref($cb) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cb eq "CODE" 0 13 13
91 13 ▶ croak 'on_finish(): Transaction is terminal' if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 13 13
92 13 ▶ croak 'on_finish(): callback is already registered' if $self->{callbacks}{on_finish};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"callbacks"}{"on_finish"} 0 13 13
93 13 $self->{callbacks}{on_finish} = $cb;
94 13 return $self;
95 }
96  
97 91 ▶sub _receive_data {
Subroutine _receive_data: called CC=8 SCAR=20.8
98 91 my ($self, $message, $bytes) = @_;
99 91 ▶ return 1 if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 91 91
100 91 $self->{receive_started} = 1;
101 91 ▶ if ($self->{receive_body} eq 'buffered') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"receive_body"} eq "buffered") 13 78 91
102 13 ▶ my $size = ($self->{received_bytes} || 0) + length($bytes);
Condition100%2/2
$self->{'received_bytes'} || 0
l!l
112
MC/DC100%1/1
$self->{'received_bytes'} || 0
$self->{'received_bytes'}
Truth table100%2/2
A
A= $self->{'received_bytes'}
Aresult
11
00
103 13 ▶ if ($size > $self->{max_buffered_body_bytes}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size > $self->{"max_buffered_body_bytes"}) 2 11 13
104 2 delete $self->{receive_chunks};
105 2 delete $self->{received_bytes};
106 2 return 'received body exceeds max_buffered_body_bytes';
107 }
108 11 push @{ $self->{receive_chunks} }, $bytes;
109 11 $self->{received_bytes} = $size;
110 11 return 1;
111 }
112 78 ▶ return $self->_invoke('on_data', $bytes) if $self->{callbacks}{on_data};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"callbacks"}{"on_data"} 3 75 78
113 75 my $owner = $self->{connection};
114 75 ▶ return $owner->_invoke_callback('on_body', $self, $message, $bytes)
Branch: 1 branch
BranchTrueFalseTotal
if $owner and $owner->can("_invoke_callback") 33 42 75
Condition66%2/3
$owner and $owner->can("_invoke_callback")
!ll&&!rl&&r
04233
MC/DC50%1/2
$owner and $owner->can("_invoke_callback")
$owner $owner->can("_invoke_callback")
Truth table66%2/3
A and B
A= $ownerB= $owner->can("_invoke_callback")
ABresult
0X0
100
111
115 if $owner && $owner->can('_invoke_callback');
116 42 return $self->_invoke('on_body', $message, $bytes);
117 }
118  
119 7276 ▶sub _finish_receive {
Subroutine _finish_receive: called CC=4 SCAR=13.9
120 7276 my ($self, $message) = @_;
121 7276 $self->{receive_done} = 1;
122 7276 ▶ if ($self->{receive_body} eq 'buffered' && $message->body_is_mutable) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"receive_body"} eq "buffered" and $message->body_is_mutable) 9 7267 7276
Condition100%3/3
$self->{"receive_body"} eq "buffered" and $message->body_is_mutable
!ll&&!rl&&r
726529
MC/DC100%2/2
$self->{"receive_body"} eq "buffered" and $message->body_is_mutable
$self->{"receive_body"} eq "buffered" $message->body_is_mutable
Truth table100%3/3
A and B
A= $self->{"receive_body"} eq "buffered"B= $message->body_is_mutable
ABresult
0X0
100
111
123 9 ▶ $message->body(join '', @{ delete($self->{receive_chunks}) || [] });
Condition50%1/2
delete $self->{'receive_chunks'} || []
l!l
90
MC/DC0%0/1
delete $self->{'receive_chunks'} || []
delete $self->{'receive_chunks'}
Truth table50%1/2
A
A= delete $self->{'receive_chunks'}
Aresult
11
00
124 }
125 7276 delete $self->{receive_chunks};
126 7276 delete $self->{received_bytes};
127 7276 return;
128 }
129  
130 7381 ▶sub _notify_finish {
Subroutine _notify_finish: called CC=4 SCAR=14.2
131 7381 my ($self) = @_;
132 7381 ▶ return unless $self->is_terminal && !$self->{finish_called};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_terminal and not $self->{"finish_called"} 0 7381 7381
Condition33%1/3
$self->is_terminal and not $self->{"finish_called"}
!ll&&!rl&&r
007381
MC/DC0%0/2
$self->is_terminal and not $self->{"finish_called"}
$self->is_terminal not $self->{"finish_called"}
Truth table33%1/3
A and not(B)
A= $self->is_terminalB= not $self->{"finish_called"}
ABresult
0X0
100
111
133 7381 $self->{finish_pending} = 1;
134 7381 ▶ return if $self->{callback_depth};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"callback_depth"} 44 7337 7381
135 7337 $self->{finish_called} = 1;
136 7337 delete $self->{finish_pending};
137 # Terminal observers cannot undo cleanup or recursively report an error.
138 7337 $self->_invoke('on_finish');
139 7337 return;
140 }
141  
142 11 ▶sub write {
Subroutine write: called CC=3 SCAR=11.4
Pod undocumented
143 11 my ($self, $bytes) = @_;
144 11 ▶ croak 'write(): Transaction is already terminal' if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 11 11
145  
146 my $connection = $self->{connection}
147 11 ▶ 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") 11 0 11
148  
149 11 return $connection->_write_stream_body($self, $bytes, 0, 'write');
150 }
151  
152 9 ▶sub end {
Subroutine end: called CC=5 SCAR=16.5
Pod undocumented
153 9 my ($self, @args) = @_;
154 9 ▶ croak 'end(): accepts at most one final byte string' if @args > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args > 1 0 9 9
155 9 ▶ croak 'end(): Transaction is already terminal' if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 9 9
156  
157 my $connection = $self->{connection}
158 9 ▶ 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") 9 0 9
159  
160 9 ▶ my $bytes = @args ? $args[0] : '';
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 5 4 9
161 9 $connection->_write_stream_body($self, $bytes, 1, 'end');
162 9 return $self;
163 }
164  
165 3 ▶sub send_informational {
Subroutine send_informational: called CC=6 SCAR=18.3
Pod undocumented
166 3 my ($self, @arg) = @_;
167 3 my $response;
168 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
169 2 $response = $arg[0];
170 }
171 else {
172 1 ▶ croak 'send_informational(): fields must be key/value pairs' if @arg % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @arg % 2 0 1 1
173 1 $response = Uniform::HTTP::Response->new(@arg);
174 }
175 3 ▶ croak 'send_informational(): Transaction is already terminal' if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 3 3
176  
177 my $connection = $self->{connection}
178 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
179  
180 3 $connection->_send_informational_stream($self, $response);
181 3 return $self;
182 }
183  
184 7217 ▶sub respond {
Subroutine respond: called CC=9 SCAR=22.7
Pod undocumented
185 7217 my ($self, @arg) = @_;
186 7217 my ($response, %option);
187 7217 ▶ if (@arg && ref($arg[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (@arg and ref $arg[0]) { } 7208 9 7217
Condition66%2/3
@arg and ref $arg[0]
!ll&&!rl&&r
097208
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
188 7208 $response = shift @arg;
189 7208 ▶ croak 'respond(): options must be key/value pairs' if @arg % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @arg % 2 0 7208 7208
190 7208 %option = @arg;
191 }
192 else {
193 9 ▶ croak 'respond(): fields must be key/value pairs' if @arg % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @arg % 2 0 9 9
194 9 my %field = @arg;
195 9 for my $name (qw(stream_body on_drain on_error)) {
196 27 ▶ $option{$name} = delete $field{$name} if exists $field{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $field{$name} 0 27 27
197 }
198 9 $response = Uniform::HTTP::Response->new(%field);
199 }
200 7217 ▶ croak 'respond(): Transaction is already terminal' if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 7217 7217
201  
202 my $connection = $self->{connection}
203 7217 ▶ 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") 7217 0 7217
204  
205 7217 $connection->_respond_stream($self, $response, %option);
206 7217 return $self;
207 }
208  
209 4 ▶sub update_priority {
Subroutine update_priority: called CC=3 SCAR=11.3
Pod undocumented
210 4 my ($self, $field_value) = @_;
211 4 ▶ croak 'update_priority(): Transaction is already terminal' if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 4 4
212  
213 my $connection = $self->{connection}
214 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
215  
216 4 $connection->_update_stream_priority($self, $field_value);
217 1 return $self;
218 }
219  
220 47 ▶sub reset {
Subroutine reset: called CC=7 SCAR=21.8
Pod undocumented
221 47 my ($self, $error_code) = @_;
222 47 ▶ croak 'reset(): Transaction is already terminal' if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 47 47
223 47 ▶ 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 46 47
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
0146
defined $error_code and not ref $error_code and "$error_code" =~ /\A[0-9]+\z/
!ll&&!rl&&r
0047
defined $error_code and not ref $error_code
!ll&&!rl&&r
0047
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
224 unless defined($error_code) && !ref($error_code)
225 && "$error_code" =~ /\A[0-9]+\z/
226 && $error_code <= 4_294_967_295;
227  
228 my $connection = $self->{connection}
229 46 ▶ 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") 46 0 46
230  
231 46 $connection->_reset_stream($self, 0 + $error_code);
232 46 return $self;
233 }
234  
235 46 ▶sub cancel {
Subroutine cancel: called CC=3 SCAR=12.3
Pod undocumented
236 46 my ($self) = @_;
237 46 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 1 45 46
238 45 ▶ if (!$self->{connection}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"connection"}) 0 45 45
239 0 $self->_mark_cancelled(8, 0);
240 0 $self->_notify_finish;
241 0 return $self;
242 }
243 45 return $self->reset(8);
244 }
245  
246 6 ▶sub auto_consume {
Subroutine auto_consume: called CC=13 SCAR=27.3
Pod undocumented
247 6 my ($self, @args) = @_;
248  
249 6 ▶ return $self->{auto_consume} ? 1 : 0 unless @args;
Branch: 2 branches
BranchTrueFalseTotal
unless @args 3 3 6
$self->{'auto_consume'} ? : 1 2 3
250  
251 3 ▶ croak 'auto_consume(): accepts exactly one zero-or-one value'
Branch: 1 branch
BranchTrueFalseTotal
unless @args == 1 0 3 3
252 unless @args == 1;
253 3 ▶ croak 'auto_consume(): Transaction is already terminal'
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 3 3
254 if $self->is_terminal;
255  
256 3 my $value = $args[0];
257 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
258 if !defined($value) || ref($value) || "$value" !~ /\A[01]\z/;
259 3 ▶ $value = $value ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 1 2 3
260  
261 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
262 my $connection = $self->{connection}
263 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
264  
265 1 my $bytes = $self->{unconsumed_bytes};
266 1 $connection->_consume_stream_body($self, $bytes);
267 1 $self->{unconsumed_bytes} -= $bytes;
268 }
269  
270 3 $self->{auto_consume} = $value;
271 3 return $self;
272 }
273  
274 6 ▶sub consume {
Subroutine consume: called CC=8 SCAR=22.9
Pod undocumented
275 6 my ($self, $bytes) = @_;
276  
277 6 ▶ croak 'consume(): Transaction is already terminal' if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 6 6
278 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
279 unless defined($bytes) && !ref($bytes) && "$bytes" =~ /\A[0-9]+\z/;
280  
281 6 $bytes = 0 + $bytes;
282 croak 'consume(): cannot consume more bytes than have been delivered'
283 6 ▶ if $bytes > $self->{unconsumed_bytes};
Branch: 1 branch
BranchTrueFalseTotal
if $bytes > $self->{"unconsumed_bytes"} 1 5 6
284 5 ▶ return $self unless $bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless $bytes 0 5 5
285  
286 my $connection = $self->{connection}
287 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
288  
289 5 $connection->_consume_stream_body($self, $bytes);
290 5 $self->{unconsumed_bytes} -= $bytes;
291 5 return $self;
292 }
293  
294 91 ▶sub _receive_body_bytes {
Subroutine _receive_body_bytes: called CC=2 SCAR=7.1
295 91 my ($self, $bytes) = @_;
296 91 ▶ $self->{unconsumed_bytes} += $bytes if $bytes;
Branch: 1 branch
BranchTrueFalseTotal
if $bytes 91 0 91
297 91 return $self;
298 }
299  
300 89 ▶sub _auto_consume_body {
Subroutine _auto_consume_body: called CC=5 SCAR=16.2
301 89 my ($self) = @_;
302 89 ▶ return $self unless $self->{auto_consume};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"auto_consume"} 7 82 89
303 82 ▶ return $self unless $self->{unconsumed_bytes};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"unconsumed_bytes"} 0 82 82
304 82 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 1 81 82
305  
306 81 ▶ my $connection = $self->{connection} or return $self;
Branch: 1 branch
BranchTrueFalseTotal
my $connection = $self->{"connection"} or return $self 81 0 81
307 81 my $bytes = $self->{unconsumed_bytes};
308 81 $connection->_consume_stream_body($self, $bytes);
309 81 $self->{unconsumed_bytes} -= $bytes;
310 81 return $self;
311 }
312  
313 2 ▶sub _set_callback {
Subroutine _set_callback: called CC=4 SCAR=15.9
314 2 my ($self, $name, $callback) = @_;
315 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
316 if defined($callback) && ref($callback) ne 'CODE';
317  
318 2 ▶ if ($callback) {
Branch: 1 branch
BranchTrueFalseTotal
if ($callback) { } 2 0 2
319 2 $self->{callbacks}{$name} = $callback;
320 }
321 else {
322 0 delete $self->{callbacks}{$name};
323 }
324  
325 2 return $self;
326 }
327  
328 7257 ▶sub _set_response {
Subroutine _set_response: called CC=2 SCAR=7.0
329 7257 my ($self, $response) = @_;
330 7257 ▶ croak 'Transaction already has a Response' if $self->{response};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"response"} 0 7257 7257
331 7257 $self->{response} = $response;
332 7257 return $response;
333 }
334  
335 7248 ▶sub _mark_complete {
Subroutine _mark_complete: called CC=2 SCAR=7.0
336 7248 my ($self) = @_;
337 7248 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 7248 7248
338 7248 $self->{state} = 'complete';
339 7248 return $self;
340 }
341  
342 46 ▶sub _mark_cancelled {
Subroutine _mark_cancelled: called CC=4 SCAR=14.2
343 46 my ($self, $error_code, $by_peer) = @_;
344 46 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 46 46
345 46 delete $self->{receive_chunks};
346 46 delete $self->{received_bytes};
347 46 $self->{state} = 'cancelled';
348 46 ▶ if (defined $error_code) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error_code) 46 0 46
349 46 $self->{error_code} = 0 + $error_code;
350 46 ▶ $self->{reset_by_peer} = $by_peer ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$by_peer ? : 0 46 46
351 }
352 46 return $self;
353 }
354  
355 43 ▶sub _fail {
Subroutine _fail: called CC=6 SCAR=18.3
356 43 my ($self, $error, $error_code, $by_peer) = @_;
357 43 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 43 43
358  
359 43 ▶ $error = 'HTTP/2 stream failed'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $error and length $error 0 43 43
Condition33%1/3
defined $error and length $error
!ll&&!rl&&r
0043
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
360 unless defined($error) && length($error);
361  
362 43 delete $self->{receive_chunks};
363 43 delete $self->{received_bytes};
364 43 $self->{state} = 'error';
365 43 $self->{error} = "$error";
366 43 ▶ if (defined $error_code) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error_code) 37 6 43
367 37 $self->{error_code} = 0 + $error_code;
368 37 ▶ $self->{reset_by_peer} = $by_peer ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$by_peer ? : 35 2 37
369 }
370 43 return $self;
371 }
372  
373 7510 ▶sub _invoke {
Subroutine _invoke: called CC=4 SCAR=13.9
374 7510 my ($self, $name, @args) = @_;
375 7510 ▶ my $callback = $self->{callbacks}{$name} or return 1;
Branch: 1 branch
BranchTrueFalseTotal
my $callback = $self->{"callbacks"}{$name} or return 1 99 7411 7510
376  
377 99 $self->{callback_depth}++;
378 99 my $ok = eval {
379 99 $callback->($self, @args);
380 99 1;
381 };
382  
383 99 my $error = "$@";
384 99 $self->{callback_depth}--;
385 99 ▶ $self->_notify_finish if $self->{finish_pending};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"finish_pending"} 1 98 99
386 99 ▶ return $ok ? 1 : $error;
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 99 0 99
387 }
388  
389 3 ▶sub _drain {
Subroutine _drain: called CC=1 SCAR=0.0
390 3 my ($self) = @_;
391 3 my $result = $self->_invoke('on_drain');
392 3 return $result;
393 }
394  
395 30 1;
396  
397 __END__
« blib/lib/Unblock/HTTP2/_Connection.pm ↑ Summary blib/lib/Unblock/HTTP2.pm »