HTTP/Response.pm

filter: Statementstmt 96.6% 171 / 177 Branchbran 74.5% 85 / 114 Conditioncond 58.0% 36 / 62 MC/DCmcdc 25.7% 9 / 35 Subroutinesub 95.3% 41 / 43 Podpod 94.1% 16 / 17 totaltotal 79.9% 358 / 448 CC 83 SCAR 16.3
CC
83
Cov
83%
new
11.3
version
10.7
_body_bytes
8.1
CRAP 5.1
« HTTP/_ClientAuth.pm ↑ Summary HTTP/Body/Stream.pm »
1 package Linux::Event::HTTP::Response;
2 38 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 38 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 38 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 38 ▶use Scalar::Util qw(refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 38 ▶use utf8 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 38 ▶use Linux::Event::HTTP::_HTTP1 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 38 our $VERSION = '0.003';
12  
13 38 my $EMPTY_HEADERS = [];
14  
15 642 ▶sub _byte_string ($operation, $value) {
Subroutine _byte_string: called CC=5 SCAR=17.2
16 642 ▶ die "$operation(): value must be a defined scalar byte string"
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or ref $value 0 642 642
Condition33%1/3
not defined $value or ref $value
l!l&&r!l&&!r
00642
MC/DC0%0/2
not defined $value or ref $value
not defined $value ref $value
Truth table33%1/3
not(A) or B
A= not defined $valueB= ref $value
ABresult
1X1
011
000
17 if !defined($value) || ref($value);
18 642 my $bytes = "$value";
19 642 ▶ if (utf8::is_utf8($bytes)) {
Branch: 1 branch
BranchTrueFalseTotal
if (utf8::is_utf8($bytes)) 1 641 642
20 1 ▶ die "$operation(): value contains wide characters; encode it to bytes first"
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::downgrade($bytes, 1) 1 0 1
21 if !utf8::downgrade($bytes, 1);
22 }
23 641 return $bytes;
24 }
25  
26 51 ▶sub new ($class, %args) {
Subroutine new: called CC=11 SCAR=24.2
Pod undocumented
27 51 ▶ my $status = delete($args{status}) // 200;
Condition100%2/2
delete $args{"status"} // 200
l!l
3219
MC/DC100%1/1
delete $args{"status"} // 200
delete $args{"status"}
Truth table100%2/2
A
A= delete $args{"status"}
Aresult
11
00
28 51 my $reason = delete $args{reason};
29 51 ▶ my $version = delete($args{version}) // '1.1';
Condition100%2/2
delete $args{"version"} // "1.1"
l!l
546
MC/DC100%1/1
delete $args{"version"} // "1.1"
delete $args{"version"}
Truth table100%2/2
A
A= delete $args{"version"}
Aresult
11
00
30 51 my $headers = delete $args{headers};
31 51 my $has_body = exists $args{body};
32 51 my $body = delete $args{body};
33  
34 51 ▶ die 'unknown response option: ' . join(', ', sort keys %args)
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 51 51
35 if %args;
36  
37 51 _validate_status($status);
38 48 ▶ $reason = _validate_reason($reason) if defined $reason;
Branch: 1 branch
BranchTrueFalseTotal
if defined $reason 1 47 48
39 48 $version = _validate_version($version);
40  
41 48 my $self = bless {
42 status => 0 + $status,
43 reason => $reason,
44 version => $version,
45 headers => $EMPTY_HEADERS,
46 committed => 0,
47 complete => 0,
48 body_kind => undef,
49 body => undef,
50 }, $class;
51  
52 48 ▶ if (defined $headers) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $headers) 30 18 48
53 30 ▶ die 'headers must be an array reference of [name, value] pairs'
Branch: 1 branch
BranchTrueFalseTotal
if ref $headers ne "ARRAY" 0 30 30
54 if ref($headers) ne 'ARRAY';
55  
56 30 for my $pair (@$headers) {
57 59 ▶ die 'each response header must be a [name, value] pair'
Branch: 1 branch
BranchTrueFalseTotal
if ref $pair ne "ARRAY" or @$pair != 2 0 59 59
Condition33%1/3
ref $pair ne "ARRAY" or @$pair != 2
l!l&&r!l&&!r
0059
MC/DC0%0/2
ref $pair ne "ARRAY" or @$pair != 2
ref $pair ne "ARRAY" @$pair != 2
Truth table33%1/3
A or B
A= ref $pair ne "ARRAY"B= @$pair != 2
ABresult
1X1
011
000
58 if ref($pair) ne 'ARRAY' || @$pair != 2;
59 59 $self->add_header($pair->[0], $pair->[1]);
60 }
61 }
62  
63 47 ▶ $self->body($body) if $has_body;
Branch: 1 branch
BranchTrueFalseTotal
if $has_body 1 46 47
64 47 return $self;
65 }
66  
67 20 ▶sub _new ($class, %args) {
Subroutine _new: called CC=1 SCAR=0.0
68 20 return $class->new(%args);
69 }
70  
71 64 ▶sub is_complete ($self) { !!$self->{complete} }
Subroutine is_complete: called CC=1 SCAR=0.0
Pod documented
72 4 ▶sub is_mutable ($self) { $self->{committed} ? 0 : 1 }
Subroutine is_mutable: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$self->{'committed'} ? : 2 2 4
73 2 ▶sub headers_are_lossless ($self) { 1 }
Subroutine headers_are_lossless: called CC=1 SCAR=0.0
Pod documented
74 12 ▶sub has_buffered_body ($self) { ($self->{body_kind} // '') eq 'scalar' ? 1 : 0 }
Subroutine has_buffered_body: called CC=3 SCAR=11.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
($self->{'body_kind'} // '') eq 'scalar' ? : 4 8 12
Condition100%2/2
$self->{"body_kind"} // ""
l!l
48
MC/DC100%1/1
$self->{"body_kind"} // ""
$self->{"body_kind"}
Truth table100%2/2
A
A= $self->{"body_kind"}
Aresult
11
00
75  
76 118 ▶sub _assert_mutable ($self) {
Subroutine _assert_mutable: called CC=2 SCAR=6.9
77 die 'response metadata cannot change after message commit'
78 118 ▶ if $self->{committed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"committed"} 2 116 118
79 116 return;
80 }
81  
82 451 ▶sub status ($self, @args) {
Subroutine status: called CC=6 SCAR=18.1
Pod documented
83 451 ▶ if (!@args) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@args) 422 29 451
84 422 ▶ return $self->{status} if exists $self->{status};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"status"} 385 37 422
85 37 ▶ return 200 if $self->{_server_flags};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_server_flags"} 37 0 37
86 0 return undef;
87 }
88  
89 29 ▶ die 'status accepts exactly one value' if @args != 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args != 1 0 29 29
90 29 $self->_assert_mutable;
91 27 _validate_status($args[0]);
92 27 $self->{status} = 0 + $args[0];
93 27 ▶ $self->{_server_flags} &= ~1 if exists $self->{_server_flags};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_server_flags"} 26 1 27
94 27 return $self;
95 }
96  
97 9 ▶sub reason ($self, @args) {
Subroutine reason: called CC=5 SCAR=16.1
Pod documented
98 9 ▶ return $self->{reason} if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 4 5 9
99  
100 5 ▶ die 'reason accepts exactly one value' if @args != 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args != 1 0 5 5
101 5 $self->_assert_mutable;
102 5 ▶ $self->{reason} = defined($args[0]) ? _validate_reason($args[0]) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $args[0] ? : 2 3 5
103 4 ▶ $self->{_server_flags} &= ~1 if exists $self->{_server_flags};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_server_flags"} 2 2 4
104 4 return $self;
105 }
106  
107 83 ▶sub version ($self, @args) {
Subroutine version: called CC=10 SCAR=23.7
Pod documented
108 83 ▶ if (!@args) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@args) 80 3 83
109 80 ▶ return $self->{version} if exists $self->{version};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"version"} 77 3 80
110 3 ▶ my $flags = $self->{_server_flags} // 0;
Condition50%1/2
$self->{"_server_flags"} // 0
l!l
30
MC/DC0%0/1
$self->{"_server_flags"} // 0
$self->{"_server_flags"}
Truth table50%1/2
A
A= $self->{"_server_flags"}
Aresult
11
00
111 3 ▶ return ($flags & 4) ? '1.0' : '1.1' if $flags;
Branch: 2 branches
BranchTrueFalseTotal
if $flags 3 0 3
$flags & 4 ? : 1 2 3
112 0 return undef;
113 }
114  
115 3 ▶ die 'version accepts exactly one value' if @args != 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args != 1 0 3 3
116 3 $self->_assert_mutable;
117 3 ▶ if (!defined $args[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args[0]) 1 2 3
118 1 $self->{version} = undef;
119 1 ▶ $self->{_server_flags} &= ~1 if exists $self->{_server_flags};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_server_flags"} 0 1 1
120 1 return $self;
121 }
122 2 $self->{version} = _validate_version($args[0]);
123 2 ▶ $self->{_server_flags} &= ~1 if exists $self->{_server_flags};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_server_flags"} 0 2 2
124 2 return $self;
125 }
126  
127 152 ▶sub header ($self, $name, @args) {
Subroutine header: called CC=6 SCAR=18.2
Pod documented
128 152 ▶ if (!@args) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@args) 24 128 152
129 24 $name = _validate_name($name);
130 24 my $wanted = lc $name;
131 24 ▶ my $headers = $self->{headers} // $EMPTY_HEADERS;
Condition33%1/3
$self->{"headers"} // $EMPTY_HEADERS
l!l&&r!l&&!r
2400
MC/DC0%0/2
$self->{"headers"} // $EMPTY_HEADERS
$self->{"headers"} $EMPTY_HEADERS
Truth table33%1/3
A // B
A= $self->{"headers"}B= $EMPTY_HEADERS
ABresult
1X1
011
000
132 24 for my $pair (@$headers) {
133 44 ▶ return $pair->[1] if lc($pair->[0]) eq $wanted;
Branch: 1 branch
BranchTrueFalseTotal
if lc $pair->[0] eq $wanted 22 22 44
134 }
135 2 return undef;
136 }
137  
138 128 ▶ die 'header setter accepts exactly one value' if @args != 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args != 1 0 128 128
139 128 Linux::Event::HTTP::Response::_set_header_native(
140 $self, $name, $args[0],
141 );
142 122 return $self;
143 }
144  
145 67 ▶sub add_header ($self, $name, $value) {
Subroutine add_header: called CC=4 SCAR=13.9
Pod documented
146 67 $self->_assert_mutable;
147 67 $name = _validate_name($name);
148 67 $value = _validate_value($value);
149 66 my $headers = $self->{headers};
150 66 ▶ if (!defined($headers) || refaddr($headers) == refaddr($EMPTY_HEADERS)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $headers or builtin::refaddr($headers) == builtin::refaddr($EMPTY_HEADERS)) 32 34 66
Condition100%3/3
not defined $headers or builtin::refaddr($headers) == builtin::refaddr($EMPTY_HEADERS)
l!l&&r!l&&!r
23034
MC/DC100%2/2
not defined $headers or builtin::refaddr($headers) == builtin::refaddr($EMPTY_HEADERS)
not defined $headers builtin::refaddr($headers) == builtin::refaddr($EMPTY_HEADERS)
Truth table100%3/3
not(A) or B
A= not defined $headersB= builtin::refaddr($headers) == builtin::refaddr($EMPTY_HEADERS)
ABresult
1X1
011
000
151 32 $headers = $self->{headers} = [];
152 }
153 66 push @$headers, [ $name, $value ];
154 66 ▶ $self->{_server_flags} &= ~3 if exists $self->{_server_flags};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_server_flags"} 5 61 66
155 66 return $self;
156 }
157  
158 1 ▶sub remove_header ($self, $name) {
Subroutine remove_header: called CC=3 SCAR=11.3
Pod documented
159 1 $self->_assert_mutable;
160 1 $name = _validate_name($name);
161 1 my $wanted = lc $name;
162 1 ▶ my $headers = $self->{headers} // $EMPTY_HEADERS;
Condition33%1/3
$self->{"headers"} // $EMPTY_HEADERS
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->{"headers"} // $EMPTY_HEADERS
$self->{"headers"} $EMPTY_HEADERS
Truth table33%1/3
A // B
A= $self->{"headers"}B= $EMPTY_HEADERS
ABresult
1X1
011
000
163 1 my @kept = grep { lc($_->[0]) ne $wanted } @$headers;
164 1 $self->{headers} = \@kept;
165 1 ▶ $self->{_server_flags} &= ~3 if exists $self->{_server_flags};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_server_flags"} 0 1 1
166 1 return $self;
167 }
168  
169 430 ▶sub _header_values_list ($self, $name) {
Subroutine _header_values_list: called CC=2 SCAR=7.0
170 430 $name = _validate_name($name);
171 430 my $wanted = lc $name;
172 430 ▶ my $headers = $self->{headers} // $EMPTY_HEADERS;
Condition66%2/3
$self->{"headers"} // $EMPTY_HEADERS
l!l&&r!l&&!r
409210
MC/DC0%0/2
$self->{"headers"} // $EMPTY_HEADERS
$self->{"headers"} $EMPTY_HEADERS
Truth table66%2/3
A // B
A= $self->{"headers"}B= $EMPTY_HEADERS
ABresult
1X1
011
000
173 197 return map { $_->[1] }
174 430 grep { lc($_->[0]) eq $wanted }
175 @$headers;
176 }
177  
178 30 ▶sub header_values ($self, $name) {
Subroutine header_values: called CC=1 SCAR=0.0
Pod documented
179 30 return [ $self->_header_values_list($name) ];
180 }
181  
182 8 ▶sub header_count ($self) {
Subroutine header_count: called CC=2 SCAR=7.1
Pod documented
183 8 ▶ my $headers = $self->{headers} // $EMPTY_HEADERS;
Condition66%2/3
$self->{"headers"} // $EMPTY_HEADERS
l!l&&r!l&&!r
710
MC/DC0%0/2
$self->{"headers"} // $EMPTY_HEADERS
$self->{"headers"} $EMPTY_HEADERS
Truth table66%2/3
A // B
A= $self->{"headers"}B= $EMPTY_HEADERS
ABresult
1X1
011
000
184 8 return scalar @$headers;
185 }
186  
187 19 ▶sub _validate_header_index ($index) {
Subroutine _validate_header_index: called CC=4 SCAR=14.9
188 19 ▶ die 'header index must be a non-negative integer'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $index or ref $index or not "$index" =~ /\A[0-9]+\z/u 2 17 19
Condition50%3/6
not defined $index or ref $index or not "$index" =~ /\A[0-9]+\z/u
l!l&&r!l&&!r
0217
not defined $index or ref $index
l!l&&r!l&&!r
0019
MC/DC33%1/3
not defined $index or ref $index or not "$index" =~ /\A[0-9]+\z/u
not defined $index ref $index not "$index" =~ /\A[0-9]+\z/u
Truth table50%2/4
not(A) or B or not(C)
A= not defined $indexB= ref $indexC= not "$index" =~ /\A[0-9]+\z/u
ABCresult
1XX1
01X1
0011
0000
189 if !defined($index) || ref($index) || "$index" !~ /\A[0-9]+\z/;
190 17 return 0 + $index;
191 }
192  
193 11 ▶sub header_name ($self, $index) {
Subroutine header_name: called CC=3 SCAR=11.3
Pod documented
194 11 $index = _validate_header_index($index);
195 10 ▶ my $headers = $self->{headers} // $EMPTY_HEADERS;
Condition33%1/3
$self->{"headers"} // $EMPTY_HEADERS
l!l&&r!l&&!r
1000
MC/DC0%0/2
$self->{"headers"} // $EMPTY_HEADERS
$self->{"headers"} $EMPTY_HEADERS
Truth table33%1/3
A // B
A= $self->{"headers"}B= $EMPTY_HEADERS
ABresult
1X1
011
000
196 10 ▶ return undef if $index >= @$headers;
Branch: 1 branch
BranchTrueFalseTotal
if $index >= @$headers 2 8 10
197 8 return $headers->[$index][0];
198 }
199  
200 8 ▶sub header_value ($self, $index) {
Subroutine header_value: called CC=3 SCAR=11.3
Pod documented
201 8 $index = _validate_header_index($index);
202 7 ▶ my $headers = $self->{headers} // $EMPTY_HEADERS;
Condition33%1/3
$self->{"headers"} // $EMPTY_HEADERS
l!l&&r!l&&!r
700
MC/DC0%0/2
$self->{"headers"} // $EMPTY_HEADERS
$self->{"headers"} $EMPTY_HEADERS
Truth table33%1/3
A // B
A= $self->{"headers"}B= $EMPTY_HEADERS
ABresult
1X1
011
000
203 7 ▶ return undef if $index >= @$headers;
Branch: 1 branch
BranchTrueFalseTotal
if $index >= @$headers 2 5 7
204 5 return $headers->[$index][1];
205 }
206  
207 3 ▶sub content_length ($self) {
Subroutine content_length: called CC=4 SCAR=14.6
Pod documented
208 3 my @values = $self->_header_values_list('Content-Length');
209 3 ▶ return undef if !@values;
Branch: 1 branch
BranchTrueFalseTotal
unless @values 0 3 3
210 3 ▶ die 'response must not contain multiple Content-Length fields' if @values != 1;
Branch: 1 branch
BranchTrueFalseTotal
if @values != 1 0 3 3
211 3 ▶ die 'response Content-Length must be a decimal number'
Branch: 1 branch
BranchTrueFalseTotal
unless $values[0] =~ /\A[0-9]+\z/u 0 3 3
212 if $values[0] !~ /\A[0-9]+\z/;
213 3 return 0 + $values[0];
214 }
215  
216 16 ▶sub _body_bytes ($operation, $body) {
Subroutine _body_bytes: called CC=5 SCAR=20.9
217 16 ▶ die "$operation(): body must be a defined scalar byte string"
Branch: 1 branch
BranchTrueFalseTotal
if not defined $body or ref $body 0 16 16
Condition33%1/3
not defined $body or ref $body
l!l&&r!l&&!r
0016
MC/DC0%0/2
not defined $body or ref $body
not defined $body ref $body
Truth table33%1/3
not(A) or B
A= not defined $bodyB= ref $body
ABresult
1X1
011
000
218 if !defined($body) || ref($body);
219  
220 16 my $bytes = "$body";
221 16 ▶ if (utf8::is_utf8($bytes)) {
Branch: 1 branch
BranchTrueFalseTotal
if (utf8::is_utf8($bytes)) 0 16 16
222 0 ▶ die "$operation(): body contains wide characters; encode it to bytes first"
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::downgrade($bytes, 1) 0 0 0
223 if !utf8::downgrade($bytes, 1);
224 }
225 16 return $bytes;
226 }
227  
228 128 ▶sub body ($self, @args) {
Subroutine body: called CC=3 SCAR=11.0
Pod documented
229 128 ▶ return $self->{body} if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 25 103 128
230  
231 103 ▶ die 'body accepts exactly one value' if @args != 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args != 1 0 103 103
232 103 Linux::Event::HTTP::Response::_set_body_native(
233 $self, $args[0],
234 );
235 100 return $self;
236 }
237  
238 16 ▶sub _set_received_body ($self, $body) {
Subroutine _set_received_body: called CC=3 SCAR=11.3
239 die 'received response body can only be attached after message commit'
240 16 ▶ if !$self->{committed};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"committed"} 0 16 16
241 die 'received response body has already been attached'
242 16 ▶ if defined $self->{body_kind};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"body_kind"} 0 16 16
243  
244 16 $self->{body_kind} = 'scalar';
245 16 $self->{body} = _body_bytes('received body', $body);
246 16 return $self;
247 }
248  
249 13 ▶sub _begin_stream_body ($self) {
Subroutine _begin_stream_body: called CC=6 SCAR=18.0
250 13 $self->_assert_mutable;
251 die 'response_body(): Response already has a complete scalar body'
252 13 ▶ if ($self->{body_kind} // '') eq 'scalar';
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"body_kind"} // "") eq "scalar" 1 12 13
Condition100%2/2
$self->{"body_kind"} // ""
l!l
112
MC/DC100%1/1
$self->{"body_kind"} // ""
$self->{"body_kind"}
Truth table100%2/2
A
A= $self->{"body_kind"}
Aresult
11
00
253 die 'response_body(): Response already has an incremental body producer'
254 12 ▶ if ($self->{body_kind} // '') eq 'stream';
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"body_kind"} // "") eq "stream" 0 12 12
Condition50%1/2
$self->{"body_kind"} // ""
l!l
012
MC/DC0%0/1
$self->{"body_kind"} // ""
$self->{"body_kind"}
Truth table50%1/2
A
A= $self->{"body_kind"}
Aresult
11
00
255  
256 12 $self->{body_kind} = 'stream';
257 12 $self->{complete} = 0;
258 12 ▶ $self->{_server_flags} &= ~3 if exists $self->{_server_flags};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_server_flags"} 9 3 12
259 12 return $self;
260 }
261  
262 8 ▶sub _has_scalar_body ($self) {
Subroutine _has_scalar_body: called CC=1 SCAR=0.0
263 8 return $self->has_buffered_body;
264 }
265  
266 10 ▶sub _has_incremental_body ($self) {
Subroutine _has_incremental_body: called CC=2 SCAR=7.6
267 10 ▶ return ($self->{body_kind} // '') eq 'stream';
Condition50%1/2
$self->{"body_kind"} // ""
l!l
010
MC/DC0%0/1
$self->{"body_kind"} // ""
$self->{"body_kind"}
Truth table50%1/2
A
A= $self->{"body_kind"}
Aresult
11
00
268 }
269  
270 0 ▶sub _scalar_body ($self) {
Subroutine _scalar_body: not called CC=1 SCAR=6.9
271 0 return $self->{body};
272 }
273  
274 34 ▶sub _commit ($self) {
Subroutine _commit: called CC=1 SCAR=0.0
275 34 $self->{committed} = 1;
276 34 return $self;
277 }
278  
279 11 ▶sub _is_committed ($self) {
Subroutine _is_committed: called CC=1 SCAR=0.0
280 11 return !!$self->{committed};
281 }
282  
283 81 ▶sub _mark_complete ($self) {
Subroutine _mark_complete: called CC=1 SCAR=0.0
284 81 $self->{complete} = 1;
285 81 return;
286 }
287  
288 0 ▶sub _mark_incomplete ($self) {
Subroutine _mark_incomplete: not called CC=1 SCAR=6.9
289 0 $self->{complete} = 0;
290 0 return;
291 }
292  
293 78 ▶sub _validate_status ($status) {
Subroutine _validate_status: called CC=6 SCAR=19.0
294 78 ▶ die 'response status must be an integer between 100 and 599'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $status or ref $status or not "$status" =~ /\A[0-9]{3}\z/u or $status < 100 or $status > 599 3 75 78
Condition66%8/12
not defined $status or ref $status or not "$status" =~ /\A[0-9]{3}\z/u or $status < 100 or $status > 599
l!l&&r!l&&!r
1275
not defined $status or ref $status or not "$status" =~ /\A[0-9]{3}\z/u or $status < 100
l!l&&r!l&&!r
1077
not defined $status or ref $status or not "$status" =~ /\A[0-9]{3}\z/u
l!l&&r!l&&!r
0177
not defined $status or ref $status
l!l&&r!l&&!r
0078
MC/DC40%2/5
not defined $status or ref $status or not "$status" =~ /\A[0-9]{3}\z/u or $status < 100 or $status > 599
not defined $status ref $status not "$status" =~ /\A[0-9]{3}\z/u $status < 100 $status > 599
Truth table50%3/6
not(A) or B or not(C) or D or E
A= not defined $statusB= ref $statusC= not "$status" =~ /\A[0-9]{3}\z/uD= $status < 100E= $status > 599
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
295 if !defined($status) || ref($status) || "$status" !~ /\A[0-9]{3}\z/
296 || $status < 100 || $status > 599;
297 }
298  
299 3 ▶sub _validate_reason ($reason) {
Subroutine _validate_reason: called CC=2 SCAR=6.9
300 3 my $bytes = _byte_string('reason', $reason);
301 3 ▶ die 'response reason phrase contains invalid control characters'
Branch: 1 branch
BranchTrueFalseTotal
if $bytes =~ /[\x00-\x08\x0a-\x1f\x7f]/u 1 2 3
302 if $bytes =~ /[\x00-\x08\x0a-\x1f\x7f]/;
303 2 return $bytes;
304 }
305  
306 50 ▶sub _validate_version ($version) {
Subroutine _validate_version: called CC=2 SCAR=7.1
307 50 my $bytes = _byte_string('version', $version);
308 50 ▶ die 'invalid HTTP version' if $bytes !~ /\A[0-9]+(?:\.[0-9]+)?\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $bytes =~ /\A[0-9]+(?:\.[0-9]+)?\z/u 0 50 50
309 50 return $bytes;
310 }
311  
312 522 ▶sub _validate_name ($name) {
Subroutine _validate_name: called CC=3 SCAR=11.4
313 522 my $bytes = _byte_string('response header field name', $name);
314 522 ▶ die 'response header field name is required' if $bytes eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $bytes eq "" 0 522 522
315 522 ▶ die 'invalid response header field name'
Branch: 1 branch
BranchTrueFalseTotal
unless $bytes =~ /\A[!#\$%&'*+\-.^_`|~0-9A-Za-z]+\z/u 0 522 522
316 if $bytes !~ /\A[!#\$%&'*+\-.^_`|~0-9A-Za-z]+\z/;
317 522 return $bytes;
318 }
319  
320 67 ▶sub _validate_value ($value) {
Subroutine _validate_value: called CC=2 SCAR=7.1
321 67 my $bytes = _byte_string('response header field value', $value);
322 66 ▶ die 'response header field value contains invalid control characters'
Branch: 1 branch
BranchTrueFalseTotal
if $bytes =~ /[\x00-\x08\x0a-\x1f\x7f]/u 0 66 66
323 if $bytes =~ /[\x00-\x08\x0a-\x1f\x7f]/;
324 66 return $bytes;
325 }
326  
327 38 1;
328  
329 __END__
« HTTP/_ClientAuth.pm ↑ Summary HTTP/Body/Stream.pm »