HTTP2/Response.pm

filter: Statementstmt 78.1% 25 / 32 Branchbran 66.6% 8 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 75.0% 6 / 8 Podpod 80.0% 4 / 5 totaltotal 69.3% 43 / 62 CC 8 SCAR 14.3
CC
8
Cov
70%
headers
6.8
success
6.0
status
2.1
CRAP 4.2
« HTTP2/Client/Connection.pm ↑ Summary HTTP2/Client.pm »
1 package Net::HTTP2::Response;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =encoding utf-8
7  
8 =head1 NAME
9  
10 Net::HTTP2::Response - HTTP/2 Response
11  
12 =head1 DESCRIPTION
13  
14 This class represents an HTTP/2 response.
15  
16 =cut
17  
18 #----------------------------------------------------------------------
19  
20 1 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 _HEADERS_AR => 0,
22 _DATA => 1,
23 _STATUS => 2,
24 _HEADERS_HR => 3,
25 1 };
26  
27 #----------------------------------------------------------------------
28  
29 =head1 METHODS
30  
31 =cut
32  
33 # Not called publicly.
34 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
35 1 my ($class, $headers_ar, $data) = @_;
36  
37 1 return bless [$headers_ar, $data], $class;
38 }
39  
40 =head2 $str = I<OBJ>->content()
41  
42 Returns the response payload, or undef if the payload was
43 delivered to an C<on_data> handler. (See L<Net::HTTP2::Client>’s
44 C<request()> method.)
45  
46 =cut
47  
48 0 ▶sub content { $_[0][ _DATA ] }
Subroutine content: not called CC=1 SCAR=6.9
Pod documented
49  
50 =head2 $num = I<OBJ>->status()
51  
52 Returns the (numeric) HTTP statis.
53  
54 (NB: HTTP/2 doesn’t have response status strings as HTTP/1 has.)
55  
56 =cut
57  
58 1 ▶sub status {
Subroutine status: called CC=2 SCAR=7.2
Pod documented
59 1 ▶ $_[0]->headers() if !defined $_[0][ _STATUS ];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0][2] 1 0 1
60 1 return $_[0][ _STATUS ];
61 }
62  
63 =head2 $yn = I<OBJ>->success()
64  
65 Returns a boolean that indicates whether the response indicates
66 success.
67  
68 =cut
69  
70 0 ▶sub success {
Subroutine success: not called CC=2 SCAR=17.9
Pod documented
71 0 my $status = $_[0]->status();
72  
73 0 ▶ return ($status >= 200) && ($status <= 299);
Condition0%0/3
$status >= 200 && $status <= 299
!ll&&!rl&&r
000
MC/DC0%0/2
$status >= 200 && $status <= 299
$status >= 200 $status <= 299
Truth table0%0/3
A && B
A= $status >= 200B= $status <= 299
ABresult
0X0
100
111
74 }
75  
76 =head2 $hr = I<OBJ>->headers()
77  
78 Returns a hash reference similar to that in
79 L<HTTP::Tiny::UA::Response>’s method of the same name.
80  
81 =cut
82  
83 2 ▶sub headers {
Subroutine headers: called CC=6 SCAR=19.2
Pod documented
84 2 ▶ if (!$_[0][ _HEADERS_HR ]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_[0][3]) 1 1 2
85 1 my $headers_ar = $_[0][ _HEADERS_AR ];
86  
87 1 my %headers;
88 1 $_[0][ _HEADERS_HR ] = \%headers;
89  
90 1 ▶ for (my $h=0; $h < @$headers_ar; $h+=2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h < @$headers_ar) 12 1 13
91 12 my ($name, $value) = @{$headers_ar}[ $h, $h+1 ];
92  
93 12 ▶ if ($name eq ':status') {
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq ':status') { } 1 11 12
elsif (exists $headers{$name}) { } 0 11 11
94 1 $_[0][ _STATUS ] = $value;
95 }
96 elsif (exists $headers{$name}) {
97 0 ▶ if ('ARRAY' eq ref $headers{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ('ARRAY' eq ref $headers{$name}) { } 0 0 0
98 0 push @{$headers{$name}}, $value;
99 }
100 else {
101 0 $headers{$name} = [ $headers{$name}, $value ];
102 }
103 }
104 else {
105 11 $headers{$name} = $value;
106 }
107 }
108 }
109  
110 2 return $_[0][ _HEADERS_HR ];
111 }
112  
113 1 1;
114  
« HTTP2/Client/Connection.pm ↑ Summary HTTP2/Client.pm »