Promise.pm

filter: Statementstmt 8.0% 82 / 1018 Branchbran 0.0% 0 / 672 Conditioncond 0.0% 0 / 627 MC/DCmcdc 0.0% 0 / 325 Subroutinesub 21.1% 23 / 109 Podpod 96.8% 61 / 63 totaltotal 5.9% 166 / 2814 CC 591 SCAR 89.5
CC
591
Cov
4%
send
25122.0
_make_request_data
9506.0
_read_body
4970.0
CRAP 7694.2
↑ Summary Promise/Request.pm »
1 ##----------------------------------------------------------------------------
2 ## Asynchronous HTTP Request and Promise - ~/lib/HTTP/Promise.pm
3 ## Version v0.7.5
4 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/05/06
7 ## Modified 2026/10/19
8 ## All rights reserved.
9 ##
10 ## This program is free software; you can redistribute it and/or modify it
11 ## under the same terms as Perl itself.
12 ##----------------------------------------------------------------------------
13 package HTTP::Promise;
14 BEGIN
15 2 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶ use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶ use vars qw( $VERSION $AUTOLOAD $CONTENT_SIZE_THRESHOLD $CRLF
Subroutine BEGIN: called CC=1 SCAR=0.0
21 $DEFAULT_PROTOCOL $EXCEPTION_CLASS $EXTENSION_VARY
22 $IS_WIN32 $HTTP_TOKEN $HTTP_QUOTED_STRING $BUFFER_SIZE
23 $MAX_HEADERS_SIZE $MAX_BODY_IN_MEMORY_SIZE $EXPECT_THRESHOLD $DEFAULT_MIME_TYPE
24 2 $SERIALISER @EXPORT_OK );
25 2 ▶ use Cookie;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 ▶ use Cookie::Jar;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶ use Errno qw( EAGAIN ECONNRESET EINPROGRESS EINTR EWOULDBLOCK ECONNABORTED EISCONN );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 2 ▶ use HTTP::Promise::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 ▶ use HTTP::Promise::IO;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 2 ▶ use HTTP::Promise::Pool;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 2 ▶ use HTTP::Promise::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 ▶ use HTTP::Promise::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 2 ▶ use HTTP::Promise::Status qw( :all );
Subroutine BEGIN: called CC=1 SCAR=0.0
34 # use Nice::Try;
35 2 ▶ use Promise::Me;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 2 ▶ use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
37 2 ▶ use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 2 ▶ use URI::Escape::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
39 # < 0 so we recognise those as system errors
40 2 ▶ use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
41 2 ERROR_EINTR => ( abs( Errno::EINTR ) * -1 ),
42 TYPE_URL_ENCODED => 'application/x-www-form-urlencoded',
43 2 };
44 2 our @EXPORT = qw( async await );
45 2 our @EXPORT_OK = qw( fetch );
46 # "\r\n" is not portable
47 2 our $CRLF = "\015\012";
48 2 our $DEFAULT_PROTOCOL = 'HTTP/1.1';
49 2 our $EXCEPTION_CLASS = 'HTTP::Promise::Exception';
50 2 our $HTTP_TOKEN = qr/[^\x00-\x31\x7F]+/;
51 2 our $HTTP_QUOTED_STRING = qr/"([^"]+|\\.)*"/;
52 # 10K
53 2 our $BUFFER_SIZE = 10240000;
54 2 our $MAX_HEADERS_SIZE = 8192;
55 # 256Kb
56 2 our $MAX_BODY_IN_MEMORY_SIZE = 102400;
57 # 1Mb
58 2 our $EXPECT_THRESHOLD = 1024000000;
59 2 our $EXTENSION_VARY = 1;
60 2 our $DEFAULT_MIME_TYPE = 'application/octet-stream';
61 2 our $SERIALISER = $Promise::Me::SERIALISER;
62 2 our $VERSION = 'v0.7.5';
63 };
64  
65 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
67  
68 sub init
69 0 ▶{
Subroutine init: not called CC=9 SCAR=45.0
Pod documented
70 0 my $self = shift( @_ );
71 0 $self->{accept_language} = [];
72 0 $self->{accept_encoding} = 'auto';
73 0 $self->{agent} = qq{HTTP-Promise/$VERSION (perl; +https://metacpan.org/pod/HTTP::Promise)};
74 0 $self->{auto_switch_https} = 1;
75 0 $self->{buffer_size} = $BUFFER_SIZE;
76 0 $self->{cookie_jar} = Cookie::Jar->new;
77 0 $self->{default_headers} = undef;
78 0 ▶ $self->{default_protocol} = ( $DEFAULT_PROTOCOL || 'HTTP/1.1' );
Condition0%0/2
$HTTP::Promise::DEFAULT_PROTOCOL || 'HTTP/1.1'
l!l
00
MC/DC0%0/1
$HTTP::Promise::DEFAULT_PROTOCOL || 'HTTP/1.1'
$HTTP::Promise::DEFAULT_PROTOCOL
Truth table0%0/2
A
A= $HTTP::Promise::DEFAULT_PROTOCOL
Aresult
11
00
79 # DNT -> Do not track header field
80 0 $self->{dnt} = undef;
81 0 $self->{expect_threshold} = $EXPECT_THRESHOLD;
82 0 $self->{ext_vary} = $EXTENSION_VARY;
83 0 $self->{from} = undef;
84 0 $self->{inactivity_timeout} = 600;
85 0 $self->{local_host} = undef;
86 0 $self->{local_port} = undef;
87 0 $self->{max_body_in_memory_size} = $MAX_BODY_IN_MEMORY_SIZE;
88 0 $self->{max_headers_size} = $MAX_HEADERS_SIZE;
89 0 $self->{max_redirect} = 7;
90 0 $self->{max_size} = undef;
91 0 $self->{medium} = $Promise::Me::SHARE_MEDIUM;
92 0 $self->{no_proxy} = [];
93 0 ▶ $self->{proxy} = $ENV{http_proxy} || $ENV{HTTP_PROXY} || undef;
Condition0%0/5
$ENV{'http_proxy'} || $ENV{'HTTP_PROXY'} || undef
l!l
00
$ENV{"http_proxy"} or $ENV{"HTTP_PROXY"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'http_proxy'} || $ENV{'HTTP_PROXY'} || undef
$ENV{"http_proxy"} $ENV{"HTTP_PROXY"}
Truth table0%0/3
A or B
A= $ENV{"http_proxy"}B= $ENV{"HTTP_PROXY"}
ABresult
1X1
011
000
94 0 $self->{proxy_authorization} = undef;
95 0 $self->{requests_redirectable} = [qw( GET HEAD )];
96 0 $self->{send_te} = 1;
97 0 $self->{serialiser} = $SERIALISER;
98 0 $self->{shared_mem_size} = $Promise::Me::RESULT_MEMORY_SIZE;
99 0 $self->{ssl_opts} = undef;
100 0 ▶ $self->{stop_if} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
101 0 $self->{threshold} = $CONTENT_SIZE_THRESHOLD;
102 # 3 minutes
103 0 $self->{timeout} = 180;
104 0 $self->{use_content_file} = 0;
105 0 $self->{use_promise} = 1;
106 0 $self->{_init_strict_use_sub} = 1;
107 0 $self->{_exception_class} = $EXCEPTION_CLASS;
108 0 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 0 0
109 0 my $headers = $self->default_headers;
110 0 ▶ if( $headers )
Branch: 1 branch
BranchTrueFalseTotal
if ($headers) { } 0 0 0
111 {
112 0 ▶ unless( $self->connection_header )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->connection_header) 0 0 0
113 {
114 0 my $connection_header = 'keep-alive';
115 0 ▶ if( $headers->exists( 'connection' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($headers->exists("connection")) 0 0 0
116 {
117 0 $connection_header = $headers->get( 'connection' );
118 }
119 0 $self->{connection_header} = $connection_header;
120 }
121 }
122 else
123 {
124 0 ▶ $self->default_headers( HTTP::Promise::Headers->new ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->default_headers("HTTP::Promise::Headers"->new) or return $self->pass_error("HTTP::Promise::Headers"->error) 0 0 0
125 return( $self->pass_error( HTTP::Promise::Headers->error ) );
126 }
127 0 $self->{_pool} = HTTP::Promise::Pool->new;
128 0 return( $self );
129 }
130  
131 0 ▶sub accept_language { return( shift->_set_get_array_as_object( 'accept_language', @_ ) ); }
Subroutine accept_language: not called CC=1 SCAR=6.9
Pod documented
132  
133 0 ▶sub accept_encoding { return( shift->_set_get_scalar_as_object( 'accept_encoding', @_ ) ); }
Subroutine accept_encoding: not called CC=1 SCAR=6.9
Pod documented
134  
135 # NOTE: request parameter
136 0 ▶sub agent { return( shift->_set_get_scalar_as_object( 'agent', @_ ) ); }
Subroutine agent: not called CC=1 SCAR=6.9
Pod documented
137  
138 0 ▶sub auto_switch_https { return( shift->_set_get_boolean( 'auto_switch_https', @_ ) ); }
Subroutine auto_switch_https: not called CC=1 SCAR=6.9
Pod documented
139  
140 0 ▶sub buffer_size { return( shift->_set_get_number( 'buffer_size', @_ ) ); }
Subroutine buffer_size: not called CC=1 SCAR=6.9
Pod documented
141  
142 sub clone
143 0 ▶{
Subroutine clone: not called CC=2 SCAR=17.9
Pod documented
144 0 my $self = shift( @_ );
145 0 my $new = $self->SUPER::clone;
146 0 ▶ if( $self->{default_headers} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"default_headers"}) 0 0 0
147 {
148 0 $new->{default_headers} = $self->{default_headers}->clone;
149 }
150 0 $new->{_pool} = HTTP::Promise::Pool->new;
151 0 return( $new );
152 }
153  
154 0 ▶sub connection_header { return( shift->_set_get_scalar_as_object( 'connection_header', @_ ) ); }
Subroutine connection_header: not called CC=1 SCAR=6.9
Pod documented
155  
156 # NOTE: request parameter
157 0 ▶sub cookie_jar { return( shift->_set_get_scalar( 'cookie_jar', @_ ) ); }
Subroutine cookie_jar: not called CC=1 SCAR=6.9
Pod documented
158  
159 0 ▶sub decodable { return( HTTP::Promise::Stream->decodable( @_ ) ); }
Subroutine decodable: not called CC=1 SCAR=6.9
Pod documented
160  
161 # NOTE: request parameter
162 0 ▶sub default_header { return( shift->default_headers->header( @_ ) ); }
Subroutine default_header: not called CC=1 SCAR=6.9
Pod documented
163  
164 # NOTE: request parameter
165 0 ▶sub default_headers { return( shift->_set_get_object_without_init( 'default_headers', [qw( HTTP::Promise::Headers HTTP::Headers )], @_ ) ); }
Subroutine default_headers: not called CC=1 SCAR=6.9
Pod documented
166  
167 0 ▶sub default_protocol { return( shift->_set_get_scalar_as_object( 'default_protocol', @_ ) ); }
Subroutine default_protocol: not called CC=1 SCAR=6.9
Pod documented
168  
169 # As per rfc7231, a body is allowed for DELETE, but usually discarded by most of the servers.
170 sub delete
171 0 ▶{
Subroutine delete: not called CC=9 SCAR=45.0
Pod documented
172 0 my $self = shift( @_ );
173 0 ▶ if( $self->use_promise )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_promise) { } 0 0 0
174 {
175 my $prom = Promise::Me->new(sub
176 0 ▶ {
Subroutine __ANON__: not called CC=4 SCAR=30.0
177 0 my( $resolve, $reject ) = @$_;
178 0 ▶ my $req = $self->_make_request_data( 'DELETE' => @_ ) ||
Condition0%0/2
$self->_make_request_data('DELETE', @_) || (return &$reject($self->error))
l!l
00
MC/DC0%0/1
$self->_make_request_data('DELETE', @_) || (return &$reject($self->error))
$self->_make_request_data('DELETE', @_)
Truth table0%0/2
A
A= $self->_make_request_data('DELETE', @_)
Aresult
11
00
179 return( $reject->( $self->error ) );
180 0 ▶ unless( $req->headers->host )
Branch: 1 branch
BranchTrueFalseTotal
unless ($req->headers->host) 0 0 0
181 {
182 0 $req->headers->host( $req->host );
183 }
184 0 ▶ my $resp = $self->send( $req ) || return( $reject->( $self->error ) );
Condition0%0/2
$self->send($req) || (return &$reject($self->error))
l!l
00
MC/DC0%0/1
$self->send($req) || (return &$reject($self->error))
$self->send($req)
Truth table0%0/2
A
A= $self->send($req)
Aresult
11
00
185 0 return( $resolve->( $resp ) );
186 },
187 {
188 args => [@_],
189 ( defined( $self->{serialiser} ) ? ( serialiser => $self->{serialiser} ) : () ),
190 ( defined( $self->{medium} ) ? ( medium => $self->{medium} ) : () ),
191 0 ▶ ( defined( $self->{shared_mem_size} ) ? ( result_shared_mem_size => $self->{shared_mem_size} ) : () ),
Branch: 3 branches
BranchTrueFalseTotal
defined $self->{'serialiser'} ? : 0 0 0
defined $self->{'medium'} ? : 0 0 0
defined $self->{'shared_mem_size'} ? : 0 0 0
Condition0%0/2
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_data('DELETE', @_) || (return &$reject($self->error)); unless ($req->headers->host) { $req->headers->host($req->host); } ; my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()}) || (return $self->pass_error('Promise::Me'->error))
l!l
00
MC/DC0%0/1
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_data('DELETE', @_) || (return &$reject($self->error)); unless ($req->headers->host) { $req->headers->host($req->host); } ; my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()}) || (return $self->pass_error('Promise::Me'->error))
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_data('DELETE', @_) || (return &$reject($self->error)); unless ($req->headers->host) { $req->headers->host($req->host); } ; my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()})
Truth table0%0/2
A
A= 'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_data('DELETE', @_) || (return &$reject($self->error)); unless ($req->headers->host) { $req->headers->host($req->host); } ; my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()})
Aresult
11
00
192 }) || return( $self->pass_error( Promise::Me->error ) );
193 0 return( $prom );
194 }
195 else
196 {
197 0 ▶ my $req = $self->_make_request_data( 'DELETE' => @_ ) ||
Condition0%0/2
$self->_make_request_data('DELETE', @_) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_make_request_data('DELETE', @_) || (return $self->pass_error)
$self->_make_request_data('DELETE', @_)
Truth table0%0/2
A
A= $self->_make_request_data('DELETE', @_)
Aresult
11
00
198 return( $self->pass_error );
199 0 ▶ unless( $req->headers->host )
Branch: 1 branch
BranchTrueFalseTotal
unless ($req->headers->host) 0 0 0
200 {
201 0 $req->headers->host( $req->host );
202 }
203 0 ▶ my $resp = $self->send( $req ) ||
Condition0%0/2
$self->send($req) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->send($req) || (return $self->pass_error)
$self->send($req)
Truth table0%0/2
A
A= $self->send($req)
Aresult
11
00
204 return( $self->pass_error );
205 0 return( $resp );
206 }
207 }
208  
209  
210 0 ▶sub dnt { return( shift->_set_get_boolean( 'dnt', @_ ) ); }
Subroutine dnt: not called CC=1 SCAR=6.9
Pod documented
211  
212 0 ▶sub expect_threshold { return( shift->_set_get_number( 'expect_threshold', @_ ) ); }
Subroutine expect_threshold: not called CC=1 SCAR=6.9
Pod documented
213  
214 0 ▶sub ext_vary { return( shift->_set_get_boolean( 'ext_vary', @_ ) ); }
Subroutine ext_vary: not called CC=1 SCAR=6.9
Pod documented
215  
216 sub fetch
217 0 ▶{
Subroutine fetch: not called CC=7 SCAR=40.3
Pod documented
218 0 my $self;
219 0 ▶ if( Scalar::Util::blessed( $_[0] ) && $_[0]->isa( __PACKAGE__ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)) { } 0 0 0
Condition0%0/3
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
builtin::blessed($_[0]) $_[0]->isa(__PACKAGE__)
Truth table0%0/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa(__PACKAGE__)
ABresult
0X0
100
111
220 {
221 0 $self = shift( @_ );
222 }
223 else
224 {
225 0 $self = __PACKAGE__->new;
226 }
227 0 my $meth = 'get';
228 0 ▶ for( my $i = 0; $i < scalar( @_ ); $i += 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @_) 0 0 0
229 {
230 0 ▶ if( $_[$i] eq 'method' )
Branch: 1 branch
BranchTrueFalseTotal
if ($_[$i] eq "method") 0 0 0
231 {
232 0 $meth = $_[$i + 1];
233 0 splice( @_, $i, 2 );
234 0 last;
235 }
236 }
237 0 ▶ return( $self->error( "Unknown HTTP method \"${meth}\"." ) ) if( $meth !~ /^$HTTP::Promise::Request::KNOWN_METHODS_I$/i );
Branch: 1 branch
BranchTrueFalseTotal
unless $meth =~ /^$HTTP::Promise::Request::KNOWN_METHODS_I$/i 0 0 0
238 0 ▶ my $code = $self->can( $meth ) ||
Condition0%0/2
$self->can($meth) || (return $self->error(qq[Somehow the HTTP method "$meth" is not supported by ], ref $self))
l!l
00
MC/DC0%0/1
$self->can($meth) || (return $self->error(qq[Somehow the HTTP method "$meth" is not supported by ], ref $self))
$self->can($meth)
Truth table0%0/2
A
A= $self->can($meth)
Aresult
11
00
239 return( $self->error( "Somehow the HTTP method \"${meth}\" is not supported by ", ref( $self ) ) );
240 0 return( $code->( $self, @_ ) );
241 }
242  
243 0 ▶sub file { return( shift->_set_get_object_without_init( 'file', 'Module::Generic::File', @_ ) ); }
Subroutine file: not called CC=1 SCAR=6.9
Pod documented
244  
245 # NOTE: request parameter
246 0 ▶sub from { return( shift->_set_get_scalar_as_object( 'from', @_ ) ); }
Subroutine from: not called CC=1 SCAR=6.9
Pod documented
247  
248 sub get
249 0 ▶{
Subroutine get: not called CC=8 SCAR=42.8
Pod documented
250 0 my $self = shift( @_ );
251 0 ▶ if( $self->use_promise )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_promise) { } 0 0 0
252 {
253 my $prom = Promise::Me->new(sub
254 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
255 0 my( $resolve, $reject ) = @$_;
256 0 ▶ my $req = $self->_make_request_query( GET => @_ ) ||
Condition0%0/2
$self->_make_request_query('GET', @_) || (return &$reject($self->error))
l!l
00
MC/DC0%0/1
$self->_make_request_query('GET', @_) || (return &$reject($self->error))
$self->_make_request_query('GET', @_)
Truth table0%0/2
A
A= $self->_make_request_query('GET', @_)
Aresult
11
00
257 return( $reject->( $self->error ) );
258 0 ▶ my $resp = $self->send( $req ) || return( $reject->( $self->error ) );
Condition0%0/2
$self->send($req) || (return &$reject($self->error))
l!l
00
MC/DC0%0/1
$self->send($req) || (return &$reject($self->error))
$self->send($req)
Truth table0%0/2
A
A= $self->send($req)
Aresult
11
00
259 0 return( $resolve->( $resp ) );
260 },
261 {
262 args => [@_],
263 ( defined( $self->{serialiser} ) ? ( serialiser => $self->{serialiser} ) : () ),
264 ( defined( $self->{medium} ) ? ( medium => $self->{medium} ) : () ),
265 0 ▶ ( defined( $self->{shared_mem_size} ) ? ( result_shared_mem_size => $self->{shared_mem_size} ) : () ),
Branch: 3 branches
BranchTrueFalseTotal
defined $self->{'serialiser'} ? : 0 0 0
defined $self->{'medium'} ? : 0 0 0
defined $self->{'shared_mem_size'} ? : 0 0 0
Condition0%0/2
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_query('GET', @_) || (return &$reject($self->error)); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()}) || (return $self->pass_error('Promise::Me'->error))
l!l
00
MC/DC0%0/1
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_query('GET', @_) || (return &$reject($self->error)); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()}) || (return $self->pass_error('Promise::Me'->error))
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_query('GET', @_) || (return &$reject($self->error)); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()})
Truth table0%0/2
A
A= 'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_query('GET', @_) || (return &$reject($self->error)); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()})
Aresult
11
00
266 }) || return( $self->pass_error( Promise::Me->error ) );
267 0 return( $prom );
268 }
269 else
270 {
271 0 ▶ my $req = $self->_make_request_query( GET => @_ ) ||
Condition0%0/2
$self->_make_request_query('GET', @_) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_make_request_query('GET', @_) || (return $self->pass_error)
$self->_make_request_query('GET', @_)
Truth table0%0/2
A
A= $self->_make_request_query('GET', @_)
Aresult
11
00
272 return( $self->pass_error );
273 0 ▶ my $resp = $self->send( $req ) ||
Condition0%0/2
$self->send($req) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->send($req) || (return $self->pass_error)
$self->send($req)
Truth table0%0/2
A
A= $self->send($req)
Aresult
11
00
274 return( $self->pass_error );
275 0 return( $resp );
276 }
277 }
278  
279 sub head
280 0 ▶{
Subroutine head: not called CC=8 SCAR=42.8
Pod documented
281 0 my $self = shift( @_ );
282 0 ▶ if( $self->use_promise )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_promise) { } 0 0 0
283 {
284 my $prom = Promise::Me->new(sub
285 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
286 0 my( $resolve, $reject ) = @$_;
287 0 ▶ my $req = $self->_make_request_query( HEAD => @_ ) ||
Condition0%0/2
$self->_make_request_query('HEAD', @_) || (return &$reject($self->error))
l!l
00
MC/DC0%0/1
$self->_make_request_query('HEAD', @_) || (return &$reject($self->error))
$self->_make_request_query('HEAD', @_)
Truth table0%0/2
A
A= $self->_make_request_query('HEAD', @_)
Aresult
11
00
288 return( $reject->( $self->error ) );
289 0 ▶ my $resp = $self->send( $req ) || return( $reject->( $self->error ) );
Condition0%0/2
$self->send($req) || (return &$reject($self->error))
l!l
00
MC/DC0%0/1
$self->send($req) || (return &$reject($self->error))
$self->send($req)
Truth table0%0/2
A
A= $self->send($req)
Aresult
11
00
290 0 return( $resolve->( $resp ) );
291 },
292 {
293 args => [@_],
294 ( defined( $self->{serialiser} ) ? ( serialiser => $self->{serialiser} ) : () ),
295 ( defined( $self->{medium} ) ? ( medium => $self->{medium} ) : () ),
296 0 ▶ ( defined( $self->{shared_mem_size} ) ? ( result_shared_mem_size => $self->{shared_mem_size} ) : () ),
Branch: 3 branches
BranchTrueFalseTotal
defined $self->{'serialiser'} ? : 0 0 0
defined $self->{'medium'} ? : 0 0 0
defined $self->{'shared_mem_size'} ? : 0 0 0
Condition0%0/2
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_query('HEAD', @_) || (return &$reject($self->error)); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()}) || (return $self->pass_error('Promise::Me'->error))
l!l
00
MC/DC0%0/1
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_query('HEAD', @_) || (return &$reject($self->error)); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()}) || (return $self->pass_error('Promise::Me'->error))
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_query('HEAD', @_) || (return &$reject($self->error)); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()})
Truth table0%0/2
A
A= 'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_query('HEAD', @_) || (return &$reject($self->error)); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()})
Aresult
11
00
297 }) || return( $self->pass_error( Promise::Me->error ) );
298 0 return( $prom );
299 }
300 else
301 {
302 0 ▶ my $req = $self->_make_request_query( HEAD => @_ ) ||
Condition0%0/2
$self->_make_request_query('HEAD', @_) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_make_request_query('HEAD', @_) || (return $self->pass_error)
$self->_make_request_query('HEAD', @_)
Truth table0%0/2
A
A= $self->_make_request_query('HEAD', @_)
Aresult
11
00
303 return( $self->pass_error );
304 0 ▶ my $resp = $self->send( $req ) ||
Condition0%0/2
$self->send($req) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->send($req) || (return $self->pass_error)
$self->send($req)
Truth table0%0/2
A
A= $self->send($req)
Aresult
11
00
305 return( $self->pass_error );
306 0 return( $resp );
307 }
308 }
309  
310 0 ▶sub httpize_datetime { return( shift->_datetime( @_ ) ); }
Subroutine httpize_datetime: not called CC=1 SCAR=6.9
Pod documented
311  
312 0 ▶sub inactivity_timeout { return( shift->_set_get_number( 'inactivity_timeout', @_ ) ); }
Subroutine inactivity_timeout: not called CC=1 SCAR=6.9
Pod documented
313  
314 sub is_protocol_supported
315 0 ▶{
Subroutine is_protocol_supported: not called CC=7 SCAR=40.3
Pod documented
316 0 my $self = shift( @_ );
317 0 ▶ my $scheme = shift( @_ ) ||
Condition0%0/2
shift @_ || (return $self->error('No scheme value was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No scheme value was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
318 return( $self->error( "No scheme value was provided." ) );
319 0 ▶ if( $self->_is_object( $scheme ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_object($scheme)) { } 0 0 0
320 {
321 0 ▶ return( $self->error( "Object provided (", overload::StrVal( $scheme ), ") does not support the 'scheme' method." ) ) if( !$scheme->can( 'scheme' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $scheme->can("scheme") 0 0 0
322 0 $scheme = $scheme->scheme;
323 }
324 else
325 {
326 0 ▶ return( $self->error( "Illegal scheme '$scheme' passed to is_protocol_supported" ) ) if( $scheme =~ /\W/ );
Branch: 1 branch
BranchTrueFalseTotal
if $scheme =~ /\W/ 0 0 0
327 0 $scheme = lc $scheme;
328 }
329 0 ▶ return(1) if( $scheme eq 'http' || $scheme eq 'https' );
Branch: 1 branch
BranchTrueFalseTotal
if $scheme eq "http" or $scheme eq "https" 0 0 0
Condition0%0/3
$scheme eq "http" or $scheme eq "https"
l!l&&r!l&&!r
000
MC/DC0%0/2
$scheme eq "http" or $scheme eq "https"
$scheme eq "http" $scheme eq "https"
Truth table0%0/3
A or B
A= $scheme eq "http"B= $scheme eq "https"
ABresult
1X1
011
000
330 0 return(0);
331 }
332  
333 0 ▶sub languages { return( shift->_set_get_array_as_object( 'accept_language', @_ ) ); }
Subroutine languages: not called CC=1 SCAR=6.9
Pod documented
334  
335 # NOTE: request parameter
336 0 ▶sub local_address { return( shift->_set_get_scalar( 'local_host', @_ ) ); }
Subroutine local_address: not called CC=1 SCAR=6.9
Pod documented
337  
338 0 ▶sub local_host { return( shift->_set_get_scalar( 'local_host', @_ ) ); }
Subroutine local_host: not called CC=1 SCAR=6.9
Pod documented
339  
340 0 ▶sub local_port { return( shift->_set_get_scalar( 'local_port', @_ ) ); }
Subroutine local_port: not called CC=1 SCAR=6.9
Pod documented
341  
342 0 ▶sub max_body_in_memory_size { return( shift->_set_get_number( 'max_body_in_memory_size', @_ ) ); }
Subroutine max_body_in_memory_size: not called CC=1 SCAR=6.9
Pod documented
343  
344 0 ▶sub max_headers_size { return( shift->_set_get_number( 'max_headers_size', @_ ) ); }
Subroutine max_headers_size: not called CC=1 SCAR=6.9
Pod documented
345  
346 # NOTE: request parameter
347 0 ▶sub max_redirect { return( shift->_set_get_number( 'max_redirect', @_ ) ); }
Subroutine max_redirect: not called CC=1 SCAR=6.9
Pod documented
348  
349 # NOTE: request parameter
350 0 ▶sub max_size { return( shift->_set_get_number( 'max_size', @_ ) ); }
Subroutine max_size: not called CC=1 SCAR=6.9
Pod documented
351  
352 # NOTE: medium method for Promise::Me
353 0 ▶sub medium { return( shift->_set_get_scalar( 'medium', @_ ) ); }
Subroutine medium: not called CC=1 SCAR=6.9
Pod documented
354  
355 sub mirror
356 0 ▶{
Subroutine mirror: not called CC=31 SCAR=69.0
Pod documented
357 0 my $self = shift( @_ );
358 0 my( $url, $file ) = @_;
359 0 ▶ if( $self->use_promise )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_promise) { } 0 0 0
360 {
361 return( Promise::Me->new(sub
362 0 ▶ {
Subroutine __ANON__: not called CC=32 SCAR=69.6
363 0 my( $resolve, $reject ) = @$_;
364 0 ▶ return( $reject->( HTTP::Promise::Exception->new({
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file and length $file 0 0 0
Condition0%0/3
defined $file and length $file
!ll&&!rl&&r
000
MC/DC0%0/2
defined $file and length $file
defined $file length $file
Truth table0%0/3
A and B
A= defined $fileB= length $file
ABresult
0X0
100
111
365 code => 500,
366 message => 'Local file name is missing',
367 }) ) ) unless( defined( $file ) && length( $file ) );
368  
369 0 ▶ my $request = HTTP::Promise::Request->new( 'GET' => $url ) ||
Condition0%0/2
'HTTP::Promise::Request'->new('GET', $url) || (return &$reject('HTTP::Promise::Exception'->new({'code', 500, 'message', 'HTTP::Promise::Request'->error->message})))
l!l
00
MC/DC0%0/1
'HTTP::Promise::Request'->new('GET', $url) || (return &$reject('HTTP::Promise::Exception'->new({'code', 500, 'message', 'HTTP::Promise::Request'->error->message})))
'HTTP::Promise::Request'->new('GET', $url)
Truth table0%0/2
A
A= 'HTTP::Promise::Request'->new('GET', $url)
Aresult
11
00
370 return( $reject->( HTTP::Promise::Exception->new({
371 code => 500,
372 message => HTTP::Promise::Request->error->message
373 }) ) );
374 0 ▶ $self->prepare_headers( $request ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->prepare_headers($request) or return &$reject("HTTP::Promise::Exception"->new({"code", 500, "message", $self->error->message})) 0 0 0
375 return( $reject->( HTTP::Promise::Exception->new({
376 code => 500,
377 message => $self->error->message,
378 }) ) );
379 0 ▶ $file = $self->new_file( $file ) ||
Condition0%0/2
$self->new_file($file) || (return &$reject('HTTP::Promise::Exception'->new({'code', 500, 'message', $self->error->message})))
l!l
00
MC/DC0%0/1
$self->new_file($file) || (return &$reject('HTTP::Promise::Exception'->new({'code', 500, 'message', $self->error->message})))
$self->new_file($file)
Truth table0%0/2
A
A= $self->new_file($file)
Aresult
11
00
380 return( $reject->( HTTP::Promise::Exception->new({
381 code => 500,
382 message => $self->error->message,
383 }) ) );
384 # If the file exists, add a cache-related header
385 0 ▶ if( $file->exists )
Branch: 1 branch
BranchTrueFalseTotal
if ($file->exists) 0 0 0
386 {
387 # Module::Generic::Finfo->mtime returns a Module::Generic::DateTime object
388 0 my $mtime = $file->mtime;
389 0 ▶ if( $mtime )
Branch: 1 branch
BranchTrueFalseTotal
if ($mtime) 0 0 0
390 {
391 0 ▶ my $strtime = $self->_datetime( $mtime ) ||
Condition0%0/2
$self->_datetime($mtime) || (return &$reject('HTTP::Promise::Exception'->new({'code', 500, 'message', $self->error->message})))
l!l
00
MC/DC0%0/1
$self->_datetime($mtime) || (return &$reject('HTTP::Promise::Exception'->new({'code', 500, 'message', $self->error->message})))
$self->_datetime($mtime)
Truth table0%0/2
A
A= $self->_datetime($mtime)
Aresult
11
00
392 return( $reject->( HTTP::Promise::Exception->new({
393 code => 500,
394 message => $self->error->message,
395 }) ) );
396 0 $request->header( 'If-Modified-Since' => $strtime );
397 }
398 }
399  
400 0 my $tmpfile = $self->new_tempfile;
401 0 ▶ $tmpfile->touch || return( $reject->( $tmpfile->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$tmpfile->touch or return &$reject($tmpfile->error) 0 0 0
402  
403 0 ▶ my $response = $self->send( $request ) || return( $reject->( $self->pass_error ) );
Condition0%0/2
$self->send($request) || (return &$reject($self->pass_error))
l!l
00
MC/DC0%0/1
$self->send($request) || (return &$reject($self->pass_error))
$self->send($request)
Truth table0%0/2
A
A= $self->send($request)
Aresult
11
00
404
405 0 ▶ if( $response->header( 'X-Died' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($response->header("X-Died")) 0 0 0
406 {
407 0 $tmpfile->unlink;
408 0 return( $reject->( HTTP::Promise::Exception->new({
409 code => 500,
410 message => $response->header( 'X-Died' ),
411 }) ) );
412 }
413  
414 # Only fetching a fresh copy of the file would be considered success.
415 # If the file was not modified, "304" would returned, which
416 # is considered by HTTP::Status to be a "redirect", /not/ "success"
417 0 ▶ if( $response->is_success )
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 0 0 0
418 {
419 0 my $body = $response->entity->body;
420 0 ▶ return( $reject->( HTTP::Promise::Exception->new({
Branch: 1 branch
BranchTrueFalseTotal
unless $body 0 0 0
421 code => 500,
422 message => "No body set for this HTTP message entity.",
423 }) ) ) if( !$body );
424 0 ▶ my $io = $body->open( '<' ) ||
Branch: 1 branch
BranchTrueFalseTotal
unless $body 0 0 0
Condition0%0/2
$body->open('<') || (return &$reject('HTTP::Promise::Exception'->new({'code', 500, 'message', 'Unable to open HTTP message entity body: ' . $body->error})))
l!l
00
MC/DC0%0/1
$body->open('<') || (return &$reject('HTTP::Promise::Exception'->new({'code', 500, 'message', 'Unable to open HTTP message entity body: ' . $body->error})))
$body->open('<')
Truth table0%0/2
A
A= $body->open('<')
Aresult
11
00
425 return( $reject->( HTTP::Promise::Exception->new({
426 code => 500,
427 message => "Unable to open HTTP message entity body: " . $body->error,
428 }) ) ) if( !$body );
429 0 ▶ my $out = $tmpfile->open( '>', { autoflush => 1 } ) ||
Branch: 1 branch
BranchTrueFalseTotal
unless $body 0 0 0
Condition0%0/2
$tmpfile->open('>', {'autoflush', 1}) || (return &$reject('HTTP::Promise::Exception'->new({'code', 500, 'message', qq[Unable to open temporary file "$tmpfile" in write mode: ] . $tmpfile->error})))
l!l
00
MC/DC0%0/1
$tmpfile->open('>', {'autoflush', 1}) || (return &$reject('HTTP::Promise::Exception'->new({'code', 500, 'message', qq[Unable to open temporary file "$tmpfile" in write mode: ] . $tmpfile->error})))
$tmpfile->open('>', {'autoflush', 1})
Truth table0%0/2
A
A= $tmpfile->open('>', {'autoflush', 1})
Aresult
11
00
430 return( $reject->( HTTP::Promise::Exception->new({
431 code => 500,
432 message => "Unable to open temporary file \"$tmpfile\" in write mode: " . $tmpfile->error,
433 }) ) ) if( !$body );
434 0 ▶ while( $io->read( my $buff, 8192 ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($io->read(my $buff, 8192)) 0 0 0
435 {
436 0 ▶ $out->print( $buff ) ||
Branch: 1 branch
BranchTrueFalseTotal
unless $body 0 0 0
Condition0%0/5
$body || ($out->print($buff) || (return &$reject('HTTP::Promise::Exception'->new({'code', 500, 'message', qq[Unable to write to temporary file "$tmpfile": ] . $out->error}))))
l!l&&r!l&&!r
000
$out->print($buff) or return &$reject("HTTP::Promise::Exception"->new({"code", 500, "message", qq[Unable to write to temporary file "$tmpfile": ] . $out->error}))
l!l
00
MC/DC0%0/2
$body || ($out->print($buff) || (return &$reject('HTTP::Promise::Exception'->new({'code', 500, 'message', qq[Unable to write to temporary file "$tmpfile": ] . $out->error}))))
$body $out->print($buff)
Truth table0%0/3
A || B
A= $bodyB= $out->print($buff)
ABresult
1X1
011
000
437 return( $reject->( HTTP::Promise::Exception->new({
438 code => 500,
439 message => "Unable to write to temporary file \"$tmpfile\": " . $out->error,
440 }) ) ) if( !$body );
441 }
442 0 $io->close;
443 0 $out->close;
444 0 ▶ my $stat = $tmpfile->stat or
Branch: 1 branch
BranchTrueFalseTotal
my $stat = $tmpfile->stat or return &$reject("HTTP::Promise::Exception"->new({"code", 500, "message", "Could not stat tmpfile '${tmpfile}': " . $tmpfile->error})) 0 0 0
445 return( $reject->( HTTP::Promise::Exception->new({
446 code => 500,
447 message => "Could not stat tmpfile '$tmpfile': " . $tmpfile->error,
448 }) ) );
449 0 my $file_length = $stat->size;
450 0 my( $content_length ) = $response->header( 'Content-length' );
451  
452 0 ▶ if( defined( $content_length ) and $file_length < $content_length )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $content_length and $file_length < $content_length) { } 0 0 0
elsif (defined $content_length and $file_length > $content_length) { } 0 0 0
Condition0%0/3
defined $content_length and $file_length < $content_length
!ll&&!rl&&r
000
MC/DC0%0/2
defined $content_length and $file_length < $content_length
defined $content_length $file_length < $content_length
Truth table0%0/3
A and B
A= defined $content_lengthB= $file_length < $content_length
ABresult
0X0
100
111
453 {
454 0 $tmpfile->unlink;
455 0 return( $reject->( HTTP::Promise::Exception->new({
456 code => 500,
457 message => "Transfer truncated: only $file_length out of $content_length bytes received",
458 }) ) );
459 }
460 ▶ elsif( defined( $content_length ) and $file_length > $content_length )
Condition0%0/3
defined $content_length and $file_length > $content_length
!ll&&!rl&&r
000
MC/DC0%0/2
defined $content_length and $file_length > $content_length
defined $content_length $file_length > $content_length
Truth table0%0/3
A and B
A= defined $content_lengthB= $file_length > $content_length
ABresult
0X0
100
111
461 {
462 0 $tmpfile->unlink;
463 0 return( $reject->( HTTP::Promise::Exception->new({
464 code => 500,
465 message => "Content-length mismatch: expected $content_length bytes, got $file_length",
466 }) ) );
467 }
468 # The file was the expected length.
469 else
470 {
471 # Replace the stale file with a fresh copy
472 # File::Copy will attempt to do it atomically,
473 # and fall back to a delete + copy if that fails.
474 0 ▶ $file = $tmpfile->move( $file, overwrite => 1 ) ||
Condition0%0/2
$tmpfile->move($file, 'overwrite', 1) || (return &$reject('HTTP::Promise::Exception'->new({'code', 500, 'message', "Cannot copy '${tmpfile}' to '${file}': $!"})))
l!l
00
MC/DC0%0/1
$tmpfile->move($file, 'overwrite', 1) || (return &$reject('HTTP::Promise::Exception'->new({'code', 500, 'message', "Cannot copy '${tmpfile}' to '${file}': $!"})))
$tmpfile->move($file, 'overwrite', 1)
Truth table0%0/2
A
A= $tmpfile->move($file, 'overwrite', 1)
Aresult
11
00
475 return( $reject->( HTTP::Promise::Exception->new({
476 code => 500,
477 message => "Cannot copy '$tmpfile' to '$file': $!",
478 }) ) );
479  
480 # Set standard file permissions if umask is supported.
481 # If not, leave what Module::Generic::File created in effect.
482 0 ▶ if( defined( my $umask = umask() ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $umask = umask())) 0 0 0
483 {
484 0 my $mode = 0666 &~ $umask;
485 0 ▶ $file->chmod( $mode ) ||
Branch: 1 branch
BranchTrueFalseTotal
$file->chmod($mode) or return &$reject("HTTP::Promise::Exception"->new({"code", 500, "message", sprintf("Cannot chmod %o '%s': %s", $mode, $file, $file->error)})) 0 0 0
486 return( $reject->( HTTP::Promise::Exception->new({
487 code => 500,
488 message => sprintf( "Cannot chmod %o '%s': %s", $mode, $file, $file->error ),
489 }) ) );
490 }
491  
492 # make sure the file has the same last modification time
493 0 ▶ if( my $lm = $response->last_modified )
Branch: 1 branch
BranchTrueFalseTotal
if (my $lm = $response->last_modified) 0 0 0
494 {
495 $file->utime( $lm, $lm ) || do
496 0 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
$file->utime($lm, $lm) or do { warn "Warning: cannot update modification time for file '${file}': $!\n" if $self->_warnings_is_enabled } 0 0 0
497 0 ▶ warn( "Warning: cannot update modification time for file '$file': $!\n" ) if( $self->_warnings_is_enabled );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_warnings_is_enabled 0 0 0
498 };
499 }
500 }
501 }
502 # The local copy is fresh enough, so just delete the temp file
503 else
504 {
505 0 $tmpfile->unlink;
506 }
507 0 return( $resolve->( $response ) );
508 0 ▶ }, { ( defined( $self->{serialiser} ) ? ( serialiser => $self->{serialiser} ) : () ) } ) );
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'serialiser'} ? : 0 0 0
509 }
510 else
511 {
512 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file and length $file 0 0 0
Condition0%0/3
defined $file and length $file
!ll&&!rl&&r
000
MC/DC0%0/2
defined $file and length $file
defined $file length $file
Truth table0%0/3
A and B
A= defined $fileB= length $file
ABresult
0X0
100
111
513 code => 500,
514 message => 'Local file name is missing',
515 }) ) unless( defined( $file ) && length( $file ) );
516  
517 0 ▶ my $request = HTTP::Promise::Request->new( 'GET' => $url ) ||
Condition0%0/2
'HTTP::Promise::Request'->new('GET', $url) || (return $self->error({'code', 500, 'message', 'HTTP::Promise::Request'->error->message}))
l!l
00
MC/DC0%0/1
'HTTP::Promise::Request'->new('GET', $url) || (return $self->error({'code', 500, 'message', 'HTTP::Promise::Request'->error->message}))
'HTTP::Promise::Request'->new('GET', $url)
Truth table0%0/2
A
A= 'HTTP::Promise::Request'->new('GET', $url)
Aresult
11
00
518 return( $self->error({
519 code => 500,
520 message => HTTP::Promise::Request->error->message
521 }) );
522 0 ▶ $self->prepare_headers( $request ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->prepare_headers($request) or return $self->pass_error 0 0 0
523 0 ▶ $file = $self->new_file( $file ) || return( $self->pass_error );
Condition0%0/2
$self->new_file($file) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_file($file) || (return $self->pass_error)
$self->new_file($file)
Truth table0%0/2
A
A= $self->new_file($file)
Aresult
11
00
524 # If the file exists, add a cache-related header
525 0 ▶ if( $file->exists )
Branch: 1 branch
BranchTrueFalseTotal
if ($file->exists) 0 0 0
526 {
527 # Module::Generic::Finfo->mtime returns a Module::Generic::DateTime object
528 0 my $mtime = $file->mtime;
529 0 ▶ if( $mtime )
Branch: 1 branch
BranchTrueFalseTotal
if ($mtime) 0 0 0
530 {
531 0 ▶ my $strtime = $self->_datetime( $mtime ) ||
Condition0%0/2
$self->_datetime($mtime) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_datetime($mtime) || (return $self->pass_error)
$self->_datetime($mtime)
Truth table0%0/2
A
A= $self->_datetime($mtime)
Aresult
11
00
532 return( $self->pass_error );
533 0 $request->header( 'If-Modified-Since' => $strtime );
534 }
535 }
536  
537 0 my $tmpfile = $self->new_tempfile;
538 0 ▶ $tmpfile->touch || return( $self->pass_error( $tmpfile->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$tmpfile->touch or return $self->pass_error($tmpfile->error) 0 0 0
539  
540 0 ▶ my $response = $self->send( $request ) || return( $self->pass_error );
Condition0%0/2
$self->send($request) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->send($request) || (return $self->pass_error)
$self->send($request)
Truth table0%0/2
A
A= $self->send($request)
Aresult
11
00
541  
542 0 ▶ if( $response->header( 'X-Died' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($response->header("X-Died")) 0 0 0
543 {
544 0 $tmpfile->unlink;
545 0 return( $self->error({
546 code => 500,
547 message => $response->header( 'X-Died' ),
548 }) );
549 }
550  
551 # Only fetching a fresh copy of the file would be considered success.
552 # If the file was not modified, "304" would returned, which
553 # is considered by HTTP::Status to be a "redirect", /not/ "success"
554 0 ▶ if( $response->is_success )
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 0 0 0
555 {
556 0 my $body = $response->entity->body;
557 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless $body 0 0 0
558 code => 500,
559 message => "No body set for this HTTP message entity.",
560 }) ) if( !$body );
561 0 ▶ my $io = $body->open( '<' ) ||
Condition0%0/2
$body->open('<') || (return $self->error({'code', 500, 'message', 'Unable to open HTTP message entity body: ' . $body->error}))
l!l
00
MC/DC0%0/1
$body->open('<') || (return $self->error({'code', 500, 'message', 'Unable to open HTTP message entity body: ' . $body->error}))
$body->open('<')
Truth table0%0/2
A
A= $body->open('<')
Aresult
11
00
562 return( $self->error({
563 code => 500,
564 message => "Unable to open HTTP message entity body: " . $body->error,
565 }) );
566 0 ▶ my $out = $tmpfile->open( '>', { autoflush => 1 } ) ||
Condition0%0/2
$tmpfile->open('>', {'autoflush', 1}) || (return $self->error({'code', 500, 'message', qq[Unable to open temporary file "$tmpfile" in write mode: ] . $tmpfile->error}))
l!l
00
MC/DC0%0/1
$tmpfile->open('>', {'autoflush', 1}) || (return $self->error({'code', 500, 'message', qq[Unable to open temporary file "$tmpfile" in write mode: ] . $tmpfile->error}))
$tmpfile->open('>', {'autoflush', 1})
Truth table0%0/2
A
A= $tmpfile->open('>', {'autoflush', 1})
Aresult
11
00
567 return( $self->error({
568 code => 500,
569 message => "Unable to open temporary file \"$tmpfile\" in write mode: " . $tmpfile->error,
570 }) );
571 0 ▶ while( $io->read( my $buff, 8192 ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($io->read(my $buff, 8192)) 0 0 0
572 {
573 0 ▶ $out->print( $buff ) ||
Branch: 1 branch
BranchTrueFalseTotal
$out->print($buff) or return $self->error({"code", 500, "message", qq[Unable to write to temporary file "$tmpfile": ] . $out->error}) 0 0 0
574 return( $self->error({
575 code => 500,
576 message => "Unable to write to temporary file \"$tmpfile\": " . $out->error,
577 }) );
578 }
579 0 $io->close;
580 0 $out->close;
581 0 ▶ my $stat = $tmpfile->stat or
Branch: 1 branch
BranchTrueFalseTotal
my $stat = $tmpfile->stat or return $self->error({"code", 500, "message", "Could not stat tmpfile '${tmpfile}': " . $tmpfile->error}) 0 0 0
582 return( $self->error({
583 code => 500,
584 message => "Could not stat tmpfile '$tmpfile': " . $tmpfile->error,
585 }) );
586 0 my $file_length = $stat->size;
587 0 my( $content_length ) = $response->header( 'Content-length' );
588  
589 0 ▶ if( defined( $content_length ) and $file_length < $content_length )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $content_length and $file_length < $content_length) { } 0 0 0
elsif (defined $content_length and $file_length > $content_length) { } 0 0 0
Condition0%0/3
defined $content_length and $file_length < $content_length
!ll&&!rl&&r
000
MC/DC0%0/2
defined $content_length and $file_length < $content_length
defined $content_length $file_length < $content_length
Truth table0%0/3
A and B
A= defined $content_lengthB= $file_length < $content_length
ABresult
0X0
100
111
590 {
591 0 $tmpfile->unlink;
592 0 return( $self->error({
593 code => 500,
594 message => "Transfer truncated: only $file_length out of $content_length bytes received",
595 }) );
596 }
597 ▶ elsif( defined( $content_length ) and $file_length > $content_length )
Condition0%0/3
defined $content_length and $file_length > $content_length
!ll&&!rl&&r
000
MC/DC0%0/2
defined $content_length and $file_length > $content_length
defined $content_length $file_length > $content_length
Truth table0%0/3
A and B
A= defined $content_lengthB= $file_length > $content_length
ABresult
0X0
100
111
598 {
599 0 $tmpfile->unlink;
600 0 return( $self->error({
601 code => 500,
602 message => "Content-length mismatch: expected $content_length bytes, got $file_length",
603 }) );
604 }
605 # The file was the expected length.
606 else
607 {
608 # Replace the stale file with a fresh copy
609 # File::Copy will attempt to do it atomically,
610 # and fall back to a delete + copy if that fails.
611 0 ▶ $file = $tmpfile->move( $file, overwrite => 1 ) ||
Condition0%0/2
$tmpfile->move($file, 'overwrite', 1) || (return $self->error({'code', 500, 'message', "Cannot copy '${tmpfile}' to '${file}': $!"}))
l!l
00
MC/DC0%0/1
$tmpfile->move($file, 'overwrite', 1) || (return $self->error({'code', 500, 'message', "Cannot copy '${tmpfile}' to '${file}': $!"}))
$tmpfile->move($file, 'overwrite', 1)
Truth table0%0/2
A
A= $tmpfile->move($file, 'overwrite', 1)
Aresult
11
00
612 return( $self->error({
613 code => 500,
614 message => "Cannot copy '$tmpfile' to '$file': $!",
615 }) );
616  
617 # Set standard file permissions if umask is supported.
618 # If not, leave what Module::Generic::File created in effect.
619 0 ▶ if( defined( my $umask = umask() ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $umask = umask())) 0 0 0
620 {
621 0 my $mode = 0666 &~ $umask;
622 0 ▶ $file->chmod( $mode ) ||
Branch: 1 branch
BranchTrueFalseTotal
$file->chmod($mode) or return $self->error({"code", 500, "message", sprintf("Cannot chmod %o '%s': %s", $mode, $file, $file->error)}) 0 0 0
623 return( $self->error({
624 code => 500,
625 message => sprintf( "Cannot chmod %o '%s': %s", $mode, $file, $file->error ),
626 }) );
627 }
628  
629 # make sure the file has the same last modification time
630 0 ▶ if( my $lm = $response->last_modified )
Branch: 1 branch
BranchTrueFalseTotal
if (my $lm = $response->last_modified) 0 0 0
631 {
632 $file->utime( $lm, $lm ) || do
633 0 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
$file->utime($lm, $lm) or do { warn "Warning: cannot update modification time for file '${file}': $!\n" if $self->_warnings_is_enabled } 0 0 0
634 0 ▶ warn( "Warning: cannot update modification time for file '$file': $!\n" ) if( $self->_warnings_is_enabled );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_warnings_is_enabled 0 0 0
635 };
636 }
637 }
638 }
639 # The local copy is fresh enough, so just delete the temp file
640 else
641 {
642 0 $tmpfile->unlink;
643 }
644 0 return( $response );
645 }
646 }
647  
648 sub new_headers
649 0 ▶{
Subroutine new_headers: not called CC=3 SCAR=24.8
Pod documented
650 0 my $self = shift( @_ );
651 0 ▶ $self->_load_class( 'HTTP::Promise::Headers' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Headers") or return $self->pass_error 0 0 0
652 0 ▶ my $headers = HTTP::Promise::Headers->new( @_ ) ||
Condition0%0/2
'HTTP::Promise::Headers'->new(@_) || (return $self->pass_error('HTTP::Promise::Headers'->error))
l!l
00
MC/DC0%0/1
'HTTP::Promise::Headers'->new(@_) || (return $self->pass_error('HTTP::Promise::Headers'->error))
'HTTP::Promise::Headers'->new(@_)
Truth table0%0/2
A
A= 'HTTP::Promise::Headers'->new(@_)
Aresult
11
00
653 return( $self->pass_error( HTTP::Promise::Headers->error ) );
654 0 return( $headers );
655 }
656  
657 # NOTE: request parameter
658 0 ▶sub no_proxy { return( shift->_set_get_array_as_object( 'no_proxy', @_ ) ); }
Subroutine no_proxy: not called CC=1 SCAR=6.9
Pod documented
659  
660 sub options
661 0 ▶{
Subroutine options: not called CC=8 SCAR=42.8
Pod documented
662 0 my $self = shift( @_ );
663 0 ▶ if( $self->use_promise )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_promise) { } 0 0 0
664 {
665 my $prom = Promise::Me->new(sub
666 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
667 0 my( $resolve, $reject ) = @$_;
668 0 ▶ my $req = $self->_make_request_data( OPTIONS => @_ ) ||
Condition0%0/2
$self->_make_request_data('OPTIONS', @_) || die('HTTP::Promise::Request'->error)
l!l
00
MC/DC0%0/1
$self->_make_request_data('OPTIONS', @_) || die('HTTP::Promise::Request'->error)
$self->_make_request_data('OPTIONS', @_)
Truth table0%0/2
A
A= $self->_make_request_data('OPTIONS', @_)
Aresult
11
00
669 die( HTTP::Promise::Request->error );
670 0 ▶ my $resp = $self->send( $req ) || return( $reject->( $self->error ) );
Condition0%0/2
$self->send($req) || (return &$reject($self->error))
l!l
00
MC/DC0%0/1
$self->send($req) || (return &$reject($self->error))
$self->send($req)
Truth table0%0/2
A
A= $self->send($req)
Aresult
11
00
671 0 return( $resolve->( $resp ) );
672 },
673 {
674 args => [@_],
675 ( defined( $self->{serialiser} ) ? ( serialiser => $self->{serialiser} ) : () ),
676 ( defined( $self->{medium} ) ? ( medium => $self->{medium} ) : () ),
677 0 ▶ ( defined( $self->{shared_mem_size} ) ? ( result_shared_mem_size => $self->{shared_mem_size} ) : () ),
Branch: 3 branches
BranchTrueFalseTotal
defined $self->{'serialiser'} ? : 0 0 0
defined $self->{'medium'} ? : 0 0 0
defined $self->{'shared_mem_size'} ? : 0 0 0
Condition0%0/2
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_data('OPTIONS', @_) || die('HTTP::Promise::Request'->error); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()}) || (return $self->pass_error('Promise::Me'->error))
l!l
00
MC/DC0%0/1
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_data('OPTIONS', @_) || die('HTTP::Promise::Request'->error); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()}) || (return $self->pass_error('Promise::Me'->error))
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_data('OPTIONS', @_) || die('HTTP::Promise::Request'->error); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()})
Truth table0%0/2
A
A= 'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_data('OPTIONS', @_) || die('HTTP::Promise::Request'->error); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()})
Aresult
11
00
678 }) || return( $self->pass_error( Promise::Me->error ) );
679 0 return( $prom );
680 }
681 else
682 {
683 0 ▶ my $req = $self->_make_request_data( OPTIONS => @_ ) ||
Condition0%0/2
$self->_make_request_data('OPTIONS', @_) || (return $self->pass_error('HTTP::Promise::Request'->error))
l!l
00
MC/DC0%0/1
$self->_make_request_data('OPTIONS', @_) || (return $self->pass_error('HTTP::Promise::Request'->error))
$self->_make_request_data('OPTIONS', @_)
Truth table0%0/2
A
A= $self->_make_request_data('OPTIONS', @_)
Aresult
11
00
684 return( $self->pass_error( HTTP::Promise::Request->error ) );
685 0 ▶ my $resp = $self->send( $req ) ||
Condition0%0/2
$self->send($req) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->send($req) || (return $self->pass_error)
$self->send($req)
Truth table0%0/2
A
A= $self->send($req)
Aresult
11
00
686 return( $self->pass_error );
687 0 return( $resp );
688 }
689 }
690  
691 sub patch
692 0 ▶{
Subroutine patch: not called CC=8 SCAR=42.8
Pod documented
693 0 my $self = shift( @_ );
694 0 ▶ if( $self->use_promise )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_promise) { } 0 0 0
695 {
696 my $prom = Promise::Me->new(sub
697 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
698 0 my( $resolve, $reject ) = @$_;
699 0 ▶ my $req = $self->_make_request_data( PATCH => @_ ) ||
Condition0%0/2
$self->_make_request_data('PATCH', @_) || die('HTTP::Promise::Request'->error)
l!l
00
MC/DC0%0/1
$self->_make_request_data('PATCH', @_) || die('HTTP::Promise::Request'->error)
$self->_make_request_data('PATCH', @_)
Truth table0%0/2
A
A= $self->_make_request_data('PATCH', @_)
Aresult
11
00
700 die( HTTP::Promise::Request->error );
701 0 ▶ my $resp = $self->send( $req ) || return( $reject->( $self->error ) );
Condition0%0/2
$self->send($req) || (return &$reject($self->error))
l!l
00
MC/DC0%0/1
$self->send($req) || (return &$reject($self->error))
$self->send($req)
Truth table0%0/2
A
A= $self->send($req)
Aresult
11
00
702 0 return( $resolve->( $resp ) );
703 },
704 {
705 args => [@_],
706 ( defined( $self->{serialiser} ) ? ( serialiser => $self->{serialiser} ) : () ),
707 ( defined( $self->{medium} ) ? ( medium => $self->{medium} ) : () ),
708 0 ▶ ( defined( $self->{shared_mem_size} ) ? ( result_shared_mem_size => $self->{shared_mem_size} ) : () ),
Branch: 3 branches
BranchTrueFalseTotal
defined $self->{'serialiser'} ? : 0 0 0
defined $self->{'medium'} ? : 0 0 0
defined $self->{'shared_mem_size'} ? : 0 0 0
Condition0%0/2
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_data('PATCH', @_) || die('HTTP::Promise::Request'->error); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()}) || (return $self->pass_error('Promise::Me'->error))
l!l
00
MC/DC0%0/1
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_data('PATCH', @_) || die('HTTP::Promise::Request'->error); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()}) || (return $self->pass_error('Promise::Me'->error))
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_data('PATCH', @_) || die('HTTP::Promise::Request'->error); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()})
Truth table0%0/2
A
A= 'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_data('PATCH', @_) || die('HTTP::Promise::Request'->error); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()})
Aresult
11
00
709 }) || return( $self->pass_error( Promise::Me->error ) );
710 0 return( $prom );
711 }
712 else
713 {
714 0 ▶ my $req = $self->_make_request_data( PATCH => @_ ) ||
Condition0%0/2
$self->_make_request_data('PATCH', @_) || (return $self->pass_error('HTTP::Promise::Request'->error))
l!l
00
MC/DC0%0/1
$self->_make_request_data('PATCH', @_) || (return $self->pass_error('HTTP::Promise::Request'->error))
$self->_make_request_data('PATCH', @_)
Truth table0%0/2
A
A= $self->_make_request_data('PATCH', @_)
Aresult
11
00
715 return( $self->pass_error( HTTP::Promise::Request->error ) );
716 0 ▶ my $resp = $self->send( $req ) ||
Condition0%0/2
$self->send($req) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->send($req) || (return $self->pass_error)
$self->send($req)
Truth table0%0/2
A
A= $self->send($req)
Aresult
11
00
717 return( $self->pass_error );
718 0 return( $resp );
719 }
720 }
721  
722 sub post
723 0 ▶{
Subroutine post: not called CC=8 SCAR=42.8
Pod documented
724 0 my $self = shift( @_ );
725 0 my @args = @_;
726 0 ▶ if( $self->use_promise )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_promise) { } 0 0 0
727 {
728 my $prom = Promise::Me->new(sub
729 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
730 0 my( $resolve, $reject ) = @$_;
731 0 ▶ my $req = $self->_make_request_data( POST => @args ) ||
Condition0%0/2
$self->_make_request_data('POST', @args) || die('HTTP::Promise::Request'->error)
l!l
00
MC/DC0%0/1
$self->_make_request_data('POST', @args) || die('HTTP::Promise::Request'->error)
$self->_make_request_data('POST', @args)
Truth table0%0/2
A
A= $self->_make_request_data('POST', @args)
Aresult
11
00
732 die( HTTP::Promise::Request->error );
733 0 ▶ my $resp = $self->send( $req ) || return( $reject->( $self->error ) );
Condition0%0/2
$self->send($req) || (return &$reject($self->error))
l!l
00
MC/DC0%0/1
$self->send($req) || (return &$reject($self->error))
$self->send($req)
Truth table0%0/2
A
A= $self->send($req)
Aresult
11
00
734 0 return( $resolve->( $resp ) );
735 },
736 {
737 args => [@_],
738 ( defined( $self->{serialiser} ) ? ( serialiser => $self->{serialiser} ) : () ),
739 ( defined( $self->{medium} ) ? ( medium => $self->{medium} ) : () ),
740 0 ▶ ( defined( $self->{shared_mem_size} ) ? ( result_shared_mem_size => $self->{shared_mem_size} ) : () ),
Branch: 3 branches
BranchTrueFalseTotal
defined $self->{'serialiser'} ? : 0 0 0
defined $self->{'medium'} ? : 0 0 0
defined $self->{'shared_mem_size'} ? : 0 0 0
Condition0%0/2
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_data('POST', @args) || die('HTTP::Promise::Request'->error); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()}) || (return $self->pass_error('Promise::Me'->error))
l!l
00
MC/DC0%0/1
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_data('POST', @args) || die('HTTP::Promise::Request'->error); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()}) || (return $self->pass_error('Promise::Me'->error))
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_data('POST', @args) || die('HTTP::Promise::Request'->error); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()})
Truth table0%0/2
A
A= 'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_data('POST', @args) || die('HTTP::Promise::Request'->error); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()})
Aresult
11
00
741 }) || return( $self->pass_error( Promise::Me->error ) );
742 0 return( $prom );
743 }
744 else
745 {
746 0 ▶ my $req = $self->_make_request_data( POST => @args ) ||
Condition0%0/2
$self->_make_request_data('POST', @args) || (return $self->pass_error('HTTP::Promise::Request'->error))
l!l
00
MC/DC0%0/1
$self->_make_request_data('POST', @args) || (return $self->pass_error('HTTP::Promise::Request'->error))
$self->_make_request_data('POST', @args)
Truth table0%0/2
A
A= $self->_make_request_data('POST', @args)
Aresult
11
00
747 return( $self->pass_error( HTTP::Promise::Request->error ) );
748 0 ▶ my $resp = $self->send( $req ) ||
Condition0%0/2
$self->send($req) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->send($req) || (return $self->pass_error)
$self->send($req)
Truth table0%0/2
A
A= $self->send($req)
Aresult
11
00
749 return( $self->pass_error );
750 0 return( $resp );
751 }
752 }
753  
754 sub prepare
755 0 ▶{
Subroutine prepare: not called CC=9 SCAR=45.0
Pod documented
756 0 my $self = shift( @_ );
757 0 ▶ my $meth = shift( @_ ) || return( $self->error( "No HTTP method was provided to prepare the request." ) );
Condition0%0/2
shift @_ || (return $self->error('No HTTP method was provided to prepare the request.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No HTTP method was provided to prepare the request.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
758 0 my @args = @_;
759 0 $meth = uc( $meth );
760 0 ▶ if( $meth eq 'GET' || $meth eq 'HEAD' )
Branch: 2 branches
BranchTrueFalseTotal
if ($meth eq 'GET' or $meth eq 'HEAD') { } 0 0 0
elsif ($meth eq 'OPTIONS' or $meth eq 'PATCH' or $meth eq 'POST' or $meth eq 'PUT') { } 0 0 0
Condition0%0/3
$meth eq "GET" or $meth eq "HEAD"
l!l&&r!l&&!r
000
MC/DC0%0/2
$meth eq "GET" or $meth eq "HEAD"
$meth eq "GET" $meth eq "HEAD"
Truth table0%0/3
A or B
A= $meth eq "GET"B= $meth eq "HEAD"
ABresult
1X1
011
000
761 {
762 0 return( $self->_make_request_query( $meth, @args ) );
763 }
764 ▶ elsif( $meth eq 'OPTIONS' || $meth eq 'PATCH' || $meth eq 'POST' || $meth eq 'PUT' )
Condition0%0/9
$meth eq "OPTIONS" or $meth eq "PATCH" or $meth eq "POST" or $meth eq "PUT"
l!l&&r!l&&!r
000
$meth eq "OPTIONS" or $meth eq "PATCH" or $meth eq "POST"
l!l&&r!l&&!r
000
$meth eq "OPTIONS" or $meth eq "PATCH"
l!l&&r!l&&!r
000
MC/DC0%0/4
$meth eq "OPTIONS" or $meth eq "PATCH" or $meth eq "POST" or $meth eq "PUT"
$meth eq "OPTIONS" $meth eq "PATCH" $meth eq "POST" $meth eq "PUT"
Truth table0%0/5
A or B or C or D
A= $meth eq "OPTIONS"B= $meth eq "PATCH"C= $meth eq "POST"D= $meth eq "PUT"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
765 {
766 0 return( $self->_make_request_data( $meth, @args ) );
767 }
768 else
769 {
770 0 ▶ my $req = HTTP::Promise::Request->new( $meth, @args ) ||
Condition0%0/2
'HTTP::Promise::Request'->new($meth, @args) || (return $self->pass_error('HTTP::Promise::Request'->error))
l!l
00
MC/DC0%0/1
'HTTP::Promise::Request'->new($meth, @args) || (return $self->pass_error('HTTP::Promise::Request'->error))
'HTTP::Promise::Request'->new($meth, @args)
Truth table0%0/2
A
A= 'HTTP::Promise::Request'->new($meth, @args)
Aresult
11
00
771 return( $self->pass_error( HTTP::Promise::Request->error ) );
772 0 return( $req );
773 }
774 }
775  
776 sub prepare_headers
777 0 ▶{
Subroutine prepare_headers: not called CC=23 SCAR=62.2
Pod documented
778 0 my $self = shift( @_ );
779 0 my $req = shift( @_ );
780 0 ▶ return( $self->error( "Object provided is not an HTTP::Promise::Request object" ) ) if( !$self->_is_a( $req => 'HTTP::Promise::Request' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($req, "HTTP::Promise::Request") 0 0 0
781 0 my $h = $req->headers;
782 0 ▶ return( $self->error( "Request object provided does not have an HTTP::Promise::Headers object set to it!" ) ) if( !$h );
Branch: 1 branch
BranchTrueFalseTotal
unless $h 0 0 0
783 0 ▶ unless( $req->protocol )
Branch: 1 branch
BranchTrueFalseTotal
unless ($req->protocol) 0 0 0
784 {
785 0 ▶ $req->protocol( $self->default_protocol || 'HTTP/1.1' );
Condition0%0/2
$self->default_protocol || 'HTTP/1.1'
l!l
00
MC/DC0%0/1
$self->default_protocol || 'HTTP/1.1'
$self->default_protocol
Truth table0%0/2
A
A= $self->default_protocol
Aresult
11
00
786 }
787
788 # Set default headers now
789 0 my $default_headers = $self->default_headers;
790 $default_headers->scan(sub
791 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
792 0 my( $name, $value ) = @_;
793 0 $h->header( $name => $value );
794 0 });
795
796 0 my $ua = $self->agent;
797 0 ▶ if( defined( $ua ) && !$h->user_agent )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ua and not $h->user_agent) 0 0 0
Condition0%0/3
defined $ua and not $h->user_agent
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ua and not $h->user_agent
defined $ua not $h->user_agent
Truth table0%0/3
A and not(B)
A= defined $uaB= not $h->user_agent
ABresult
0X0
100
111
798 {
799 0 $h->user_agent( $ua );
800 }
801 # e.g.: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
802 0 ▶ if( !$h->accept )
Branch: 1 branch
BranchTrueFalseTotal
unless ($h->accept) 0 0 0
803 {
804 0 $h->accept( 'text/html,application/xhtml+xml;q=0.9,*/*;q=0.8' );
805 }
806 # Accept-Encoding: gzip, deflate, br
807 0 my $ae = $self->accept_encoding;
808 0 ▶ if( !$h->accept_encoding && $ae ne 'none' )
Branch: 1 branch
BranchTrueFalseTotal
if (not $h->accept_encoding and $ae ne "none") 0 0 0
Condition0%0/3
not $h->accept_encoding and $ae ne "none"
!ll&&!rl&&r
000
MC/DC0%0/2
not $h->accept_encoding and $ae ne "none"
not $h->accept_encoding $ae ne "none"
Truth table0%0/3
not(A) and B
A= not $h->accept_encodingB= $ae ne "none"
ABresult
0X0
100
111
809 {
810 0 ▶ $self->_load_class( 'HTTP::Promise::Stream' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Stream") or return $self->pass_error 0 0 0
811 0 my $decodables;
812 2 ▶ no warnings 'once'; # REMOVE ME
Subroutine BEGIN: called CC=1 SCAR=0.0
813 0 local $HTTP::Promise::Stream::DEBUG = $self->debug; # REMOVE ME
814 0 ▶ if( !$ae->is_empty && $ae ne 'all' && $ae ne 'auto' )
Branch: 1 branch
BranchTrueFalseTotal
if (not $ae->is_empty and $ae ne 'all' and $ae ne 'auto') { } 0 0 0
Condition0%0/6
not $ae->is_empty and $ae ne "all" and $ae ne "auto"
!ll&&!rl&&r
000
not $ae->is_empty and $ae ne "all"
!ll&&!rl&&r
000
MC/DC0%0/3
not $ae->is_empty and $ae ne "all" and $ae ne "auto"
not $ae->is_empty $ae ne "all" $ae ne "auto"
Truth table0%0/4
not(A) and B and C
A= not $ae->is_emptyB= $ae ne "all"C= $ae ne "auto"
ABCresult
0XX0
10X0
1100
1111
815 {
816 0 $decodables = HTTP::Promise::Stream->decodable( [split( /[[:blank:]\h]*\,[[:blank:]\h]*/, "$ae" )] );
817 }
818 else
819 {
820 0 $decodables = HTTP::Promise::Stream->decodable( 'browser' );
821 }
822 0 $h->accept_encoding( $decodables->join( ',' )->scalar );
823 }
824 # Accept-Language: fr-FR,en-GB;q=0.8,fr;q=0.6,en;q=0.4,ja;q=0.2
825 0 ▶ if( !$h->accept_language && !$self->accept_language->is_empty )
Branch: 1 branch
BranchTrueFalseTotal
unless ($h->accept_language or $self->accept_language->is_empty) 0 0 0
Condition0%0/3
$h->accept_language or $self->accept_language->is_empty
l!l&&r!l&&!r
000
MC/DC0%0/2
$h->accept_language or $self->accept_language->is_empty
$h->accept_language $self->accept_language->is_empty
Truth table0%0/3
A or B
A= $h->accept_languageB= $self->accept_language->is_empty
ABresult
1X1
011
000
826 {
827 0 my $pref = 0.9;
828 0 my $langs = [];
829 $self->accept_language->foreach(sub
830 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
831 0 push( @$langs, sprintf( '%s;q=%.1f', $_, $pref ) );
832 0 ▶ $pref -= 0.1 unless( $pref == 0.1 );
Branch: 1 branch
BranchTrueFalseTotal
unless $pref == "0.1" 0 0 0
833 0 });
834 0 $h->accept_language( join( ',', @$langs ) );
835 }
836 0 my $dnt = $self->dnt;
837 0 ▶ if( !defined( $h->dnt ) && defined( $dnt ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $h->dnt and defined $dnt) 0 0 0
Condition0%0/3
not defined $h->dnt and defined $dnt
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $h->dnt and defined $dnt
not defined $h->dnt defined $dnt
Truth table0%0/3
not(A) and B
A= not defined $h->dntB= defined $dnt
ABresult
0X0
100
111
838 {
839 0 ▶ $h->dnt( $dnt ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$dnt ? : 0 0 0
840 }
841 # Upgrade-Insecure-Requests: 1
842 0 my $upgrade_ssl = $self->auto_switch_https;
843 0 ▶ if( $req->uri->scheme eq 'http' && ( !defined( $upgrade_ssl ) || $upgrade_ssl ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($req->uri->scheme eq "http" and !defined($upgrade_ssl) || $upgrade_ssl) 0 0 0
Condition0%0/6
$req->uri->scheme eq "http" and !defined($upgrade_ssl) || $upgrade_ssl
!ll&&!rl&&r
000
not defined $upgrade_ssl or $upgrade_ssl
l!l&&r!l&&!r
000
MC/DC0%0/3
$req->uri->scheme eq "http" and !defined($upgrade_ssl) || $upgrade_ssl
$req->uri->scheme eq "http" not defined $upgrade_ssl $upgrade_ssl
Truth table0%0/4
A and not(B) or C
A= $req->uri->scheme eq "http"B= not defined $upgrade_sslC= $upgrade_ssl
ABCresult
0XX0
1000
11X1
1011
844 {
845 0 $h->upgrade_insecure_requests(1);
846 }
847 0 ▶ unless( $req->headers->host )
Branch: 1 branch
BranchTrueFalseTotal
unless ($req->headers->host) 0 0 0
848 {
849 0 $req->headers->host( $req->host );
850 }
851 0 return( $req );
852 }
853  
854 0 ▶sub proxy { return( shift->_set_get_scalar_as_object( 'proxy', @_ ) ); }
Subroutine proxy: not called CC=1 SCAR=6.9
Pod documented
855  
856 0 ▶sub proxy_authorization { return( shift->_set_get_scalar_as_object( 'proxy_authorization', @_ ) ); }
Subroutine proxy_authorization: not called CC=1 SCAR=6.9
Pod documented
857  
858 sub put
859 0 ▶{
Subroutine put: not called CC=8 SCAR=42.8
Pod documented
860 0 my $self = shift( @_ );
861 0 ▶ if( $self->use_promise )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_promise) { } 0 0 0
862 {
863 my $prom = Promise::Me->new(sub
864 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
865 0 my( $resolve, $reject ) = @$_;
866 0 ▶ my $req = $self->_make_request_data( PUT => @_ ) ||
Condition0%0/2
$self->_make_request_data('PUT', @_) || die('HTTP::Promise::Request'->error)
l!l
00
MC/DC0%0/1
$self->_make_request_data('PUT', @_) || die('HTTP::Promise::Request'->error)
$self->_make_request_data('PUT', @_)
Truth table0%0/2
A
A= $self->_make_request_data('PUT', @_)
Aresult
11
00
867 die( HTTP::Promise::Request->error );
868 0 ▶ my $resp = $self->send( $req ) || return( $reject->( $self->error ) );
Condition0%0/2
$self->send($req) || (return &$reject($self->error))
l!l
00
MC/DC0%0/1
$self->send($req) || (return &$reject($self->error))
$self->send($req)
Truth table0%0/2
A
A= $self->send($req)
Aresult
11
00
869 0 return( $resolve->( $resp ) );
870 },
871 {
872 args => [@_],
873 ( defined( $self->{serialiser} ) ? ( serialiser => $self->{serialiser} ) : () ),
874 ( defined( $self->{medium} ) ? ( medium => $self->{medium} ) : () ),
875 0 ▶ ( defined( $self->{shared_mem_size} ) ? ( result_shared_mem_size => $self->{shared_mem_size} ) : () ),
Branch: 3 branches
BranchTrueFalseTotal
defined $self->{'serialiser'} ? : 0 0 0
defined $self->{'medium'} ? : 0 0 0
defined $self->{'shared_mem_size'} ? : 0 0 0
Condition0%0/2
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_data('PUT', @_) || die('HTTP::Promise::Request'->error); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()}) || (return $self->pass_error('Promise::Me'->error))
l!l
00
MC/DC0%0/1
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_data('PUT', @_) || die('HTTP::Promise::Request'->error); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()}) || (return $self->pass_error('Promise::Me'->error))
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_data('PUT', @_) || die('HTTP::Promise::Request'->error); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()})
Truth table0%0/2
A
A= 'Promise::Me'->new(sub { my($resolve, $reject) = @$_; my $req = $self->_make_request_data('PUT', @_) || die('HTTP::Promise::Request'->error); my $resp = $self->send($req) || (return &$reject($self->error)); return &$resolve($resp); } , {'args', [@_], defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : ()})
Aresult
11
00
876 }) || return( $self->pass_error( Promise::Me->error ) );
877 0 return( $prom );
878 }
879 else
880 {
881 0 ▶ my $req = $self->_make_request_data( PUT => @_ ) ||
Condition0%0/2
$self->_make_request_data('PUT', @_) || (return $self->pass_error('HTTP::Promise::Request'->error))
l!l
00
MC/DC0%0/1
$self->_make_request_data('PUT', @_) || (return $self->pass_error('HTTP::Promise::Request'->error))
$self->_make_request_data('PUT', @_)
Truth table0%0/2
A
A= $self->_make_request_data('PUT', @_)
Aresult
11
00
882 return( $self->pass_error( HTTP::Promise::Request->error ) );
883 0 ▶ my $resp = $self->send( $req ) ||
Condition0%0/2
$self->send($req) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->send($req) || (return $self->pass_error)
$self->send($req)
Truth table0%0/2
A
A= $self->send($req)
Aresult
11
00
884 return( $self->pass_error );
885 0 return( $resp );
886 }
887 }
888  
889 sub request
890 0 ▶{
Subroutine request: not called CC=11 SCAR=48.8
Pod documented
891 0 my $self = shift( @_ );
892 0 my $req = shift( @_ );
893 0 my $opts = $self->_get_args_as_hash( @_ );
894 0 ▶ $opts->{read_size} //= 0;
Condition0%0/2
$opts->{"read_size"} //= 0
l!l
00
MC/DC0%0/1
$opts->{"read_size"} //= 0
$opts->{"read_size"}
Truth table0%0/2
A
A= $opts->{"read_size"}
Aresult
11
00
895 0 ▶ if( $self->use_promise )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_promise) { } 0 0 0
896 {
897 my $prom = Promise::Me->new(sub
898 0 ▶ {
Subroutine __ANON__: not called CC=4 SCAR=30.0
899 0 my( $resolve, $reject ) = @$_;
900 0 ▶ return( $reject->( HTTP::Promise::Exception->new({
Branch: 1 branch
BranchTrueFalseTotal
unless $req 0 0 0
901 code => 500,
902 message => "No request object was provided."
903 }) ) ) if( !$req );
904 0 ▶ $self->use_content_file( $opts->{use_content_file} ) if( exists( $opts->{use_content_file} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"use_content_file"} 0 0 0
905 0 ▶ my $resp = $self->send( $req, $opts ) || return( $reject->( $self->pass_error ) );
Condition0%0/2
$self->send($req, $opts) || (return &$reject($self->pass_error))
l!l
00
MC/DC0%0/1
$self->send($req, $opts) || (return &$reject($self->pass_error))
$self->send($req, $opts)
Truth table0%0/2
A
A= $self->send($req, $opts)
Aresult
11
00
906 0 return( $resolve->( $resp ) );
907 },
908 {
909 ( defined( $self->{serialiser} ) ? ( serialiser => $self->{serialiser} ) : () ),
910 ( defined( $self->{medium} ) ? ( medium => $self->{medium} ) : () ),
911 ( defined( $self->{shared_mem_size} ) ? ( result_shared_mem_size => $self->{shared_mem_size} ) : () ),
912 0 ▶ ( defined( $opts->{promise_debug} ) ? ( debug => $opts->{promise_debug} ) : () ),
Branch: 4 branches
BranchTrueFalseTotal
defined $self->{'serialiser'} ? : 0 0 0
defined $self->{'medium'} ? : 0 0 0
defined $self->{'shared_mem_size'} ? : 0 0 0
defined $opts->{'promise_debug'} ? : 0 0 0
Condition0%0/2
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; return &$reject('HTTP::Promise::Exception'->new({'code', 500, 'message', 'No request object was provided.'})) unless $req; $self->use_content_file($opts->{'use_content_file'}) if exists $opts->{'use_content_file'}; my $resp = $self->send($req, $opts) || (return &$reject($self->pass_error)); return &$resolve($resp); } , {defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : (), defined $opts->{'promise_debug'} ? ('debug', $opts->{'promise_debug'}) : ()}) || (return $self->pass_error('Promise::Me'->error))
l!l
00
MC/DC0%0/1
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; return &$reject('HTTP::Promise::Exception'->new({'code', 500, 'message', 'No request object was provided.'})) unless $req; $self->use_content_file($opts->{'use_content_file'}) if exists $opts->{'use_content_file'}; my $resp = $self->send($req, $opts) || (return &$reject($self->pass_error)); return &$resolve($resp); } , {defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : (), defined $opts->{'promise_debug'} ? ('debug', $opts->{'promise_debug'}) : ()}) || (return $self->pass_error('Promise::Me'->error))
'Promise::Me'->new(sub { my($resolve, $reject) = @$_; return &$reject('HTTP::Promise::Exception'->new({'code', 500, 'message', 'No request object was provided.'})) unless $req; $self->use_content_file($opts->{'use_content_file'}) if exists $opts->{'use_content_file'}; my $resp = $self->send($req, $opts) || (return &$reject($self->pass_error)); return &$resolve($resp); } , {defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : (), defined $opts->{'promise_debug'} ? ('debug', $opts->{'promise_debug'}) : ()})
Truth table0%0/2
A
A= 'Promise::Me'->new(sub { my($resolve, $reject) = @$_; return &$reject('HTTP::Promise::Exception'->new({'code', 500, 'message', 'No request object was provided.'})) unless $req; $self->use_content_file($opts->{'use_content_file'}) if exists $opts->{'use_content_file'}; my $resp = $self->send($req, $opts) || (return &$reject($self->pass_error)); return &$resolve($resp); } , {defined $self->{'serialiser'} ? ('serialiser', $self->{'serialiser'}) : (), defined $self->{'medium'} ? ('medium', $self->{'medium'}) : (), defined $self->{'shared_mem_size'} ? ('result_shared_mem_size', $self->{'shared_mem_size'}) : (), defined $opts->{'promise_debug'} ? ('debug', $opts->{'promise_debug'}) : ()})
Aresult
11
00
913 }) || return( $self->pass_error( Promise::Me->error ) );
914 0 return( $prom );
915 }
916 else
917 {
918 0 ▶ return( $self->error( "No request object was provided." ) ) if( !$req );
Branch: 1 branch
BranchTrueFalseTotal
unless $req 0 0 0
919 0 ▶ $self->use_content_file( $opts->{use_content_file} ) if( exists( $opts->{use_content_file} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"use_content_file"} 0 0 0
920 0 ▶ my $resp = $self->send( $req, $opts ) || return( $self->pass_error );
Condition0%0/2
$self->send($req, $opts) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->send($req, $opts) || (return $self->pass_error)
$self->send($req, $opts)
Truth table0%0/2
A
A= $self->send($req, $opts)
Aresult
11
00
921 0 return( $resp );
922 }
923 }
924  
925 # NOTE: request parameter
926 0 ▶sub requests_redirectable { return( shift->_set_get_array_as_object( 'requests_redirectable', @_ ) ); }
Subroutine requests_redirectable: not called CC=1 SCAR=6.9
Pod documented
927  
928 sub send
929 0 ▶{
Subroutine send: not called CC=158 SCAR=101.3
Pod documented
930 0 my $self = shift( @_ );
931 0 my $req = shift( @_ );
932 0 ▶ return( $self->error( "Request object provided ($req) is not a HTTP::Promise::Request object." ) ) if( !$self->_is_a( $req => 'HTTP::Promise::Request' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($req, "HTTP::Promise::Request") 0 0 0
933 0 my $opts = $self->_get_args_as_hash( @_ );
934 0 ▶ $opts->{expect_threshold} //= $self->expect_threshold // 0;
Condition0%0/4
$opts->{"expect_threshold"} //= $self->expect_threshold // 0
l!l
00
$self->expect_threshold // 0
l!l
00
MC/DC0%0/1
$opts->{"expect_threshold"} //= $self->expect_threshold // 0
$opts->{"expect_threshold"}
Truth table0%0/2
A
A= $opts->{"expect_threshold"}
Aresult
11
00
935 0 ▶ $opts->{total_attempts} //= 0;
Condition0%0/2
$opts->{"total_attempts"} //= 0
l!l
00
MC/DC0%0/1
$opts->{"total_attempts"} //= 0
$opts->{"total_attempts"}
Truth table0%0/2
A
A= $opts->{"total_attempts"}
Aresult
11
00
936 # if( $self->debug >= 4 )
937 # {
938 # my $hcopy = $req->headers->clone;
939 # if( my $auth = $hcopy->authorization )
940 # {
941 # $auth =~ s/\b([A-Za-z]+)\s+(\S{6})\S+/$1 $2…/;
942 # $hcopy->authorization( $auth );
943 # }
944 # my $h = $hcopy->as_string;
945 # my $cl = $req->content_length // 0;
946 # my $preview = $req->start_line . "\n" . $h . "\n<" . $cl . " bytes body omitted>";
947 # }
948  
949 0 my $p = {};
950 # my $timeout = time() + $self->timeout;
951 0 my $timeout = $self->timeout;
952 0 my $uri = $req->uri;
953 0 ▶ if( !$uri->scheme )
Branch: 2 branches
BranchTrueFalseTotal
if (not $uri->scheme) { } 0 0 0
elsif ($uri->scheme ne 'http' and $uri->scheme ne 'https') { } 0 0 0
954 {
955 0 $uri->scheme( 'http' );
956 }
957 ▶ elsif( $uri->scheme ne 'http' && $uri->scheme ne 'https' )
Condition0%0/3
$uri->scheme ne "http" and $uri->scheme ne "https"
!ll&&!rl&&r
000
MC/DC0%0/2
$uri->scheme ne "http" and $uri->scheme ne "https"
$uri->scheme ne "http" $uri->scheme ne "https"
Truth table0%0/3
A and B
A= $uri->scheme ne "http"B= $uri->scheme ne "https"
ABresult
0X0
100
111
958 {
959 0 return( $self->error( "Unsupported scheme: ", $uri->scheme ) );
960 }
961 0 ▶ my $default_port = $uri->scheme eq 'http'
Branch: 1 branch
BranchTrueFalseTotal
$uri->scheme eq 'http' ? : 0 0 0
962 ? 80
963 : 443;
964 0 ▶ if( !$uri->can( 'port' ) || !defined( $uri->port ) || !length( $uri->port ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $uri->can('port') && defined $uri->port && length $uri->port) { } 0 0 0
Condition0%0/6
$uri->can('port') && defined $uri->port && length $uri->port
!ll&&!rl&&r
000
$uri->can("port") and defined $uri->port
!ll&&!rl&&r
000
MC/DC0%0/3
$uri->can('port') && defined $uri->port && length $uri->port
$uri->can("port") defined $uri->port length $uri->port
Truth table0%0/4
A and B && C
A= $uri->can("port")B= defined $uri->portC= length $uri->port
ABCresult
0XX0
10X0
1100
1111
965 {
966 0 $p->{port} = $default_port;
967 }
968 else
969 {
970 0 $p->{port} = $uri->port;
971 }
972 0 ▶ $uri->path( '/' ) if( !length( $uri->path ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $uri->path 0 0 0
973  
974 0 ▶ $p->{host} = $uri->host ||
Condition0%0/2
$uri->host || (return $self->error(qq[No host set for request uri "$uri".]))
l!l
00
MC/DC0%0/1
$uri->host || (return $self->error(qq[No host set for request uri "$uri".]))
$uri->host
Truth table0%0/2
A
A= $uri->host
Aresult
11
00
975 return( $self->error( "No host set for request uri \"$uri\"." ) );
976
977 0 ▶ if( my $local_host = $self->local_host )
Branch: 1 branch
BranchTrueFalseTotal
if (my $local_host = $self->local_host) 0 0 0
978 {
979 0 $p->{local_host} = $local_host;
980 }
981 0 ▶ if( my $local_port = $self->local_port )
Branch: 1 branch
BranchTrueFalseTotal
if (my $local_port = $self->local_port) 0 0 0
982 {
983 0 $p->{local_port} = $local_port;
984 }
985  
986 0 my $proxy = $self->proxy;
987 0 my $no_proxy = $self->no_proxy;
988 0 ▶ if( $proxy && $no_proxy )
Branch: 1 branch
BranchTrueFalseTotal
if ($proxy and $no_proxy) 0 0 0
Condition0%0/3
$proxy and $no_proxy
!ll&&!rl&&r
000
MC/DC0%0/2
$proxy and $no_proxy
$proxy $no_proxy
Truth table0%0/3
A and B
A= $proxyB= $no_proxy
ABresult
0X0
100
111
989 {
990 0 ▶ if( $self->_match_no_proxy( $no_proxy, $p->{host} ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_match_no_proxy($no_proxy, $p->{"host"})) 0 0 0
991 {
992 0 undef( $proxy );
993 }
994 }
995  
996 0 local $SIG{PIPE} = 'IGNORE';
997 0 my $io;
998 0 my $sock = $self->_pool->steal( @$p{qw( host port )} );
999 0 ▶ if( defined( $sock ) && Scalar::Util::openhandle( $sock ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sock and &Scalar::Util::openhandle($sock)) 0 0 0
Condition0%0/3
defined $sock and &Scalar::Util::openhandle($sock)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $sock and &Scalar::Util::openhandle($sock)
defined $sock &Scalar::Util::openhandle($sock)
Truth table0%0/3
A and B
A= defined $sockB= &Scalar::Util::openhandle($sock)
ABresult
0X0
100
111
1000 {
1001 0 ▶ $io = HTTP::Promise::IO->new( $sock, stop_if => $self->stop_if ) ||
Condition0%0/2
'HTTP::Promise::IO'->new($sock, 'stop_if', $self->stop_if) || (return $self->pass_error('HTTP::Promise::IO'->error))
l!l
00
MC/DC0%0/1
'HTTP::Promise::IO'->new($sock, 'stop_if', $self->stop_if) || (return $self->pass_error('HTTP::Promise::IO'->error))
'HTTP::Promise::IO'->new($sock, 'stop_if', $self->stop_if)
Truth table0%0/2
A
A= 'HTTP::Promise::IO'->new($sock, 'stop_if', $self->stop_if)
Aresult
11
00
1002 return( $self->pass_error( HTTP::Promise::IO->error ) );
1003 0 ▶ if( !$io->make_select( write => 0, timeout => 0 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $io->make_select('write', 0, 'timeout', 0)) { } 0 0 0
1004 {
1005 0 close( $sock );
1006 0 undef( $sock );
1007 }
1008 else
1009 {
1010 0 $p->{in_keepalive} = 1;
1011 }
1012 }
1013 0 ▶ if( !$p->{in_keepalive} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($p->{"in_keepalive"}) 0 0 0
1014 {
1015 0 ▶ if( $proxy )
Branch: 1 branch
BranchTrueFalseTotal
if ($proxy) { } 0 0 0
1016 {
1017 # my( undef, $proxy_user, $proxy_pass, $proxy_host, $proxy_port, undef) = $self->_parse_url($proxy);
1018 0 ▶ return( $self->error( "Proxy set '$proxy' (", overload::StrVal( $proxy ), ") is not URI object." ) ) if( !$self->_is_a( $proxy => 'URI' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($proxy, "URI") 0 0 0
1019 0 my $proxy_auth = $proxy->userinfo;
1020 0 my( $proxy_user, $proxy_pass ) = split( /:/, $proxy_auth, 2 );
1021 0 my $proxy_authorization;
1022 0 ▶ if( defined( $proxy_user ) && length( $proxy_user ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $proxy_user and length $proxy_user) 0 0 0
Condition0%0/3
defined $proxy_user and length $proxy_user
!ll&&!rl&&r
000
MC/DC0%0/2
defined $proxy_user and length $proxy_user
defined $proxy_user length $proxy_user
Truth table0%0/3
A and B
A= defined $proxy_userB= length $proxy_user
ABresult
0X0
100
111
1023 {
1024 0 ▶ $self->_load_class( 'URI::Escape::XS' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("URI::Escape::XS") or return $self->pass_error 0 0 0
1025 0 $p->{proxy_user} = URI::Escape::XS::uri_unescape( $proxy_user );
1026 0 $p->{proxy_pass} = URI::Escape::XS::uri_unescape( $proxy_pass );
1027 0 ▶ $self->_load_class( 'Crypt::Misc' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Crypt::Misc") or return $self->pass_error 0 0 0
1028 0 $proxy_authorization = 'Basic ' . Crypt::Misc::encode_b64( join( ':', @$p{qw( proxy_user proxy_pass )} ), '' );
1029 }
1030 0 local $HTTP::Promise::IO::DEBUG = $self->debug; # REMOVE ME
1031 0 ▶ if( $uri->scheme eq 'http' )
Branch: 1 branch
BranchTrueFalseTotal
if ($uri->scheme eq 'http') { } 0 0 0
1032 {
1033 $io = HTTP::Promise::IO->connect(
1034 host => $proxy->host,
1035 port => $proxy->port,
1036 stop_if => $self->stop_if,
1037 timeout => $timeout,
1038 debug => $self->debug,
1039 ( defined( $p->{local_host} ) ? ( local_host => $p->{local_host} ) : () ),
1040 0 ▶ ( defined( $p->{local_port} ) ? ( local_port => $p->{local_port} ) : () ),
Branch: 2 branches
BranchTrueFalseTotal
defined $p->{'local_host'} ? : 0 0 0
defined $p->{'local_port'} ? : 0 0 0
Condition0%0/2
'HTTP::Promise::IO'->connect('host', $proxy->host, 'port', $proxy->port, 'stop_if', $self->stop_if, 'timeout', $timeout, 'debug', $self->debug, defined $p->{'local_host'} ? ('local_host', $p->{'local_host'}) : (), defined $p->{'local_port'} ? ('local_port', $p->{'local_port'}) : ()) || (return $self->pass_error('HTTP::Promise::IO'->error))
l!l
00
MC/DC0%0/1
'HTTP::Promise::IO'->connect('host', $proxy->host, 'port', $proxy->port, 'stop_if', $self->stop_if, 'timeout', $timeout, 'debug', $self->debug, defined $p->{'local_host'} ? ('local_host', $p->{'local_host'}) : (), defined $p->{'local_port'} ? ('local_port', $p->{'local_port'}) : ()) || (return $self->pass_error('HTTP::Promise::IO'->error))
'HTTP::Promise::IO'->connect('host', $proxy->host, 'port', $proxy->port, 'stop_if', $self->stop_if, 'timeout', $timeout, 'debug', $self->debug, defined $p->{'local_host'} ? ('local_host', $p->{'local_host'}) : (), defined $p->{'local_port'} ? ('local_port', $p->{'local_port'}) : ())
Truth table0%0/2
A
A= 'HTTP::Promise::IO'->connect('host', $proxy->host, 'port', $proxy->port, 'stop_if', $self->stop_if, 'timeout', $timeout, 'debug', $self->debug, defined $p->{'local_host'} ? ('local_host', $p->{'local_host'}) : (), defined $p->{'local_port'} ? ('local_port', $p->{'local_port'}) : ())
Aresult
11
00
1041 ) || return( $self->pass_error( HTTP::Promise::IO->error ) );
1042 0 ▶ if( defined( $proxy_authorization ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $proxy_authorization) 0 0 0
1043 {
1044 0 $self->proxy_authorization( $proxy_authorization );
1045 }
1046 }
1047 else
1048 {
1049 $io = HTTP::Promise::IO->connect_ssl_over_proxy(
1050 proxy_host => $proxy->host,
1051 proxy_port => $proxy->port,
1052 host => $p->{host},
1053 port => $p->{port},
1054 stop_if => $self->stop_if,
1055 timeout => $timeout,
1056 proxy_authorization => $proxy_authorization,
1057 debug => $self->debug,
1058 ( defined( $p->{local_host} ) ? ( local_host => $p->{local_host} ) : () ),
1059 0 ▶ ( defined( $p->{local_port} ) ? ( local_port => $p->{local_port} ) : () ),
Branch: 2 branches
BranchTrueFalseTotal
defined $p->{'local_host'} ? : 0 0 0
defined $p->{'local_port'} ? : 0 0 0
Condition0%0/2
'HTTP::Promise::IO'->connect_ssl_over_proxy('proxy_host', $proxy->host, 'proxy_port', $proxy->port, 'host', $p->{'host'}, 'port', $p->{'port'}, 'stop_if', $self->stop_if, 'timeout', $timeout, 'proxy_authorization', $proxy_authorization, 'debug', $self->debug, defined $p->{'local_host'} ? ('local_host', $p->{'local_host'}) : (), defined $p->{'local_port'} ? ('local_port', $p->{'local_port'}) : ()) || (return $self->pass_error('HTTP::Promise::IO'->error))
l!l
00
MC/DC0%0/1
'HTTP::Promise::IO'->connect_ssl_over_proxy('proxy_host', $proxy->host, 'proxy_port', $proxy->port, 'host', $p->{'host'}, 'port', $p->{'port'}, 'stop_if', $self->stop_if, 'timeout', $timeout, 'proxy_authorization', $proxy_authorization, 'debug', $self->debug, defined $p->{'local_host'} ? ('local_host', $p->{'local_host'}) : (), defined $p->{'local_port'} ? ('local_port', $p->{'local_port'}) : ()) || (return $self->pass_error('HTTP::Promise::IO'->error))
'HTTP::Promise::IO'->connect_ssl_over_proxy('proxy_host', $proxy->host, 'proxy_port', $proxy->port, 'host', $p->{'host'}, 'port', $p->{'port'}, 'stop_if', $self->stop_if, 'timeout', $timeout, 'proxy_authorization', $proxy_authorization, 'debug', $self->debug, defined $p->{'local_host'} ? ('local_host', $p->{'local_host'}) : (), defined $p->{'local_port'} ? ('local_port', $p->{'local_port'}) : ())
Truth table0%0/2
A
A= 'HTTP::Promise::IO'->connect_ssl_over_proxy('proxy_host', $proxy->host, 'proxy_port', $proxy->port, 'host', $p->{'host'}, 'port', $p->{'port'}, 'stop_if', $self->stop_if, 'timeout', $timeout, 'proxy_authorization', $proxy_authorization, 'debug', $self->debug, defined $p->{'local_host'} ? ('local_host', $p->{'local_host'}) : (), defined $p->{'local_port'} ? ('local_port', $p->{'local_port'}) : ())
Aresult
11
00
1060 ) || return( $self->pass_error( HTTP::Promise::IO->error ) );
1061 }
1062 }
1063 else
1064 {
1065 0 local $HTTP::Promise::IO::DEBUG = $self->debug; # REMOVE ME
1066 0 ▶ if( $uri->scheme eq 'http' )
Branch: 1 branch
BranchTrueFalseTotal
if ($uri->scheme eq 'http') { } 0 0 0
1067 {
1068 $io = HTTP::Promise::IO->connect(
1069 host => $uri->host,
1070 port => $uri->port,
1071 stop_if => $self->stop_if,
1072 timeout => $timeout,
1073 debug => $self->debug,
1074 ( defined( $p->{local_host} ) ? ( local_host => $p->{local_host} ) : () ),
1075 0 ▶ ( defined( $p->{local_port} ) ? ( local_port => $p->{local_port} ) : () ),
Branch: 2 branches
BranchTrueFalseTotal
defined $p->{'local_host'} ? : 0 0 0
defined $p->{'local_port'} ? : 0 0 0
Condition0%0/2
'HTTP::Promise::IO'->connect('host', $uri->host, 'port', $uri->port, 'stop_if', $self->stop_if, 'timeout', $timeout, 'debug', $self->debug, defined $p->{'local_host'} ? ('local_host', $p->{'local_host'}) : (), defined $p->{'local_port'} ? ('local_port', $p->{'local_port'}) : ()) || (return $self->pass_error('HTTP::Promise::IO'->error))
l!l
00
MC/DC0%0/1
'HTTP::Promise::IO'->connect('host', $uri->host, 'port', $uri->port, 'stop_if', $self->stop_if, 'timeout', $timeout, 'debug', $self->debug, defined $p->{'local_host'} ? ('local_host', $p->{'local_host'}) : (), defined $p->{'local_port'} ? ('local_port', $p->{'local_port'}) : ()) || (return $self->pass_error('HTTP::Promise::IO'->error))
'HTTP::Promise::IO'->connect('host', $uri->host, 'port', $uri->port, 'stop_if', $self->stop_if, 'timeout', $timeout, 'debug', $self->debug, defined $p->{'local_host'} ? ('local_host', $p->{'local_host'}) : (), defined $p->{'local_port'} ? ('local_port', $p->{'local_port'}) : ())
Truth table0%0/2
A
A= 'HTTP::Promise::IO'->connect('host', $uri->host, 'port', $uri->port, 'stop_if', $self->stop_if, 'timeout', $timeout, 'debug', $self->debug, defined $p->{'local_host'} ? ('local_host', $p->{'local_host'}) : (), defined $p->{'local_port'} ? ('local_port', $p->{'local_port'}) : ())
Aresult
11
00
1076 ) || return( $self->pass_error( HTTP::Promise::IO->error ) );
1077 }
1078 else
1079 {
1080 0 my $ssl_opts = $self->ssl_opts;
1081 $io = HTTP::Promise::IO->connect_ssl(
1082 host => $uri->host,
1083 port => $uri->port,
1084 stop_if => $self->stop_if,
1085 timeout => $timeout,
1086 debug => $self->debug,
1087 ( defined( $p->{local_host} ) ? ( local_host => $p->{local_host} ) : () ),
1088 0 ▶ ( defined( $p->{local_port} ) ? ( local_port => $p->{local_port} ) : () ),
Branch: 3 branches
BranchTrueFalseTotal
defined $p->{'local_host'} ? : 0 0 0
defined $p->{'local_port'} ? : 0 0 0
defined $ssl_opts && scalar keys %$ssl_opts ? : 0 0 0
Condition0%0/4
'HTTP::Promise::IO'->connect_ssl('host', $uri->host, 'port', $uri->port, 'stop_if', $self->stop_if, 'timeout', $timeout, 'debug', $self->debug, defined $p->{'local_host'} ? ('local_host', $p->{'local_host'}) : (), defined $p->{'local_port'} ? ('local_port', $p->{'local_port'}) : (), defined $ssl_opts && scalar keys %$ssl_opts ? ('ssl_opts', $ssl_opts) : ()) || (return $self->pass_error('HTTP::Promise::IO'->error))
l!l
00
defined $ssl_opts and scalar keys %$ssl_opts
!ll
00
MC/DC0%0/1
'HTTP::Promise::IO'->connect_ssl('host', $uri->host, 'port', $uri->port, 'stop_if', $self->stop_if, 'timeout', $timeout, 'debug', $self->debug, defined $p->{'local_host'} ? ('local_host', $p->{'local_host'}) : (), defined $p->{'local_port'} ? ('local_port', $p->{'local_port'}) : (), defined $ssl_opts && scalar keys %$ssl_opts ? ('ssl_opts', $ssl_opts) : ()) || (return $self->pass_error('HTTP::Promise::IO'->error))
'HTTP::Promise::IO'->connect_ssl('host', $uri->host, 'port', $uri->port, 'stop_if', $self->stop_if, 'timeout', $timeout, 'debug', $self->debug, defined $p->{'local_host'} ? ('local_host', $p->{'local_host'}) : (), defined $p->{'local_port'} ? ('local_port', $p->{'local_port'}) : (), defined $ssl_opts && scalar keys %$ssl_opts ? ('ssl_opts', $ssl_opts) : ())
MC/DC0%0/1
defined $ssl_opts and scalar keys %$ssl_opts
defined $ssl_opts
Truth table0%0/2
A
A= 'HTTP::Promise::IO'->connect_ssl('host', $uri->host, 'port', $uri->port, 'stop_if', $self->stop_if, 'timeout', $timeout, 'debug', $self->debug, defined $p->{'local_host'} ? ('local_host', $p->{'local_host'}) : (), defined $p->{'local_port'} ? ('local_port', $p->{'local_port'}) : (), defined $ssl_opts && scalar keys %$ssl_opts ? ('ssl_opts', $ssl_opts) : ())
Aresult
11
00
Truth table0%0/2
A
A= defined $ssl_opts
Aresult
00
11
1089 ( ( defined( $ssl_opts ) && scalar( keys( %$ssl_opts ) ) ) ? ( ssl_opts => $ssl_opts ) : () ),
1090 ) || return( $self->pass_error( HTTP::Promise::IO->error ) );
1091 }
1092 }
1093 # return( $self->pass_error ) unless( $io );
1094 }
1095  
1096 0 my $total_bytes_sent = 0;
1097 0 my $total_bytes_read = 0;
1098  
1099 my $send_body = sub
1100 0 ▶ {
Subroutine __ANON__: not called CC=4 SCAR=30.0
1101 0 my $entity = shift( @_ );
1102 0 my $body = $entity->body;
1103 0 my $body_len = $body->length;
1104 0 my $ct_len = $req->headers->content_length;
1105 0 ▶ if( $body_len != $ct_len )
Branch: 1 branch
BranchTrueFalseTotal
if ($body_len != $ct_len) 0 0 0
1106 {
1107 0 ▶ warn( "Content-Length set (${ct_len}) does not match the actual body size (${body_len})\n" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
1108 }
1109
1110 0 my $sock = $io->filehandle;
1111 0 my $bytes_sent = 0;
1112 0 ▶ $entity->print_body( $io ) || return( $self->pass_error( $entity->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$entity->print_body($io) or return $self->pass_error($entity->error) 0 0 0
1113 # NOTE: Hmmmm, really not great, but otherwise I would need to change a lot of code
1114 0 $bytes_sent = $body->length;
1115 0 return( $bytes_sent );
1116 0 };
1117  
1118 # write request
1119 0 my $method = $req->method;
1120 0 my $connection_header = $self->connection_header;
1121 # If no connection_header value was provided, let's guess it based on the protocol used
1122 0 ▶ unless( $connection_header )
Branch: 1 branch
BranchTrueFalseTotal
unless ($connection_header) 0 0 0
1123 {
1124 0 ▶ if( uc( $method ) eq 'HEAD' )
Branch: 2 branches
BranchTrueFalseTotal
if (uc $method eq 'HEAD') { } 0 0 0
elsif ($req->version and $req->version > 1.0) { } 0 0 0
1125 {
1126 0 $connection_header = 'close';
1127 }
1128 ▶ elsif( $req->version && $req->version > 1.0 )
Condition0%0/3
$req->version and $req->version > 1
!ll&&!rl&&r
000
MC/DC0%0/2
$req->version and $req->version > 1
$req->version $req->version > 1
Truth table0%0/3
A and B
A= $req->versionB= $req->version > 1
ABresult
0X0
100
111
1129 {
1130 0 $connection_header = 'keep-alive';
1131 }
1132 else
1133 {
1134 0 $connection_header = 'close';
1135 }
1136 }
1137
1138 0 my $cookie_jar = $self->cookie_jar;
1139 {
1140 0 my $headers = $req->headers;
1141 # Add headers that were provided as parameters
1142 0 my $in_headers = $opts->{headers};
1143 0 ▶ if( $self->_is_array( $in_headers ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_array($in_headers)) 0 0 0
1144 {
1145 0 ▶ for( my $i = 0; $i < @$in_headers; $i += 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$in_headers) 0 0 0
1146 {
1147 0 my $name = $in_headers->[$i];
1148 0 ▶ if( lc( $name ) eq 'connection' )
Branch: 1 branch
BranchTrueFalseTotal
if (lc $name eq 'connection') { } 0 0 0
1149 {
1150 0 $connection_header = $in_headers->[$i + 1];
1151 }
1152 else
1153 {
1154 0 $headers->push_header( $name => $in_headers->[$i + 1] );
1155 }
1156 }
1157 }
1158 0 $headers->header( Connection => $connection_header );
1159
1160 0 ▶ if( my $pa = $self->proxy_authorization )
Branch: 1 branch
BranchTrueFalseTotal
if (my $pa = $self->proxy_authorization) 0 0 0
1161 {
1162 0 $headers->header( 'Proxy-Authorization' => $pa );
1163 }
1164 0 my $userinfo = $uri->userinfo;
1165 0 ▶ if( defined( $userinfo ) && length( $userinfo ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $userinfo and length $userinfo) 0 0 0
Condition0%0/3
defined $userinfo and length $userinfo
!ll&&!rl&&r
000
MC/DC0%0/2
defined $userinfo and length $userinfo
defined $userinfo length $userinfo
Truth table0%0/3
A and B
A= defined $userinfoB= length $userinfo
ABresult
0X0
100
111
1166 {
1167 0 my( $username, $password ) = split( /:/, $userinfo, 2 );
1168 0 ▶ $self->_load_class( 'URI::Escape' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("URI::Escape") or return $self->pass_error 0 0 0
1169 0 my $unescape_username = URI::Escape::uri_unescape( $username );
1170 0 my $unescape_password = URI::Escape::uri_unescape( $password );
1171 0 ▶ $self->_load_class( 'Crypt::Misc' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Crypt::Misc") or return $self->pass_error 0 0 0
1172 0 my $authorization = 'Basic ' . Crypt::Misc::encode_b64( "${unescape_username}:${unescape_password}" );
1173 0 $headers->header( Authorization => 'Basic ' . $authorization );
1174 0 $uri->userinfo( undef );
1175 }
1176  
1177 # set Cookie header
1178 0 ▶ if( defined( $cookie_jar ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cookie_jar) 0 0 0
1179 {
1180 0 ▶ if( $self->_can( $cookie_jar => 'add_request_header' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_can($cookie_jar, 'add_request_header')) { } 0 0 0
1181 {
1182 0 ▶ $cookie_jar->add_request_header( $req ) ||
Branch: 1 branch
BranchTrueFalseTotal
$cookie_jar->add_request_header($req) or return $self->pass_error($cookie_jar->error) 0 0 0
1183 return( $self->pass_error( $cookie_jar->error ) );
1184 }
1185 else
1186 {
1187 0 warn( "Cookie Jar object ", $self->_str_val( $cookie_jar ), " does not support the method 'add_request_header'." );
1188 }
1189 }
1190  
1191 0 my $body = $req->entity->body;
1192 0 ▶ if( defined( $body ) && $body )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $body and $body) 0 0 0
Condition0%0/3
defined $body and $body
!ll&&!rl&&r
000
MC/DC0%0/2
defined $body and $body
defined $body $body
Truth table0%0/3
A and B
A= defined $bodyB= $body
ABresult
0X0
100
111
1193 {
1194 0 ▶ if( $body->isa( 'HTTP::Promise::Body::Form' ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($body->isa("HTTP::Promise::Body::Form") and !$headers->exists("Content-Type") || $headers->content_type->is_empty) 0 0 0
Condition0%0/6
$body->isa("HTTP::Promise::Body::Form") and !$headers->exists("Content-Type") || $headers->content_type->is_empty
!ll&&!rl&&r
000
not $headers->exists("Content-Type") or $headers->content_type->is_empty
l!l&&r!l&&!r
000
MC/DC0%0/3
$body->isa("HTTP::Promise::Body::Form") and !$headers->exists("Content-Type") || $headers->content_type->is_empty
$body->isa("HTTP::Promise::Body::Form") not $headers->exists("Content-Type") $headers->content_type->is_empty
Truth table0%0/4
A and not(B) or C
A= $body->isa("HTTP::Promise::Body::Form")B= not $headers->exists("Content-Type")C= $headers->content_type->is_empty
ABCresult
0XX0
1000
11X1
1011
1195 ( !$headers->exists( 'Content-Type' ) || $headers->content_type->is_empty ) )
1196 {
1197 0 $headers->header( 'Content-Type' => 'application/x-www-form-urlencoded' );
1198 }
1199 0 ▶ if( !$headers->exists( 'Content-Length' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($headers->exists("Content-Length")) 0 0 0
1200 {
1201 0 my $content_length = $body->length;
1202 0 $headers->header( 'Content-Length' => "$content_length" );
1203 }
1204 }
1205  
1206 # finally, set Host header
1207 0 ▶ unless( $headers->host )
Branch: 1 branch
BranchTrueFalseTotal
unless ($headers->host) 0 0 0
1208 {
1209 0 ▶ my $request_target = ( $uri->port == $default_port ) ? $uri->host : $uri->host_port;
Branch: 1 branch
BranchTrueFalseTotal
$uri->port == $default_port ? : 0 0 0
1210 0 $headers->header( Host => $request_target );
1211 }
1212
1213 0 ▶ my $expect_threshold = $opts->{expect_threshold} // $self->expect_threshold;
Condition0%0/3
$opts->{"expect_threshold"} // $self->expect_threshold
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"expect_threshold"} // $self->expect_threshold
$opts->{"expect_threshold"} $self->expect_threshold
Truth table0%0/3
A // B
A= $opts->{"expect_threshold"}B= $self->expect_threshold
ABresult
1X1
011
000
1214 0 ▶ if( defined( $expect_threshold ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $expect_threshold) 0 0 0
1215 {
1216 0 ▶ if( $self->_is_integer( $expect_threshold ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_integer($expect_threshold)) { } 0 0 0
1217 {
1218 0 $expect_threshold += 0;
1219 }
1220 else
1221 {
1222 0 undef( $expect_threshold );
1223 }
1224 }
1225
1226 0 ▶ if( $req->version &&
Branch: 1 branch
BranchTrueFalseTotal
if ($req->version and $req->version > 1 and defined $expect_threshold and $expect_threshold > 0 and defined $body and $body->length > $expect_threshold) 0 0 0
Condition0%0/15
$req->version and $req->version > 1 and defined $expect_threshold and $expect_threshold > 0 and defined $body and $body->length > $expect_threshold
!ll&&!rl&&r
000
$req->version and $req->version > 1 and defined $expect_threshold and $expect_threshold > 0 and defined $body
!ll&&!rl&&r
000
$req->version and $req->version > 1 and defined $expect_threshold and $expect_threshold > 0
!ll&&!rl&&r
000
$req->version and $req->version > 1 and defined $expect_threshold
!ll&&!rl&&r
000
$req->version and $req->version > 1
!ll&&!rl&&r
000
MC/DC0%0/6
$req->version and $req->version > 1 and defined $expect_threshold and $expect_threshold > 0 and defined $body and $body->length > $expect_threshold
$req->version $req->version > 1 defined $expect_threshold $expect_threshold > 0 defined $body $body->length > $expect_threshold
Truth table0%0/7
A and B and C and D and E and F
A= $req->versionB= $req->version > 1C= defined $expect_thresholdD= $expect_threshold > 0E= defined $bodyF= $body->length > $expect_threshold
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
1227 $req->version > 1.0 &&
1228 defined( $expect_threshold ) &&
1229 $expect_threshold > 0 &&
1230 defined( $body ) &&
1231 $body->length > $expect_threshold )
1232 {
1233 0 $headers->expect( '100-Continue' );
1234 }
1235
1236 0 my $request = $req->start_line . $CRLF . $req->headers->as_string;
1237 0 $request .= $CRLF;
1238 0 my $bytes = $io->write_all( $request, $timeout );
1239 0 ▶ if( !defined( $bytes ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $bytes) { } 0 0 0
elsif (not $bytes) { } 0 0 0
1240 {
1241 0 return( $self->pass_error( $io->error ) );
1242 }
1243 # Could not transmit the headers
1244 elsif( !$bytes )
1245 {
1246 0 return( $self->error({ code => 500, message => "Zero byte could actually be sent to the socket '", $io->filehandle, "'." }) );
1247 }
1248 0 $total_bytes_sent = $bytes;
1249  
1250 # If this is not an Expect query, we send the body now
1251 # otherwise if this is an Expect type of query, we would read the response header
1252 # and send the body
1253 0 ▶ if( !$headers->expect && defined( $body ) && $body )
Branch: 1 branch
BranchTrueFalseTotal
if (not $headers->expect and defined $body and $body) 0 0 0
Condition0%0/6
not $headers->expect and defined $body and $body
!ll&&!rl&&r
000
not $headers->expect and defined $body
!ll&&!rl&&r
000
MC/DC0%0/3
not $headers->expect and defined $body and $body
not $headers->expect defined $body $body
Truth table0%0/4
not(A) and B and C
A= not $headers->expectB= defined $bodyC= $body
ABCresult
0XX0
10X0
1100
1111
1254 {
1255 0 my $bytes = $send_body->( $req->entity );
1256 0 ▶ return( $self->pass_error ) if( !defined( $bytes ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes 0 0 0
1257 0 $total_bytes_sent += $bytes;
1258 }
1259 }
1260
1261 # read response
1262 0 my $buff = '';
1263 0 my $parser = HTTP::Promise::Parser->new;
1264 0 my $bufsize = $self->buffer_size;
1265 0 $io->max_read_buffer( $bufsize );
1266 0 $io->debug( $self->debug );
1267
1268 # Maximum headers size is not oficial, but we definitely need to set some limit.
1269 # <https://security.stackexchange.com/questions/110565/large-over-sizesd-http-header-lengths-and-security-implications>
1270 0 my $max = $self->max_headers_size;
1271 0 my( $n, $def, $headers );
1272 0 $n = -1;
1273 0 LOOP: while(1)
1274 {
1275 0 $n = $io->read( $buff, 2048, length( $buff ) );
1276 0 ▶ if( !defined( $n ) || $n == 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $n or $n == 0) 0 0 0
Condition0%0/3
not defined $n or $n == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $n or $n == 0
not defined $n $n == 0
Truth table0%0/3
not(A) or B
A= not defined $nB= $n == 0
ABresult
1X1
011
000
1277 {
1278 0 ▶ my $code = defined( $n ) ? '' : $io->error->code;
Branch: 1 branch
BranchTrueFalseTotal
defined $n ? : 0 0 0
1279 0 ▶ if( $p->{in_keepalive} &&
Branch: 3 branches
BranchTrueFalseTotal
if ($p->{'in_keepalive'} and (length $buff // 0) == 0 and not $opts->{'total_attempts'} and defined $n || $code == 104 || $HTTP::Promise::IS_WIN32 && $code == 103) { } 0 0 0
elsif (not length $buff) { } 0 0 0
elsif (not defined $n) { } 0 0 0
Condition0%0/20
$p->{"in_keepalive"} and (length $buff // 0) == 0 and not $opts->{"total_attempts"} and defined $n || $code == 104 || $HTTP::Promise::IS_WIN32 && $code == 103
!ll&&!rl&&r
000
$p->{"in_keepalive"} and (length $buff // 0) == 0 and not $opts->{"total_attempts"}
!ll&&!rl&&r
000
$p->{"in_keepalive"} and (length $buff // 0) == 0
!ll&&!rl&&r
000
length $buff // 0
l!l
00
defined $n or $code == 104 or $HTTP::Promise::IS_WIN32 and $code == 103
l!l&&r!l&&!r
000
defined $n or $code == 104
l!l&&r!l&&!r
000
$HTTP::Promise::IS_WIN32 and $code == 103
!ll&&!rl&&r
000
MC/DC0%0/7
$p->{"in_keepalive"} and (length $buff // 0) == 0 and not $opts->{"total_attempts"} and defined $n || $code == 104 || $HTTP::Promise::IS_WIN32 && $code == 103
$p->{"in_keepalive"} length $buff not $opts->{"total_attempts"} defined $n $code == 104 $HTTP::Promise::IS_WIN32 $code == 103
Truth table0%0/8
A and B and not(C) and D or E or F and G
A= $p->{"in_keepalive"}B= length $buffC= not $opts->{"total_attempts"}D= defined $nE= $code == 104F= $HTTP::Promise::IS_WIN32G= $code == 103
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
111000X0
11100100
1111XXX1
11101XX1
11100111
1280 ( length( $buff ) // 0 ) == 0 &&
1281 !$opts->{total_attempts} &&
1282 ( defined( $n ) || $code == ECONNRESET || ( $IS_WIN32 && $code == ECONNABORTED ) ) )
1283 {
1284 # the server closed the connection (maybe because of keep-alive timeout)
1285 0 $opts->{total_attempts}++;
1286 0 return( $self->send( $req, %$opts ) );
1287 }
1288 elsif( !length( $buff ) )
1289 {
1290 0 return( $self->error({ code => HTTP_BAD_REQUEST, message => "Unexpected EOF while reading response from socket '", $io->filehandle, "'." }) );
1291 }
1292 elsif( !defined( $n ) )
1293 {
1294 0 return( $self->pass_error( $io->error ) );
1295 }
1296 else
1297 {
1298 0 return( $self->error({ code => HTTP_BAD_REQUEST, message => "No headers data could be retrieved in the first " . length( $buff ) . " bytes of data read." }) );
1299 }
1300 }
1301
1302 0 $def = $parser->parse_response_headers( \$buff );
1303 0 ▶ if( !defined( $def ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $def) { } 0 0 0
1304 {
1305 # Is it an error 425 Too Early, it means we need more data.
1306 0 ▶ if( $parser->error->code == HTTP_TOO_EARLY )
Branch: 2 branches
BranchTrueFalseTotal
if ($parser->error->code == 425) { } 0 0 0
elsif ($parser->error->code == 400 and length $buff > $max) { } 0 0 0
1307 {
1308 0 next LOOP;
1309 }
1310 # 400 Bad request
1311 ▶ elsif( $parser->error->code == HTTP_BAD_REQUEST && length( $buff ) > $max )
Condition0%0/3
$parser->error->code == 400 and length $buff > $max
!ll&&!rl&&r
000
MC/DC0%0/2
$parser->error->code == 400 and length $buff > $max
$parser->error->code == 400 length $buff > $max
Truth table0%0/3
A and B
A= $parser->error->code == 400B= length $buff > $max
ABresult
0X0
100
111
1312 {
1313 0 return( $self->error({ code => HTTP_BAD_REQUEST, message => "Unable to find the response headers, within the first ${max} bytes of data. Do you need to increase the value for max_headers_size() ?" }) );
1314 }
1315 # For other errors, we stop and pass the error received
1316 0 return( $self->pass_error );
1317 }
1318 else
1319 {
1320 $headers = $def->{headers} ||
1321 0 ▶ return( $self->error( "No headers object set by \$parser->parse_headers_xs() !" ) );
Condition0%0/2
$def->{'headers'} || (return $self->error('No headers object set by $parser->parse_headers_xs() !'))
l!l
00
MC/DC0%0/1
$def->{'headers'} || (return $self->error('No headers object set by $parser->parse_headers_xs() !'))
$def->{'headers'}
Truth table0%0/2
A
A= $def->{'headers'}
Aresult
11
00
1322 0 ▶ return( $self->error( "\$parser->parse_headers_xs() did not return the headers length as an integer ($def->{length})" ) ) if( !$self->_is_integer( $def->{length} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_integer($def->{"length"}) 0 0 0
1323 0 ▶ return( $self->error( "Headers length returned by \$parser->parse_headers_xs() ($def->{length}) is higher than our buffer size (", length( $buff ), ") !" ) ) if( $def->{length} > length( $buff ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"length"} > length $buff 0 0 0
1324 # succeeded
1325 0 substr( $buff, 0, $def->{length}, '' );
1326 0 $total_bytes_read += $def->{length};
1327 0 ▶ $io->unread( $buff ) if( length( $buff ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $buff 0 0 0
1328 # We need to consume the blank line separating the headers and the body, so it does
1329 # not become part of the body, and because it does not belong anywhere
1330 0 my $trash = $io->read_until_in_memory( qr/${CRLF}/, include => 1 );
1331 0 ▶ return( $self->pass_error( $io->error ) ) if( !defined( $trash ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $trash 0 0 0
1332 0 ▶ if( $req->headers->exists( 'Expect' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($req->headers->exists("Expect")) 0 0 0
1333 {
1334 # If we initially sent an Expect request, i.e. without a body, we just got
1335 # The green light to proceed, so we remove the Expect: 100-Continue header and re-submit.
1336 # If we did not have that request header, we just read on as this is the final, albeit weird, response
1337 0 ▶ if( $def->{code} == HTTP_CONTINUE )
Branch: 2 branches
BranchTrueFalseTotal
if ($def->{'code'} == 100) { } 0 0 0
elsif ($def->{'code'} == 417) { } 0 0 0
1338 {
1339 # Read on to get the actual server response headers
1340 0 my $bytes = $send_body->( $req->entity );
1341 0 ▶ return( $self->pass_error ) if( !defined( $bytes ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes 0 0 0
1342 0 $total_bytes_sent += $bytes;
1343 # moving on to read the full response headers
1344 # Something like this:
1345 # HTTP/1.1 100 Continue
1346 #
1347 # HTTP/1.1 200 OK
1348 # Content-Type: text/plain
1349 # Content-Length: 15
1350 # Host: example.com
1351 # User-Agent: hoge
1352 #
1353 0 next LOOP;
1354 }
1355 # If this is a HTTP/1.0 protocol (but not limited to), this just means the server did not support
1356 # the Expect: 100-Continue header, so we just remove it and re-submit.
1357 elsif( $def->{code} == HTTP_EXPECTATION_FAILED )
1358 {
1359 0 $req->headers->remove( 'Expect' );
1360 # Disable the Expect feature
1361 0 $opts->{expect_threshold} = 0;
1362 0 return( $self->send( $req, $opts ) );
1363 }
1364 }
1365 0 last LOOP;
1366 }
1367 }
1368  
1369 0 ▶ my $ent = HTTP::Promise::Entity->new(
Branch: 1 branch
BranchTrueFalseTotal
$headers->exists('Content-Encoding') && !$headers->content_encoding->is_empty ? : 0 0 0
Condition0%0/3
$headers->exists("Content-Encoding") and not $headers->content_encoding->is_empty
!ll&&!rl&&r
000
MC/DC0%0/2
$headers->exists("Content-Encoding") and not $headers->content_encoding->is_empty
$headers->exists("Content-Encoding") not $headers->content_encoding->is_empty
Truth table0%0/3
A and not(B)
A= $headers->exists("Content-Encoding")B= not $headers->content_encoding->is_empty
ABresult
0X0
100
111
1370 headers => $headers,
1371 ext_vary => $self->ext_vary,
1372 debug => $self->debug,
1373 ( ( $headers->exists( 'Content-Encoding' ) && !$headers->content_encoding->is_empty ) ? ( is_encoded => 1 ) : () ),
1374 );
1375 0 ▶ $self->_load_class( 'HTTP::Promise::Response' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Response") or return $self->pass_error 0 0 0
1376 my $resp = HTTP::Promise::Response->new( @$def{qw( code status headers )}, {
1377 protocol => $def->{protocol},
1378 version => $def->{version},
1379 0 ▶ uri => $uri,
Condition0%0/2
'HTTP::Promise::Response'->new(@$def{'code', 'status', 'headers'}, {'protocol', $def->{'protocol'}, 'version', $def->{'version'}, 'uri', $uri, 'debug', $self->debug}) || (return $self->pass_error('HTTP::Promise::Response'->error))
l!l
00
MC/DC0%0/1
'HTTP::Promise::Response'->new(@$def{'code', 'status', 'headers'}, {'protocol', $def->{'protocol'}, 'version', $def->{'version'}, 'uri', $uri, 'debug', $self->debug}) || (return $self->pass_error('HTTP::Promise::Response'->error))
'HTTP::Promise::Response'->new(@$def{'code', 'status', 'headers'}, {'protocol', $def->{'protocol'}, 'version', $def->{'version'}, 'uri', $uri, 'debug', $self->debug})
Truth table0%0/2
A
A= 'HTTP::Promise::Response'->new(@$def{'code', 'status', 'headers'}, {'protocol', $def->{'protocol'}, 'version', $def->{'version'}, 'uri', $uri, 'debug', $self->debug})
Aresult
11
00
1380 debug => $self->debug,
1381 } ) || return( $self->pass_error( HTTP::Promise::Response->error ) );
1382 # Mutual assignment for convenience
1383 0 $resp->entity( $ent );
1384 0 $ent->http_message( $resp );
1385 0 $resp->request( $req );
1386 0 my $body;
1387
1388 0 my $max_redirect = 0;
1389 0 my $do_redirect = undef;
1390 0 ▶ if( $headers->exists( 'Location' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($headers->exists("Location")) 0 0 0
1391 {
1392 $max_redirect = ( defined( $opts->{max_redirect} ) && $opts->{max_redirect} =~ /^\d+$/ )
1393 ? $opts->{max_redirect}
1394 0 ▶ : $self->max_redirect;
Branch: 1 branch
BranchTrueFalseTotal
defined $opts->{'max_redirect'} && $opts->{'max_redirect'} =~ /^\d+$/ ? : 0 0 0
Condition0%0/3
defined $opts->{"max_redirect"} and $opts->{"max_redirect"} =~ /^\d+$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opts->{"max_redirect"} and $opts->{"max_redirect"} =~ /^\d+$/
defined $opts->{"max_redirect"} $opts->{"max_redirect"} =~ /^\d+$/
Truth table0%0/3
A and B
A= defined $opts->{"max_redirect"}B= $opts->{"max_redirect"} =~ /^\d+$/
ABresult
0X0
100
111
1395 0 ▶ $max_redirect //= 0;
Condition0%0/2
$max_redirect //= 0
l!l
00
MC/DC0%0/1
$max_redirect //= 0
$max_redirect
Truth table0%0/2
A
A= $max_redirect
Aresult
11
00
1396 # Perform redirect for:
1397 # Moved Permanently (301),
1398 # Moved Temporarily (302)
1399 # See Other (303)
1400 # Temporary Redirect (307)
1401 # Permanent Redirect (308)
1402 0 ▶ $do_redirect = ( $max_redirect && $def->{code} =~ /^30[12378]$/ );
Condition0%0/3
$max_redirect && $def->{'code'} =~ /^30[12378]$/
!ll&&!rl&&r
000
MC/DC0%0/2
$max_redirect && $def->{'code'} =~ /^30[12378]$/
$max_redirect $def->{'code'} =~ /^30[12378]$/
Truth table0%0/3
A && B
A= $max_redirectB= $def->{'code'} =~ /^30[12378]$/
ABresult
0X0
100
111
1403 }
1404  
1405 0 ▶ my $chunked = ( ( $headers->transfer_encoding // '' ) eq 'chunked' );
Condition0%0/2
$headers->transfer_encoding // ""
l!l
00
MC/DC0%0/1
$headers->transfer_encoding // ""
$headers->transfer_encoding
Truth table0%0/2
A
A= $headers->transfer_encoding
Aresult
11
00
1406 0 my $content_length = $headers->content_length;
1407 0 ▶ if( defined( $content_length ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content_length and length $content_length and not $content_length =~ /^\d+$/) 0 0 0
Condition0%0/6
defined $content_length and length $content_length and not $content_length =~ /^\d+$/
!ll&&!rl&&r
000
defined $content_length and length $content_length
!ll&&!rl&&r
000
MC/DC0%0/3
defined $content_length and length $content_length and not $content_length =~ /^\d+$/
defined $content_length length $content_length not $content_length =~ /^\d+$/
Truth table0%0/4
A and B and not(C)
A= defined $content_lengthB= length $content_lengthC= not $content_length =~ /^\d+$/
ABCresult
0XX0
10X0
1100
1111
1408 length( $content_length ) &&
1409 $content_length !~ /^\d+$/ )
1410 {
1411 # return( $self->error({ code => 500, message => "Bad Content-Length: ${content_length}" }) );
1412 0 ▶ warn( "Bad Content-Length '${content_length}' in server response.\n" ) if( $self->_warnings_is_enabled );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_warnings_is_enabled 0 0 0
1413 0 undef( $content_length );
1414 }
1415  
1416 0 ▶ unless( $req->method eq 'HEAD'
Branch: 1 branch
BranchTrueFalseTotal
unless ($req->method eq "HEAD" or $def->{"code"} >= 100 and $def->{"code"} < 200 or $def->{"code"} == 204 or $def->{"code"} == 302 or $def->{"code"} == 304) 0 0 0
Condition0%0/15
$req->method eq "HEAD" or $def->{"code"} >= 100 and $def->{"code"} < 200 or $def->{"code"} == 204 or $def->{"code"} == 302 or $def->{"code"} == 304
l!l&&r!l&&!r
000
$req->method eq "HEAD" or $def->{"code"} >= 100 and $def->{"code"} < 200 or $def->{"code"} == 204 or $def->{"code"} == 302
l!l&&r!l&&!r
000
$req->method eq "HEAD" or $def->{"code"} >= 100 and $def->{"code"} < 200 or $def->{"code"} == 204
l!l&&r!l&&!r
000
$req->method eq "HEAD" or $def->{"code"} >= 100 and $def->{"code"} < 200
l!l&&r!l&&!r
000
$def->{"code"} >= 100 and $def->{"code"} < 200
!ll&&!rl&&r
000
MC/DC0%0/6
$req->method eq "HEAD" or $def->{"code"} >= 100 and $def->{"code"} < 200 or $def->{"code"} == 204 or $def->{"code"} == 302 or $def->{"code"} == 304
$req->method eq "HEAD" $def->{"code"} >= 100 $def->{"code"} < 200 $def->{"code"} == 204 $def->{"code"} == 302 $def->{"code"} == 304
Truth table0%0/10
A or B and C or D or E or F
A= $req->method eq "HEAD"B= $def->{"code"} >= 100C= $def->{"code"} < 200D= $def->{"code"} == 204E= $def->{"code"} == 302F= $def->{"code"} == 304
ABCDEFresult
1XXXXX1
011XXX1
00X1XX1
0101XX1
00X01X1
01001X1
00X0011
0100011
00X0000
0100000
1417 || ( $def->{code} >= 100 && $def->{code} < 200 )
1418 || $def->{code} == 204
1419 || $def->{code} == 302
1420 || $def->{code} == 304 )
1421 {
1422 0 ▶ if( $chunked )
Branch: 1 branch
BranchTrueFalseTotal
if ($chunked) { } 0 0 0
1423 {
1424 0 ▶ $body = $self->_read_body_chunked(
Condition0%0/2
$self->_read_body_chunked('reader', $io, 'headers', $headers, 'entity', $ent) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_read_body_chunked('reader', $io, 'headers', $headers, 'entity', $ent) || (return $self->pass_error)
$self->_read_body_chunked('reader', $io, 'headers', $headers, 'entity', $ent)
Truth table0%0/2
A
A= $self->_read_body_chunked('reader', $io, 'headers', $headers, 'entity', $ent)
Aresult
11
00
1425 reader => $io,
1426 headers => $headers,
1427 entity => $ent,
1428 ) || return( $self->pass_error );
1429 }
1430 else
1431 {
1432 0 ▶ $body = $self->_read_body(
Condition0%0/2
$self->_read_body('reader', $io, 'headers', $headers, 'entity', $ent) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_read_body('reader', $io, 'headers', $headers, 'entity', $ent) || (return $self->pass_error)
$self->_read_body('reader', $io, 'headers', $headers, 'entity', $ent)
Truth table0%0/2
A
A= $self->_read_body('reader', $io, 'headers', $headers, 'entity', $ent)
Aresult
11
00
1433 reader => $io,
1434 headers => $headers,
1435 entity => $ent,
1436 ) || return( $self->pass_error );
1437 }
1438 0 ▶ return( $self->pass_error ) if( !defined( $body ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $body 0 0 0
1439 0 $total_bytes_read += $body->length;
1440 0 $ent->body( $body );
1441 }
1442  
1443 # manage connection cache (i.e. keep-alive)
1444 0 ▶ if( defined( $connection_header ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $connection_header and lc $connection_header eq "keep-alive") 0 0 0
Condition0%0/3
defined $connection_header and lc $connection_header eq "keep-alive"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $connection_header and lc $connection_header eq "keep-alive"
defined $connection_header lc $connection_header eq "keep-alive"
Truth table0%0/3
A and B
A= defined $connection_headerB= lc $connection_header eq "keep-alive"
ABresult
0X0
100
111
1445 lc( $connection_header ) eq 'keep-alive' )
1446 {
1447 0 ▶ my $connection = $headers->connection->lc // '';
Condition0%0/2
$headers->connection->lc // ""
l!l
00
MC/DC0%0/1
$headers->connection->lc // ""
$headers->connection->lc
Truth table0%0/2
A
A= $headers->connection->lc
Aresult
11
00
1448 0 ▶ if( ( $def->{version} > 1.0
Branch: 2 branches
BranchTrueFalseTotal
if ($def->{"version"} > 1 ? $connection ne "close" : $connection eq "keep-alive" and defined $content_length || $chunked) 0 0 0
$def->{'version'} > 1.0 ? : 0 0 0
Condition0%0/6
$def->{"version"} > 1 ? $connection ne "close" : $connection eq "keep-alive" and defined $content_length || $chunked
!ll&&!rl&&r
000
defined $content_length or $chunked
l!l&&r!l&&!r
000
MC/DC0%0/3
$def->{"version"} > 1 ? $connection ne "close" : $connection eq "keep-alive" and defined $content_length || $chunked
$def->{"version"} > 1 ? $connection ne "close" : $connection eq "keep-alive" defined $content_length $chunked
Truth table0%0/4
A and B or C
A= $def->{"version"} > 1 ? $connection ne "close" : $connection eq "keep-alive"B= defined $content_lengthC= $chunked
ABCresult
0XX0
1000
11X1
1011
1449 ? $connection ne 'close' # HTTP/1.1 can keep alive by default
1450 : $connection eq 'keep-alive' # HTTP/1.0 needs explicit keep-alive
1451 ) && ( defined( $content_length ) or $chunked ) )
1452 {
1453 0 my $sock = $io->filehandle;
1454 0 ▶ $self->_pool->push( $uri->host, $uri->port, $sock ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_pool->push($uri->host, $uri->port, $sock) or return $self->pass_error 0 0 0
1455 return( $self->pass_error );
1456 }
1457 }
1458 # explicitly close here, just after returning the socket to the pool,
1459 # since it might be reused in the upcoming recursive call
1460 # undef( $sock );
1461 0 $io->close;
1462  
1463 # Process 'Set-Cookie' header before redirect, because Cookies may have been set upon redirection.
1464 0 ▶ if( defined( $cookie_jar ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cookie_jar) 0 0 0
1465 {
1466 0 ▶ if( $self->_can( $cookie_jar => 'extract_cookies' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_can($cookie_jar, 'extract_cookies')) { } 0 0 0
1467 {
1468 0 ▶ $cookie_jar->extract_cookies( $resp ) ||
Branch: 1 branch
BranchTrueFalseTotal
$cookie_jar->extract_cookies($resp) or return $self->pass_error($cookie_jar->error) 0 0 0
1469 return( $self->pass_error( $cookie_jar->error ) );
1470 }
1471 else
1472 {
1473 0 warn( "Cookie Jar object ", $self->_str_val( $cookie_jar ), " does not support the method 'extract_cookies'." );
1474 }
1475 }
1476
1477 0 ▶ if( $do_redirect )
Branch: 1 branch
BranchTrueFalseTotal
if ($do_redirect) 0 0 0
1478 {
1479 0 my $location = $headers->location;
1480 0 ▶ unless( $location =~ m{^[a-zA-Z][a-zA-Z0-9]+://} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($location =~ m[^[a-zA-Z][a-zA-Z0-9]+://]) 0 0 0
1481 {
1482 # RFC 2616 14.30 says Location header is absolute URI.
1483 # But, a lot of servers return relative URI.
1484 0 $location = URI->new_abs( $location => $uri );
1485 }
1486 # Note: RFC 1945 and RFC 2068 specify that the client is not allowed
1487 # to change the method on the redirected request. However, most
1488 # existing user agent implementations treat 302 as if it were a 303
1489 # response, performing a GET on the Location field-value regardless
1490 # of the original request method. The status codes 303 and 307 have
1491 # been added for servers that wish to make unambiguously clear which
1492 # kind of reaction is expected of the client. Also, 308 was introduced
1493 # to avoid the ambiguity of 301.
1494 # TODO: Create new object and add the old one as previous() to the new request.
1495 0 ▶ my $clone = $req->clone || return( $self->pass_error( $req->error ) );
Condition0%0/2
$req->clone || (return $self->pass_error($req->error))
l!l
00
MC/DC0%0/1
$req->clone || (return $self->pass_error($req->error))
$req->clone
Truth table0%0/2
A
A= $req->clone
Aresult
11
00
1496 0 ▶ unless( $def->{code} =~ /^30[178]$/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($def->{"code"} =~ /^30[178]$/) 0 0 0
1497 {
1498 0 $clone->method( 'GET' );
1499 }
1500 0 $clone->uri( $location );
1501 0 ▶ $max_redirect-- if( $max_redirect > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $max_redirect > 0 0 0 0
1502 0 $opts->{max_redirect} = $max_redirect;
1503 0 return( $self->send( $clone, $opts ) );
1504 0 ▶ my $resp2 = $self->send( $clone, $opts ) ||
Condition0%0/2
$self->send($clone, $opts) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->send($clone, $opts) || (return $self->pass_error)
$self->send($clone, $opts)
Truth table0%0/2
A
A= $self->send($clone, $opts)
Aresult
11
00
1505 return( $self->pass_error );
1506 0 $resp2->previous( $resp );
1507 0 return( $resp2 );
1508 }
1509  
1510 0 my $type = $ent->mime_type;
1511 # I we have a body at and it is a multipart, we parse it otherwise, we already have it stored
1512 0 ▶ if( $ent->body && $type =~ m,^multipart/,i )
Branch: 1 branch
BranchTrueFalseTotal
if ($ent->body and $type =~ m[^multipart/]i) 0 0 0
Condition0%0/3
$ent->body and $type =~ m[^multipart/]i
!ll&&!rl&&r
000
MC/DC0%0/2
$ent->body and $type =~ m[^multipart/]i
$ent->body $type =~ m[^multipart/]i
Truth table0%0/3
A and B
A= $ent->bodyB= $type =~ m[^multipart/]i
ABresult
0X0
100
111
1513 {
1514 # Now parse the raw data saved earlier
1515 0 ▶ my $fh = $ent->body->open( '+<', { binmode => 'raw' } ) ||
Condition0%0/2
$ent->body->open('+<', {'binmode', 'raw'}) || (return $self->pass_error($ent->body->error))
l!l
00
MC/DC0%0/1
$ent->body->open('+<', {'binmode', 'raw'}) || (return $self->pass_error($ent->body->error))
$ent->body->open('+<', {'binmode', 'raw'})
Truth table0%0/2
A
A= $ent->body->open('+<', {'binmode', 'raw'})
Aresult
11
00
1516 return( $self->pass_error( $ent->body->error ) );
1517 0 ▶ my $reader = HTTP::Promise::IO->new( $fh, max_read_buffer => $bufsize, debug => $self->debug ) ||
Condition0%0/2
'HTTP::Promise::IO'->new($fh, 'max_read_buffer', $bufsize, 'debug', $self->debug) || (return $self->pass_error('HTTP::Promise::IO'->error))
l!l
00
MC/DC0%0/1
'HTTP::Promise::IO'->new($fh, 'max_read_buffer', $bufsize, 'debug', $self->debug) || (return $self->pass_error('HTTP::Promise::IO'->error))
'HTTP::Promise::IO'->new($fh, 'max_read_buffer', $bufsize, 'debug', $self->debug)
Truth table0%0/2
A
A= 'HTTP::Promise::IO'->new($fh, 'max_read_buffer', $bufsize, 'debug', $self->debug)
Aresult
11
00
1518 return( $self->pass_error( HTTP::Promise::IO->error ) );
1519 0 ▶ my $ent2 = HTTP::Promise::Entity->new( headers => $headers, http_message => $resp, debug => $self->debug ) ||
Condition0%0/2
'HTTP::Promise::Entity'->new('headers', $headers, 'http_message', $resp, 'debug', $self->debug) || (return $self->pass_error('HTTP::Promise::Entity'->error))
l!l
00
MC/DC0%0/1
'HTTP::Promise::Entity'->new('headers', $headers, 'http_message', $resp, 'debug', $self->debug) || (return $self->pass_error('HTTP::Promise::Entity'->error))
'HTTP::Promise::Entity'->new('headers', $headers, 'http_message', $resp, 'debug', $self->debug)
Truth table0%0/2
A
A= 'HTTP::Promise::Entity'->new('headers', $headers, 'http_message', $resp, 'debug', $self->debug)
Aresult
11
00
1520 return( $self->pass_error( HTTP::Promise::Entity->error ) );
1521 0 $resp->entity( $ent2 );
1522
1523 # Request body can be one of 3 types:
1524 # application/x-www-form-urlencoded
1525 # multipart/form-data
1526 # text/plain or other mime types
1527 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST>
1528 0 ▶ my $part_ent = $parser->parse_multi_part( entity => $ent2, reader => $reader ) ||
Condition0%0/2
$parser->parse_multi_part('entity', $ent2, 'reader', $reader) || (return $parser->pass_error)
l!l
00
MC/DC0%0/1
$parser->parse_multi_part('entity', $ent2, 'reader', $reader) || (return $parser->pass_error)
$parser->parse_multi_part('entity', $ent2, 'reader', $reader)
Truth table0%0/2
A
A= $parser->parse_multi_part('entity', $ent2, 'reader', $reader)
Aresult
11
00
1529 return( $parser->pass_error );
1530 }
1531
1532 0 return( $resp );
1533 }
1534  
1535 # NOTE: request parameter
1536 0 ▶sub send_te { return( shift->_set_get_boolean( 'send_te', @_ ) ); }
Subroutine send_te: not called CC=1 SCAR=6.9
Pod documented
1537  
1538 # NOTE: serialiser method for Promise::Me
1539 0 ▶sub serialiser { return( shift->_set_get_scalar( 'serialiser', @_ ) ); }
Subroutine serialiser: not called CC=1 SCAR=6.9
Pod documented
1540  
1541 # NOTE: shared_mem_size method for Promise::Me
1542 0 ▶sub shared_mem_size { return( shift->_set_get_scalar( 'shared_mem_size', @_ ) ); }
Subroutine shared_mem_size: not called CC=1 SCAR=6.9
Pod documented
1543  
1544 sub simple_request
1545 0 ▶{
Subroutine simple_request: not called CC=6 SCAR=37.4
Pod documented
1546 0 my $self = shift( @_ );
1547 0 my $req = shift( @_ );
1548 0 my $opts = $self->_get_args_as_hash( @_ );
1549 0 ▶ $opts->{read_size} //= 0;
Condition0%0/2
$opts->{"read_size"} //= 0
l!l
00
MC/DC0%0/1
$opts->{"read_size"} //= 0
$opts->{"read_size"}
Truth table0%0/2
A
A= $opts->{"read_size"}
Aresult
11
00
1550 0 ▶ if( $self->use_promise )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_promise) { } 0 0 0
1551 {
1552 return( Promise::Me->new(sub
1553 0 ▶ {
Subroutine __ANON__: not called CC=4 SCAR=30.0
1554 0 my( $resolve, $reject ) = @$_;
1555 0 ▶ return( $reject->( HTTP::Promise::Exception->new({
Branch: 1 branch
BranchTrueFalseTotal
unless $req 0 0 0
1556 code => 500,
1557 message => "No request object was provided."
1558 }) ) ) if( !$req );
1559 0 ▶ $self->use_content_file( $opts->{use_content_file} ) if( exists( $opts->{use_content_file} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"use_content_file"} 0 0 0
1560 0 $opts->{max_redirect} = 0;
1561 0 ▶ my $resp = $self->send( $req, $opts ) || return( $reject->( $self->pass_error ) );
Condition0%0/2
$self->send($req, $opts) || (return &$reject($self->pass_error))
l!l
00
MC/DC0%0/1
$self->send($req, $opts) || (return &$reject($self->pass_error))
$self->send($req, $opts)
Truth table0%0/2
A
A= $self->send($req, $opts)
Aresult
11
00
1562 0 return( $resolve->( $resp ) );
1563 0 }) );
1564 }
1565 else
1566 {
1567 0 ▶ return( $self->error( "No request object was provided." ) ) if( !$req );
Branch: 1 branch
BranchTrueFalseTotal
unless $req 0 0 0
1568 0 ▶ $self->use_content_file( $opts->{use_content_file} ) if( exists( $opts->{use_content_file} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"use_content_file"} 0 0 0
1569 0 $opts->{max_redirect} = 0;
1570 0 ▶ my $resp = $self->send( $req, $opts ) || return( $self->pass_error );
Condition0%0/2
$self->send($req, $opts) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->send($req, $opts) || (return $self->pass_error)
$self->send($req, $opts)
Truth table0%0/2
A
A= $self->send($req, $opts)
Aresult
11
00
1571 0 return( $resp );
1572 }
1573 }
1574  
1575 0 ▶sub ssl_opts { return( shift->_set_get_hash_as_mix_object( 'ssl_opts', @_ ) ); }
Subroutine ssl_opts: not called CC=1 SCAR=6.9
Pod documented
1576  
1577 0 ▶sub stop_if { return( shift->_set_get_code( 'stop_if', @_ ) ); }
Subroutine stop_if: not called CC=1 SCAR=6.9
Pod documented
1578  
1579 0 ▶sub threshold { return( shift->_set_get_scalar( 'threshold', @_ ) ); }
Subroutine threshold: not called CC=1 SCAR=6.9
Pod documented
1580  
1581 # NOTE: request parameter
1582 0 ▶sub timeout { return( shift->_set_get_number( 'timeout', @_ ) ); }
Subroutine timeout: not called CC=1 SCAR=6.9
Pod documented
1583  
1584 # NOTE: upgrade_insecure_requestsis an alias for auto_switch_https
1585 0 ▶sub upgrade_insecure_requests { return( shift->_set_get_boolean( 'auto_switch_https', @_ ) ); }
Subroutine upgrade_insecure_requests: not called CC=1 SCAR=6.9
Pod documented
1586  
1587 0 ▶sub uri_escape { return( URI::Escape::XS::uri_escape( $_[1] ) ); }
Subroutine uri_escape: not called CC=1 SCAR=6.9
Pod documented
1588  
1589 0 ▶sub uri_unescape { return( URI::Escape::XS::uri_unescape( $_[1] ) ); }
Subroutine uri_unescape: not called CC=1 SCAR=6.9
Pod documented
1590  
1591 0 ▶sub use_content_file { return( shift->_set_get_boolean( 'use_content_file', @_ ) ); }
Subroutine use_content_file: not called CC=1 SCAR=6.9
Pod documented
1592  
1593 0 ▶sub use_promise { return( shift->_set_get_boolean( 'use_promise', @_ ) ); }
Subroutine use_promise: not called CC=1 SCAR=6.9
Pod documented
1594  
1595 sub _datetime
1596 0 ▶{
Subroutine _datetime: not called CC=5 SCAR=34.0
1597 0 my $self = shift( @_ );
1598 0 my $dt;
1599 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1600 {
1601 0 ▶ return( $self->error( "Object provided (", ref( $_[0] ), ") is not a DateTime::Lite, DateTime or Module::Generic::DateTime object." ) ) if( !$self->_is_a( $_[0] => [qw( DateTime::Lite DateTime Module::Generic::DateTime )] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($_[0], ["DateTime::Lite", "DateTime", "Module::Generic::DateTime"]) 0 0 0
1602 0 $dt = shift( @_ );
1603 }
1604
1605 0 ▶ if( !defined( $dt ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $dt) { } 0 0 0
elsif ($dt->isa('Module::Generic::DateTime')) { } 0 0 0
1606 {
1607 0 $dt = DateTime::Lite->now;
1608 }
1609 # We need to get the underlying DateTime object if it is wrapped inside Module::Generic::DateTime
1610 elsif( $dt->isa( 'Module::Generic::DateTime' ) )
1611 {
1612 0 $dt = $dt->datetime;
1613 }
1614
1615 0 $dt->set_time_zone( 'GMT' );
1616 0 my $fmt = DateTime::Format::Lite->new(
1617 pattern => '%a, %d %b %Y %H:%M:%S GMT',
1618 locale => 'en_GB',
1619 time_zone => 'GMT',
1620 );
1621 0 $dt->set_formatter( $fmt );
1622 0 return( $dt );
1623 }
1624  
1625 # my $res = $prom->_make_request_data( $form_object );
1626 # my $res = $prom->_make_request_data( $form_data_object );
1627 # my $res = $prom->_make_request_data( 'post' => $url, \%form );
1628 # my $res = $prom->_make_request_data( 'post' => $url, \%form );
1629 # my $res = $prom->_make_request_data( 'post' => $url, \@form );
1630 # my $res = $prom->_make_request_data( 'post' => $url, \%form, $field_name => $value, ... );
1631 # my $res = $prom->_make_request_data( 'post' => $url, $field_name => $value, Content => \%form, Query => $escaped_string );
1632 # my $res = $prom->_make_request_data( 'post' => $url, $field_name => $value, Content => \@form, Query => $escaped_string );
1633 # my $res = $prom->_make_request_data( 'post' => $url, $field_name => $value, Content => $content, Query => $escaped_string );
1634 sub _make_request_data
1635 0 ▶{
Subroutine _make_request_data: not called CC=97 SCAR=91.6
1636 0 my $self = shift( @_ );
1637 0 ▶ my $meth = shift( @_ ) || return( $self->error( 'No http method was provided.' ) );
Condition0%0/2
shift @_ || (return $self->error('No http method was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No http method was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1638 0 ▶ my $uri = shift( @_ ) || return( $self->error( 'No uri was provided.' ) );
Condition0%0/2
shift @_ || (return $self->error('No uri was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No uri was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1639 0 ▶ my $req = HTTP::Promise::Request->new( $meth => $uri, { debug => $self->debug } ) ||
Condition0%0/2
'HTTP::Promise::Request'->new($meth, $uri, {'debug', $self->debug}) || (return $self->pass_error('HTTP::Promise::Request'->error))
l!l
00
MC/DC0%0/1
'HTTP::Promise::Request'->new($meth, $uri, {'debug', $self->debug}) || (return $self->pass_error('HTTP::Promise::Request'->error))
'HTTP::Promise::Request'->new($meth, $uri, {'debug', $self->debug})
Truth table0%0/2
A
A= 'HTTP::Promise::Request'->new($meth, $uri, {'debug', $self->debug})
Aresult
11
00
1640 return( $self->pass_error( HTTP::Promise::Request->error ) );
1641 0 $self->prepare_headers( $req );
1642 0 my @args = @_; # REMOVE ME
1643 0 ▶ $self->message( 4, "Received arguments -> ", sub{ $self->dump( \@args ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
1644 # To set up a possible escaped query string for this POST/PUT request
1645 0 ▶ my $u = $req->uri ||
Condition0%0/2
$req->uri || (return $self->error('No URL was provided for this HTTP query.'))
l!l
00
MC/DC0%0/1
$req->uri || (return $self->error('No URL was provided for this HTTP query.'))
$req->uri
Truth table0%0/2
A
A= $req->uri
Aresult
11
00
1646 return( $self->error( "No URL was provided for this HTTP query." ) );
1647 0 my $ent = $req->entity;
1648 0 my $content;
1649 0 ▶ if( scalar( @_ ) == 1 &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1 and defined $_[0] and ref $_[0] eq "HASH" and exists $_[0]{"Content"}) 0 0 0
Condition0%0/9
scalar @_ == 1 and defined $_[0] and ref $_[0] eq "HASH" and exists $_[0]{"Content"}
!ll&&!rl&&r
000
scalar @_ == 1 and defined $_[0] and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
scalar @_ == 1 and defined $_[0]
!ll&&!rl&&r
000
MC/DC0%0/4
scalar @_ == 1 and defined $_[0] and ref $_[0] eq "HASH" and exists $_[0]{"Content"}
scalar @_ == 1 defined $_[0] ref $_[0] eq "HASH" exists $_[0]{"Content"}
Truth table0%0/5
A and B and C and D
A= scalar @_ == 1B= defined $_[0]C= ref $_[0] eq "HASH"D= exists $_[0]{"Content"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1650 defined( $_[0] ) &&
1651 ref( $_[0] ) eq 'HASH' &&
1652 CORE::exists( $_[0]->{Content} ) )
1653 {
1654 0 ▶ warn( "It seems you are passing an hash reference of parameters, but this should be avoided as it may be confused with an hash reference of form parameters." ) if( $self->_is_warnings_enabled );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled 0 0 0
1655 }
1656  
1657 # Maybe content is provided as the first argument?
1658 0 ▶ if( scalar( @_ ) && defined( $_[0] ) &&
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_ and defined $_[0] and $self->_is_array($_[0]) || ref $_[0] eq 'HASH' && !scalar(grep /^Content$/i, @_) || $self->_is_a($_[0], 'HTTP::Promise::Body::Form') || $self->_is_a($_[0], 'HTTP::Promise::Body::Form::Data')) { } 0 0 0
elsif (scalar @_ and @_ % 2 and defined $_[-1] and $self->_is_array($_[-1]) || ref $_[-1] eq 'HASH' && !scalar(grep /^Content$/i, @_) || $self->_is_a($_[-1], 'HTTP::Promise::Body::Form') || $self->_is_a($_[-1], 'HTTP::Promise::Body::Form::Data')) { } 0 0 0
Condition0%0/18
scalar @_ and defined $_[0] and $self->_is_array($_[0]) || ref $_[0] eq "HASH" && !scalar(grep /^Content$/i, @_) || $self->_is_a($_[0], "HTTP::Promise::Body::Form") || $self->_is_a($_[0], "HTTP::Promise::Body::Form::Data")
!ll&&!rl&&r
000
scalar @_ and defined $_[0]
!ll&&!rl&&r
000
$self->_is_array($_[0]) or ref $_[0] eq "HASH" and not scalar grep(/^Content$/i, @_) or $self->_is_a($_[0], "HTTP::Promise::Body::Form") or $self->_is_a($_[0], "HTTP::Promise::Body::Form::Data")
l!l&&r!l&&!r
000
$self->_is_array($_[0]) or ref $_[0] eq "HASH" and not scalar grep(/^Content$/i, @_) or $self->_is_a($_[0], "HTTP::Promise::Body::Form")
l!l&&r!l&&!r
000
$self->_is_array($_[0]) or ref $_[0] eq "HASH" and not scalar grep(/^Content$/i, @_)
l!l&&r!l&&!r
000
ref $_[0] eq "HASH" and not scalar grep(/^Content$/i, @_)
!ll&&!rl&&r
000
MC/DC0%0/7
scalar @_ and defined $_[0] and $self->_is_array($_[0]) || ref $_[0] eq "HASH" && !scalar(grep /^Content$/i, @_) || $self->_is_a($_[0], "HTTP::Promise::Body::Form") || $self->_is_a($_[0], "HTTP::Promise::Body::Form::Data")
scalar @_ defined $_[0] $self->_is_array($_[0]) ref $_[0] eq "HASH" not scalar grep(/^Content$/i, @_) $self->_is_a($_[0], "HTTP::Promise::Body::Form") $self->_is_a($_[0], "HTTP::Promise::Body::Form::Data")
Truth table0%0/10
A and B and C or D and not(E) or F or G
A= scalar @_B= defined $_[0]C= $self->_is_array($_[0])D= ref $_[0] eq "HASH"E= not scalar grep(/^Content$/i, @_)F= $self->_is_a($_[0], "HTTP::Promise::Body::Form")G= $self->_is_a($_[0], "HTTP::Promise::Body::Form::Data")
ABCDEFGresult
0XXXXXX0
10XXXXX0
1100X000
11010000
111XXXX1
11011XX1
1100X1X1
110101X1
1100X011
11010011
1659 (
1660 $self->_is_array( $_[0] ) ||
1661 ( ref( $_[0] ) eq 'HASH' && !scalar( grep( /^Content$/i, @_ ) ) ) ||
1662 $self->_is_a( $_[0] => 'HTTP::Promise::Body::Form' ) ||
1663 $self->_is_a( $_[0] => 'HTTP::Promise::Body::Form::Data' )
1664 ) )
1665 {
1666 0 $content = shift( @_ );
1667 }
1668 # Maybe content is provided as the last argument?
1669 ▶ elsif( scalar( @_ ) &&
Condition0%0/21
scalar @_ and @_ % 2 and defined $_[-1] and $self->_is_array($_[-1]) || ref $_[-1] eq "HASH" && !scalar(grep /^Content$/i, @_) || $self->_is_a($_[-1], "HTTP::Promise::Body::Form") || $self->_is_a($_[-1], "HTTP::Promise::Body::Form::Data")
!ll&&!rl&&r
000
scalar @_ and @_ % 2 and defined $_[-1]
!ll&&!rl&&r
000
scalar @_ and @_ % 2
!ll&&!rl&&r
000
$self->_is_array($_[-1]) or ref $_[-1] eq "HASH" and not scalar grep(/^Content$/i, @_) or $self->_is_a($_[-1], "HTTP::Promise::Body::Form") or $self->_is_a($_[-1], "HTTP::Promise::Body::Form::Data")
l!l&&r!l&&!r
000
$self->_is_array($_[-1]) or ref $_[-1] eq "HASH" and not scalar grep(/^Content$/i, @_) or $self->_is_a($_[-1], "HTTP::Promise::Body::Form")
l!l&&r!l&&!r
000
$self->_is_array($_[-1]) or ref $_[-1] eq "HASH" and not scalar grep(/^Content$/i, @_)
l!l&&r!l&&!r
000
ref $_[-1] eq "HASH" and not scalar grep(/^Content$/i, @_)
!ll&&!rl&&r
000
MC/DC0%0/8
scalar @_ and @_ % 2 and defined $_[-1] and $self->_is_array($_[-1]) || ref $_[-1] eq "HASH" && !scalar(grep /^Content$/i, @_) || $self->_is_a($_[-1], "HTTP::Promise::Body::Form") || $self->_is_a($_[-1], "HTTP::Promise::Body::Form::Data")
scalar @_ @_ % 2 defined $_[-1] $self->_is_array($_[-1]) ref $_[-1] eq "HASH" not scalar grep(/^Content$/i, @_) $self->_is_a($_[-1], "HTTP::Promise::Body::Form") $self->_is_a($_[-1], "HTTP::Promise::Body::Form::Data")
Truth table0%0/11
A and B and C and D or E and not(F) or G or H
A= scalar @_B= @_ % 2C= defined $_[-1]D= $self->_is_array($_[-1])E= ref $_[-1] eq "HASH"F= not scalar grep(/^Content$/i, @_)G= $self->_is_a($_[-1], "HTTP::Promise::Body::Form")H= $self->_is_a($_[-1], "HTTP::Promise::Body::Form::Data")
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110XXXXX0
11100X000
111010000
1111XXXX1
111011XX1
11100X1X1
1110101X1
11100X011
111010011
1670 ( @_ % 2 ) &&
1671 defined( $_[-1] ) &&
1672 (
1673 $self->_is_array( $_[-1] ) ||
1674 ( ref( $_[-1] ) eq 'HASH' && !scalar( grep( /^Content$/i, @_ ) ) ) ||
1675 $self->_is_a( $_[-1] => 'HTTP::Promise::Body::Form' ) ||
1676 $self->_is_a( $_[-1] => 'HTTP::Promise::Body::Form::Data' )
1677 ) )
1678 {
1679 0 $content = pop( @_ );
1680 }
1681
1682 0 my( $k, $v );
1683 0 ▶ while( ( $k, $v ) = splice( @_, 0, 2 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 0 0 0
1684 {
1685 0 ▶ if( lc( $k ) eq 'content' )
Branch: 2 branches
BranchTrueFalseTotal
if (lc $k eq 'content') { } 0 0 0
elsif (lc $k eq 'query') { } 0 0 0
1686 {
1687 0 $content = $v;
1688 }
1689 # Handle possible escaped query string for this POST/PUT request
1690 elsif( lc( $k ) eq 'query' )
1691 {
1692 0 ▶ if( ref( $v ) eq 'HASH' || $self->_is_array( $v ) )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $v eq 'HASH' or $self->_is_array($v)) { } 0 0 0
elsif (not ref $v or ref $v and overload::Method($v, '""')) { } 0 0 0
Condition0%0/3
ref $v eq "HASH" or $self->_is_array($v)
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $v eq "HASH" or $self->_is_array($v)
ref $v eq "HASH" $self->_is_array($v)
Truth table0%0/3
A or B
A= ref $v eq "HASH"B= $self->_is_array($v)
ABresult
1X1
011
000
1693 {
1694 # try-catch
1695 0 local $@;
1696 eval
1697 0 {
1698 0 $u->query_form( $v );
1699 };
1700 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1701 {
1702 0 return( $self->error( "Error while setting query form key-value pairs: $@" ) );
1703 }
1704 }
1705 ▶ elsif( !ref( $v ) || ( ref( $v ) && overload::Method( $v => '""' ) ) )
Condition0%0/6
not ref $v or ref $v and overload::Method($v, "\"\"")
l!l&&r!l&&!r
000
ref $v and overload::Method($v, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/3
not ref $v or ref $v and overload::Method($v, "\"\"")
not ref $v ref $v overload::Method($v, "\"\"")
Truth table0%0/4
not(A) or B and C
A= not ref $vB= ref $vC= overload::Method($v, "\"\"")
ABCresult
1XX1
0111
00X0
0100
1706 {
1707 0 $u->query( "$v" );
1708 }
1709 }
1710 else
1711 {
1712 # $req->headers->push_header( $k, $v );
1713 0 $req->headers->replace( $k, $v );
1714 }
1715 }
1716 0 my $orig_ct = $req->headers->header( 'Content-Type' );
1717 0 my $ct = $orig_ct;
1718 0 my( $obj, $type );
1719 # By default
1720 0 ▶ if( !$ct && defined( $content ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not $ct and defined $content) { } 0 0 0
elsif ($ct and $ct eq 'form-data') { } 0 0 0
Condition0%0/3
not $ct and defined $content
!ll&&!rl&&r
000
MC/DC0%0/2
not $ct and defined $content
not $ct defined $content
Truth table0%0/3
not(A) and B
A= not $ctB= defined $content
ABresult
0X0
100
111
1721 {
1722 0 $ct = 'application/x-www-form-urlencoded';
1723 }
1724 # If the user used the short version of multipart/form-data, we update the Content-Type accordingly.
1725 ▶ elsif( $ct && $ct eq 'form-data' )
Condition0%0/3
$ct and $ct eq "form-data"
!ll&&!rl&&r
000
MC/DC0%0/2
$ct and $ct eq "form-data"
$ct $ct eq "form-data"
Truth table0%0/3
A and B
A= $ctB= $ct eq "form-data"
ABresult
0X0
100
111
1726 {
1727 0 $ct = 'multipart/form-data';
1728 0 $req->headers->header( 'Content-Type' => $ct );
1729 }
1730  
1731 0 ▶ if( defined( $ct ) && length( "$ct" ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ct and length "$ct") 0 0 0
Condition0%0/3
defined $ct and length "$ct"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ct and length "$ct"
defined $ct length "$ct"
Truth table0%0/3
A and B
A= defined $ctB= length "$ct"
ABresult
0X0
100
111
1732 {
1733 0 $obj = $req->headers->new_field( 'Content-Type' => "$ct" );
1734 0 ▶ return( $self->pass_error( $req->headers->error ) ) if( !defined( $obj ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $obj 0 0 0
1735 0 $type = $obj->type;
1736 }
1737  
1738 # $content can be an array reference, hash reference, an HTTP::Promise::Body::Form object, or an HTTP::Promise::Body::Form::Data object
1739 0 ▶ if( ref( $content ) )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $content) { } 0 0 0
elsif (defined $content and length $content) { } 0 0 0
1740 {
1741 # if( $ct =~ m,^multipart/form-data[[:blank:]\h]*(;|$),i )
1742 0 ▶ if( lc( substr( "$type", 0, 19 ) ) eq 'multipart/form-data' )
Branch: 5 branches
BranchTrueFalseTotal
if (lc substr("$type", 0, 19) eq 'multipart/form-data') { } 0 0 0
elsif (lc $type eq 'application/x-www-form-urlencoded' and builtin::reftype($content) eq 'ARRAY' || ref $content eq 'HASH' || $self->_is_a($content, 'HTTP::Promise::Body::Form')) { } 0 0 0
elsif ($self->_is_a($content, 'HTTP::Promise::Body')) { } 0 0 0
elsif ($self->_is_a($content, 'Module::Generic::File')) { } 0 0 0
elsif (overload::Method($content, '""')) { } 0 0 0
1743 {
1744 0 ▶ unless( $obj->boundary )
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj->boundary) 0 0 0
1745 {
1746 0 $obj->boundary( $req->make_boundary );
1747 }
1748 # HTTP::Promise::Body::Form::Data inherits from HTTP::Promise::Body::Form, so we do it first
1749 0 ▶ if( $self->_is_a( $content => 'HTTP::Promise::Body::Form::Data' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($content, "HTTP::Promise::Body::Form::Data")) 0 0 0
1750 {
1751 0 $content->debug( $self->debug ); # REMOVE ME
1752 0 $content->boundary( $obj->boundary );
1753 0 ▶ my $parts = $content->make_parts ||
Condition0%0/2
$content->make_parts || (return $self->pass_error($content->error))
l!l
00
MC/DC0%0/1
$content->make_parts || (return $self->pass_error($content->error))
$content->make_parts
Truth table0%0/2
A
A= $content->make_parts
Aresult
11
00
1754 return( $self->pass_error( $content->error ) );
1755 0 $ent->parts( $parts );
1756 0 $ent->body( $content );
1757 }
1758 0 ▶ if( $self->_is_a( $content => 'HTTP::Promise::Body::Form' ) )
Branch: 3 branches
BranchTrueFalseTotal
if ($self->_is_a($content, 'HTTP::Promise::Body::Form')) { } 0 0 0
elsif ($self->_is_array($content)) { } 0 0 0
elsif (ref $content eq 'HASH') { } 0 0 0
1759 {
1760 0 ▶ my $form = $content->as_form_data ||
Condition0%0/2
$content->as_form_data || (return $self->pass_error($content->error))
l!l
00
MC/DC0%0/1
$content->as_form_data || (return $self->pass_error($content->error))
$content->as_form_data
Truth table0%0/2
A
A= $content->as_form_data
Aresult
11
00
1761 return( $self->pass_error( $content->error ) );
1762 0 $form->debug( $self->debug ); # REMOVE ME
1763 0 $form->boundary( $obj->boundary );
1764 0 ▶ my $parts = $form->make_parts ||
Condition0%0/2
$form->make_parts || (return $self->pass_error($form->error))
l!l
00
MC/DC0%0/1
$form->make_parts || (return $self->pass_error($form->error))
$form->make_parts
Truth table0%0/2
A
A= $form->make_parts
Aresult
11
00
1765 return( $self->pass_error( $form->error ) );
1766 0 $ent->parts( $parts );
1767 0 $ent->body( $form );
1768 }
1769 elsif( $self->_is_array( $content ) )
1770 {
1771 # Keep track of the order of the fields
1772 0 my $fields = [];
1773 0 ▶ for( my $i = 0; $i < scalar( @$content ); $i += 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$content) 0 0 0
1774 {
1775 0 push( @$fields, $content->[$i] );
1776 }
1777 0 ▶ $self->_load_class( 'HTTP::Promise::Body::Form::Data' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Body::Form::Data") or return $self->pass_error 0 0 0
1778 return( $self->pass_error );
1779 0 ▶ my $form = HTTP::Promise::Body::Form::Data->new( @$content ) ||
Condition0%0/2
'HTTP::Promise::Body::Form::Data'->new(@$content) || (return $self->pass_error('HTTP::Promise::Body::Form::Data'->error))
l!l
00
MC/DC0%0/1
'HTTP::Promise::Body::Form::Data'->new(@$content) || (return $self->pass_error('HTTP::Promise::Body::Form::Data'->error))
'HTTP::Promise::Body::Form::Data'->new(@$content)
Truth table0%0/2
A
A= 'HTTP::Promise::Body::Form::Data'->new(@$content)
Aresult
11
00
1780 return( $self->pass_error( HTTP::Promise::Body::Form::Data->error ) );
1781 0 $form->debug( $self->debug ); # REMOVE ME
1782 0 $form->boundary( $obj->boundary );
1783 0 ▶ my $parts = $form->make_parts( fields => $fields ) ||
Condition0%0/2
$form->make_parts('fields', $fields) || (return $self->pass_error($form->error))
l!l
00
MC/DC0%0/1
$form->make_parts('fields', $fields) || (return $self->pass_error($form->error))
$form->make_parts('fields', $fields)
Truth table0%0/2
A
A= $form->make_parts('fields', $fields)
Aresult
11
00
1784 return( $self->pass_error( $form->error ) );
1785 0 $ent->parts( $parts );
1786 0 $ent->body( $form );
1787 }
1788 elsif( ref( $content ) eq 'HASH' )
1789 {
1790 0 ▶ $self->_load_class( 'HTTP::Promise::Body::Form::Data' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Body::Form::Data") or return $self->pass_error 0 0 0
1791 return( $self->pass_error );
1792 0 ▶ my $form = HTTP::Promise::Body::Form::Data->new( $content ) ||
Condition0%0/2
'HTTP::Promise::Body::Form::Data'->new($content) || (return $self->pass_error('HTTP::Promise::Body::Form::Data'->error))
l!l
00
MC/DC0%0/1
'HTTP::Promise::Body::Form::Data'->new($content) || (return $self->pass_error('HTTP::Promise::Body::Form::Data'->error))
'HTTP::Promise::Body::Form::Data'->new($content)
Truth table0%0/2
A
A= 'HTTP::Promise::Body::Form::Data'->new($content)
Aresult
11
00
1793 return( $self->pass_error( HTTP::Promise::Body::Form::Data->error ) );
1794 0 $form->debug( $self->debug ); # REMOVE ME
1795 0 $form->boundary( $obj->boundary );
1796 0 ▶ my $parts = $form->make_parts ||
Condition0%0/2
$form->make_parts || (return $self->pass_error($form->error))
l!l
00
MC/DC0%0/1
$form->make_parts || (return $self->pass_error($form->error))
$form->make_parts
Truth table0%0/2
A
A= $form->make_parts
Aresult
11
00
1797 return( $self->pass_error( $form->error ) );
1798 0 $ent->parts( $parts );
1799 0 $ent->body( $form );
1800 }
1801 else
1802 {
1803 0 return( $self->error( "Unsupported content of type '", ref( $content ), "'" ) );
1804 }
1805 }
1806 ▶ elsif( lc( $type ) eq TYPE_URL_ENCODED &&
Condition0%0/9
lc $type eq "application/x-www-form-urlencoded" and builtin::reftype($content) eq "ARRAY" || ref $content eq "HASH" || $self->_is_a($content, "HTTP::Promise::Body::Form")
!ll&&!rl&&r
000
builtin::reftype($content) eq "ARRAY" or ref $content eq "HASH" or $self->_is_a($content, "HTTP::Promise::Body::Form")
l!l&&r!l&&!r
000
builtin::reftype($content) eq "ARRAY" or ref $content eq "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/4
lc $type eq "application/x-www-form-urlencoded" and builtin::reftype($content) eq "ARRAY" || ref $content eq "HASH" || $self->_is_a($content, "HTTP::Promise::Body::Form")
lc $type eq "application/x-www-form-urlencoded" builtin::reftype($content) eq "ARRAY" ref $content eq "HASH" $self->_is_a($content, "HTTP::Promise::Body::Form")
Truth table0%0/5
A and B or C or D
A= lc $type eq "application/x-www-form-urlencoded"B= builtin::reftype($content) eq "ARRAY"C= ref $content eq "HASH"D= $self->_is_a($content, "HTTP::Promise::Body::Form")
ABCDresult
0XXX0
10000
11XX1
101X1
10011
1807 (
1808 Scalar::Util::reftype( $content ) eq 'ARRAY' ||
1809 ref( $content ) eq 'HASH' ||
1810 $self->_is_a( $content => 'HTTP::Promise::Body::Form' )
1811 ) )
1812 {
1813 0 my $form;
1814 0 ▶ if( $self->_is_a( $content => 'HTTP::Promise::Body::Form' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($content, 'HTTP::Promise::Body::Form')) { } 0 0 0
1815 {
1816 0 $form = $content;
1817 }
1818 else
1819 {
1820 0 my $reftype = Scalar::Util::reftype( $content );
1821 0 ▶ $self->_load_class( 'HTTP::Promise::Body::Form' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Body::Form") or return $self->pass_error 0 0 0
1822 return( $self->pass_error );
1823 0 ▶ $form = HTTP::Promise::Body::Form->new( ( $reftype eq 'ARRAY' && !$self->_can_overload( $content => '""' ) ) ? @$content : $content ) ||
Branch: 1 branch
BranchTrueFalseTotal
$reftype eq 'ARRAY' && !$self->_can_overload($content, '""') ? : 0 0 0
Condition0%0/5
'HTTP::Promise::Body::Form'->new($reftype eq 'ARRAY' && !$self->_can_overload($content, '""') ? @$content : $content) || (return $self->pass_error('HTTP::Promise::Body::Form'->error))
l!l
00
$reftype eq "ARRAY" and not $self->_can_overload($content, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/1
'HTTP::Promise::Body::Form'->new($reftype eq 'ARRAY' && !$self->_can_overload($content, '""') ? @$content : $content) || (return $self->pass_error('HTTP::Promise::Body::Form'->error))
'HTTP::Promise::Body::Form'->new($reftype eq 'ARRAY' && !$self->_can_overload($content, '""') ? @$content : $content)
MC/DC0%0/2
$reftype eq "ARRAY" and not $self->_can_overload($content, "\"\"")
$reftype eq "ARRAY" not $self->_can_overload($content, "\"\"")
Truth table0%0/2
A
A= 'HTTP::Promise::Body::Form'->new($reftype eq 'ARRAY' && !$self->_can_overload($content, '""') ? @$content : $content)
Aresult
11
00
Truth table0%0/3
A and not(B)
A= $reftype eq "ARRAY"B= not $self->_can_overload($content, "\"\"")
ABresult
0X0
100
111
1824 return( $self->pass_error( HTTP::Promise::Body::Form->error ) );
1825 }
1826 0 $ent->body( $form );
1827 }
1828 elsif( $self->_is_a( $content => 'HTTP::Promise::Body' ) )
1829 {
1830 0 $ent->body( $content );
1831 }
1832 # Module::Generic::File has stringification overloaded, so we put it here first
1833 elsif( $self->_is_a( $content => 'Module::Generic::File' ) )
1834 {
1835 0 ▶ my $body = $ent->new_body( file => $content ) ||
Condition0%0/2
$ent->new_body('file', $content) || (return $self->pass_error($ent->error))
l!l
00
MC/DC0%0/1
$ent->new_body('file', $content) || (return $self->pass_error($ent->error))
$ent->new_body('file', $content)
Truth table0%0/2
A
A= $ent->new_body('file', $content)
Aresult
11
00
1836 return( $self->pass_error( $ent->error ) );
1837 0 $ent->body( $body );
1838 }
1839 elsif( overload::Method( $content => '""' ) )
1840 {
1841 0 ▶ my $body = $ent->new_body( string => "$content" ) ||
Condition0%0/2
$ent->new_body('string', "$content") || (return $self->pass_error($ent->error))
l!l
00
MC/DC0%0/1
$ent->new_body('string', "$content") || (return $self->pass_error($ent->error))
$ent->new_body('string', "$content")
Truth table0%0/2
A
A= $ent->new_body('string', "$content")
Aresult
11
00
1842 return( $self->pass_error( $ent->error ) );
1843 0 $ent->body( $body );
1844 }
1845 else
1846 {
1847 0 return( $self->error( "Unsupported Content-Type: $ct for data type '", ref( $content ), "'" ) );
1848 }
1849 }
1850 # $content is not a reference and is not empty
1851 ▶ elsif( defined( $content ) && length( $content ) )
Condition0%0/3
defined $content and length $content
!ll&&!rl&&r
000
MC/DC0%0/2
defined $content and length $content
defined $content length $content
Truth table0%0/3
A and B
A= defined $contentB= length $content
ABresult
0X0
100
111
1852 {
1853 0 my $charset = $req->headers->charset;
1854 0 ▶ if( !defined( $charset ) && $req->headers->error )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $charset and $req->headers->error) { } 0 0 0
Condition0%0/3
not defined $charset and $req->headers->error
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $charset and $req->headers->error
not defined $charset $req->headers->error
Truth table0%0/3
not(A) and B
A= not defined $charsetB= $req->headers->error
ABresult
0X0
100
111
1855 {
1856 0 ▶ warn( "Error getting charset: ", $req->headers->error ) if( $self->_is_warnings_enabled( 'HTTP::Promise' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("HTTP::Promise") 0 0 0
1857 }
1858 else
1859 {
1860 0 ▶ $charset = lc( $charset // '' );
Condition0%0/2
$charset // ""
l!l
00
MC/DC0%0/1
$charset // ""
$charset
Truth table0%0/2
A
A= $charset
Aresult
11
00
1861 }
1862 0 ▶ my $ctype = lc( $type // '' );
Condition0%0/2
$type // ""
l!l
00
MC/DC0%0/1
$type // ""
$type
Truth table0%0/2
A
A= $type
Aresult
11
00
1863 0 ▶ my( $ctype_major, $ctype_minor ) = split( /\//, $ctype, 2 ) if( $ctype );
Branch: 1 branch
BranchTrueFalseTotal
if $ctype 0 0 0
1864 0 ▶ if( ( substr( $charset, 0, 4 ) eq 'utf8' ||
Branch: 1 branch
BranchTrueFalseTotal
if (substr($charset, 0, 4) eq "utf8" || substr($charset, 0, 5) eq "utf-8" || defined $ctype_major && defined $ctype_minor && $ctype_major eq "application" && substr($ctype_minor, -4, 4) eq "json" and utf8::is_utf8($content)) 0 0 0
Condition0%0/18
substr($charset, 0, 4) eq "utf8" || substr($charset, 0, 5) eq "utf-8" || defined $ctype_major && defined $ctype_minor && $ctype_major eq "application" && substr($ctype_minor, -4, 4) eq "json" and utf8::is_utf8($content)
!ll&&!rl&&r
000
substr($charset, 0, 4) eq "utf8" or substr($charset, 0, 5) eq "utf-8" or defined $ctype_major and defined $ctype_minor and $ctype_major eq "application" and substr($ctype_minor, -4, 4) eq "json"
l!l&&r!l&&!r
000
substr($charset, 0, 4) eq "utf8" or substr($charset, 0, 5) eq "utf-8"
l!l&&r!l&&!r
000
defined $ctype_major and defined $ctype_minor and $ctype_major eq "application" and substr($ctype_minor, -4, 4) eq "json"
!ll&&!rl&&r
000
defined $ctype_major and defined $ctype_minor and $ctype_major eq "application"
!ll&&!rl&&r
000
defined $ctype_major and defined $ctype_minor
!ll&&!rl&&r
000
MC/DC0%0/7
substr($charset, 0, 4) eq "utf8" || substr($charset, 0, 5) eq "utf-8" || defined $ctype_major && defined $ctype_minor && $ctype_major eq "application" && substr($ctype_minor, -4, 4) eq "json" and utf8::is_utf8($content)
substr($charset, 0, 4) eq "utf8" substr($charset, 0, 5) eq "utf-8" defined $ctype_major defined $ctype_minor $ctype_major eq "application" substr($ctype_minor, -4, 4) eq "json" utf8::is_utf8($content)
Truth table0%0/10
A or B or C and D and E and F and G
A= substr($charset, 0, 4) eq "utf8"B= substr($charset, 0, 5) eq "utf-8"C= defined $ctype_majorD= defined $ctype_minorE= $ctype_major eq "application"F= substr($ctype_minor, -4, 4) eq "json"G= utf8::is_utf8($content)
ABCDEFGresult
000XXXX0
0010XXX0
00110XX0
001110X0
1XXXXX00
01XXXX00
00111100
1XXXXX11
01XXXX11
00111111
1865 substr( $charset, 0, 5 ) eq 'utf-8' ||
1866 ( defined( $ctype_major ) && defined( $ctype_minor ) && $ctype_major eq 'application' && substr( $ctype_minor, -4, 4 ) eq 'json' ) ) &&
1867 utf8::is_utf8( $content ) )
1868 {
1869 0 ▶ warn( "Content data provided has the Perl internal UTF-8 flag set. You need to encode it to UTF-8 bytes before passing it to HTTP::Promise, such as by calling Encode::encode_utf8( \$data ) on it beforehand.\n" ) if( $self->_is_warnings_enabled( 'HTTP::Promise' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("HTTP::Promise") 0 0 0
1870 }
1871  
1872 0 ▶ my $body = $ent->new_body( string => $content ) ||
Condition0%0/2
$ent->new_body('string', $content) || (return $self->pass_error($ent->error))
l!l
00
MC/DC0%0/1
$ent->new_body('string', $content) || (return $self->pass_error($ent->error))
$ent->new_body('string', $content)
Truth table0%0/2
A
A= $ent->new_body('string', $content)
Aresult
11
00
1873 return( $self->pass_error( $ent->error ) );
1874 0 $ent->body( $body );
1875 }
1876  
1877 # Set Content-Type if needed
1878 0 ▶ $req->headers->content_type( "$obj" ) if( defined( $obj ) && !$orig_ct );
Branch: 1 branch
BranchTrueFalseTotal
if defined $obj and not $orig_ct 0 0 0
Condition0%0/3
defined $obj and not $orig_ct
!ll&&!rl&&r
000
MC/DC0%0/2
defined $obj and not $orig_ct
defined $obj not $orig_ct
Truth table0%0/3
A and not(B)
A= defined $objB= not $orig_ct
ABresult
0X0
100
111
1879 0 ▶ if( defined( $content ) && length( $content ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $content and length $content) { } 0 0 0
elsif ($ct) { } 0 0 0
Condition0%0/3
defined $content and length $content
!ll&&!rl&&r
000
MC/DC0%0/2
defined $content and length $content
defined $content length $content
Truth table0%0/3
A and B
A= defined $contentB= length $content
ABresult
0X0
100
111
1880 {
1881 # Make sure the content is encoded, if applicable, so we can get the proper content length.
1882 0 ▶ if( my $encodings = $req->headers->content_encoding )
Branch: 1 branch
BranchTrueFalseTotal
if (my $encodings = $req->headers->content_encoding) 0 0 0
1883 {
1884 0 ▶ $ent->encode_body( $encodings ) if( !$ent->is_encoded );
Branch: 1 branch
BranchTrueFalseTotal
unless $ent->is_encoded 0 0 0
1885 }
1886 # Here we could pass a boundary => $boundary argument to $ent->body->length which would then be passed to the as_string method, but the as_string method in HTTP::Promise::Body::Form::Data will call the method 'boundary' if no boundary value is provided as an option.
1887 # $req->content_length( $ent->body->length );
1888 0 ▶ my $bytes = $ent->body->length ||
Condition0%0/2
$ent->body->length || (return $self->pass_error($ent->body->error))
l!l
00
MC/DC0%0/1
$ent->body->length || (return $self->pass_error($ent->body->error))
$ent->body->length
Truth table0%0/2
A
A= $ent->body->length
Aresult
11
00
1889 return( $self->pass_error( $ent->body->error ) );
1890 0 $req->content_length( $bytes );
1891 }
1892 # Set the Content-Length to 0 only if there is a Content-Type set
1893 elsif( $ct )
1894 {
1895 0 $req->header( 'Content-Length' => 0 );
1896 }
1897 0 return( $req );
1898 }
1899  
1900 sub _make_request_query
1901 0 ▶{
Subroutine _make_request_query: not called CC=17 SCAR=57.2
1902 0 my $self = shift( @_ );
1903 0 ▶ my $meth = shift( @_ ) || return( $self->error( 'No http method was provided.' ) );
Condition0%0/2
shift @_ || (return $self->error('No http method was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No http method was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1904 0 ▶ my $uri = shift( @_ ) || return( $self->error( 'No uri was provided.' ) );
Condition0%0/2
shift @_ || (return $self->error('No uri was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No uri was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1905 0 ▶ my $req = HTTP::Promise::Request->new( $meth => $uri, { debug => $self->debug } ) ||
Condition0%0/2
'HTTP::Promise::Request'->new($meth, $uri, {'debug', $self->debug}) || (return $self->pass_error('HTTP::Promise::Request'->error))
l!l
00
MC/DC0%0/1
'HTTP::Promise::Request'->new($meth, $uri, {'debug', $self->debug}) || (return $self->pass_error('HTTP::Promise::Request'->error))
'HTTP::Promise::Request'->new($meth, $uri, {'debug', $self->debug})
Truth table0%0/2
A
A= 'HTTP::Promise::Request'->new($meth, $uri, {'debug', $self->debug})
Aresult
11
00
1906 return( $self->pass_error( HTTP::Promise::Request->error ) );
1907 0 $self->prepare_headers( $req );
1908 0 ▶ my $u = $req->uri ||
Condition0%0/2
$req->uri || (return $self->error('No URL was provided for this HTTP query.'))
l!l
00
MC/DC0%0/1
$req->uri || (return $self->error('No URL was provided for this HTTP query.'))
$req->uri
Truth table0%0/2
A
A= $req->uri
Aresult
11
00
1909 return( $self->error( "No URL was provided for this HTTP query." ) );
1910 0 my( $k, $v );
1911 0 ▶ while( ( $k, $v ) = ( @_ == 1 && ref( $_[0] ) eq 'HASH' ) ? each( %{$_[0]} ) : splice( @_, 0, 2 ) )
Branch: 2 branches
BranchTrueFalseTotal
if (() = @_ == 1 && ref $_[0] eq "HASH" ? each %{$_[0];} : splice(@_, 0, 2)) 0 0 0
@_ == 1 && ref $_[0] eq 'HASH' ? : 0 0 0
Condition0%0/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
1912 {
1913 0 ▶ if( lc( $k ) eq 'content' || lc( $k ) eq 'query' )
Branch: 1 branch
BranchTrueFalseTotal
if (lc $k eq 'content' or lc $k eq 'query') { } 0 0 0
Condition0%0/3
lc $k eq "content" or lc $k eq "query"
l!l&&r!l&&!r
000
MC/DC0%0/2
lc $k eq "content" or lc $k eq "query"
lc $k eq "content" lc $k eq "query"
Truth table0%0/3
A or B
A= lc $k eq "content"B= lc $k eq "query"
ABresult
1X1
011
000
1914 {
1915 0 ▶ if( ref( $v ) eq 'HASH' || $self->_is_array( $v ) )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $v eq 'HASH' or $self->_is_array($v)) { } 0 0 0
elsif (not ref $v or ref $v and overload::Method($v, '""')) { } 0 0 0
Condition0%0/3
ref $v eq "HASH" or $self->_is_array($v)
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $v eq "HASH" or $self->_is_array($v)
ref $v eq "HASH" $self->_is_array($v)
Truth table0%0/3
A or B
A= ref $v eq "HASH"B= $self->_is_array($v)
ABresult
1X1
011
000
1916 {
1917 # try-catch
1918 0 local $@;
1919 eval
1920 0 {
1921 0 $u->query_form( $v );
1922 };
1923 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1924 {
1925 0 return( $self->error( "Error while setting query form key-value pairs: $@" ) );
1926 }
1927 }
1928 ▶ elsif( !ref( $v ) || ( ref( $v ) && overload::Method( $v => '""' ) ) )
Condition0%0/6
not ref $v or ref $v and overload::Method($v, "\"\"")
l!l&&r!l&&!r
000
ref $v and overload::Method($v, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/3
not ref $v or ref $v and overload::Method($v, "\"\"")
not ref $v ref $v overload::Method($v, "\"\"")
Truth table0%0/4
not(A) or B and C
A= not ref $vB= ref $vC= overload::Method($v, "\"\"")
ABCresult
1XX1
0111
00X0
0100
1929 {
1930 0 $u->query( "$v" );
1931 }
1932 else
1933 {
1934 0 ▶ warn( "Option \"$k\" was provided, but no content data (", overload::StrVal( $v ), ") is allowed for this type of HTTP query. Ignoring it.\n" ) if( $self->_warnings_is_enabled );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_warnings_is_enabled 0 0 0
1935 }
1936 }
1937 else
1938 {
1939 # $req->headers->push_header( $k, $v );
1940 0 $req->headers->replace( $k, $v );
1941 }
1942 }
1943 0 return( $req );
1944 }
1945  
1946 sub _match_no_proxy
1947 0 ▶{
Subroutine _match_no_proxy: not called CC=5 SCAR=34.0
1948 0 my( $self, $no_proxy, $host ) = @_;
1949  
1950 # ref. curl.1.
1951 # list of host names that shouldn't go through any proxy.
1952 # If set to a asterisk '*' only, it matches all hosts.
1953 0 ▶ if( $no_proxy eq '*' )
Branch: 2 branches
BranchTrueFalseTotal
if ($no_proxy eq '*') { } 0 0 0
elsif ($self->_is_array($no_proxy)) { } 0 0 0
1954 {
1955 0 return(1);
1956 }
1957 elsif( $self->_is_array( $no_proxy ) )
1958 {
1959 0 for my $pat ( @$no_proxy )
1960 {
1961 # suffix match (same behavior as LWP)
1962 0 ▶ if( $host =~ /\Q$pat\E$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($host =~ /\Q$pat\E$/) 0 0 0
1963 {
1964 0 return(1);
1965 }
1966 }
1967 }
1968 0 return(0);
1969 }
1970  
1971 0 ▶sub _pool { return( shift->_set_get_object( '_pool', 'HTTP::Promise::Pool', @_ ) ); }
Subroutine _pool: not called CC=1 SCAR=6.9
1972  
1973 # The purpose of this method is to read the entire HTPP message body, whatever that is, i.e. multipart o not
1974 # Parsing and decoding is done after data has been read from the socket, because speed matters.
1975 sub _read_body
1976 0 ▶{
Subroutine _read_body: not called CC=70 SCAR=85.1
1977 0 my $self = shift( @_ );
1978 0 my $opts = $self->_get_args_as_hash( @_ );
1979 0 ▶ my $timeout = $opts->{timeout} // $self->timeout;
Condition0%0/3
$opts->{"timeout"} // $self->timeout
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"timeout"} // $self->timeout
$opts->{"timeout"} $self->timeout
Truth table0%0/3
A // B
A= $opts->{"timeout"}B= $self->timeout
ABresult
1X1
011
000
1980 0 my $headers = $opts->{headers};
1981 0 ▶ return( $self->error( "Headers object provided is not a HTTP::Promise::Headers object." ) ) if( !$self->_is_a( $headers => 'HTTP::Promise::Headers' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($headers, "HTTP::Promise::Headers") 0 0 0
1982 0 my $ent = $opts->{entity};
1983 0 ▶ return( $self->error( "Entity object provided is not a HTTP::Promise::Entity object." ) ) if( !$self->_is_a( $ent => 'HTTP::Promise::Entity' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($ent, "HTTP::Promise::Entity") 0 0 0
1984 0 my $reader = $opts->{reader};
1985 0 ▶ return( $self->error( "Reader object provided is not a HTTP::Promise::IO object." ) ) if( !$self->_is_a( $reader => 'HTTP::Promise::IO' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($reader, "HTTP::Promise::IO") 0 0 0
1986 0 my $bufsize = $self->buffer_size;
1987  
1988 0 my $type = $headers->type;
1989 0 my $max_in_memory = $self->max_body_in_memory_size;
1990 # rfc7231, section 3.1.1.5 says we can assume applicatin/octet-stream if there
1991 # is no Content-Type header
1992 # <https://tools.ietf.org/html/rfc7231#section-3.1.1.5>
1993 0 ▶ my $default_mime = $DEFAULT_MIME_TYPE || 'application/octet-stream';
Condition0%0/2
$HTTP::Promise::DEFAULT_MIME_TYPE || 'application/octet-stream'
l!l
00
MC/DC0%0/1
$HTTP::Promise::DEFAULT_MIME_TYPE || 'application/octet-stream'
$HTTP::Promise::DEFAULT_MIME_TYPE
Truth table0%0/2
A
A= $HTTP::Promise::DEFAULT_MIME_TYPE
Aresult
11
00
1994 0 my $len = $headers->content_length;
1995 0 my $chunk_size = $self->buffer_size;
1996 0 my( $body, $file, $mime_type, $mime, $ext );
1997 0 my $data = '';
1998 0 my $total_bytes = 0;
1999
2000 my $get_temp_file = sub
2001 0 ▶ {
Subroutine __ANON__: not called CC=6 SCAR=37.4
2002 # Guessing extension
2003 0 $mime_type = $headers->mime_type( $default_mime );
2004 0 ▶ $self->_load_class( 'HTTP::Promise::MIME' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::MIME") or return $self->pass_error 0 0 0
2005 0 $mime = HTTP::Promise::MIME->new;
2006 0 $ext = $mime->suffix( $type );
2007 0 ▶ return( $self->pass_error( $mime->error ) ) if( !defined( $ext ) && $mime->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ext and $mime->error 0 0 0
Condition0%0/3
not defined $ext and $mime->error
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $ext and $mime->error
not defined $ext $mime->error
Truth table0%0/3
not(A) and B
A= not defined $extB= $mime->error
ABresult
0X0
100
111
2008 0 ▶ $ext ||= 'dat';
Condition0%0/2
$ext ||= "dat"
l!l
00
MC/DC0%0/1
$ext ||= "dat"
$ext
Truth table0%0/2
A
A= $ext
Aresult
11
00
2009 0 ▶ my $f = $self->new_tempfile( extension => $ext ) ||
Condition0%0/2
$self->new_tempfile('extension', $ext) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_tempfile('extension', $ext) || (return $self->pass_error)
$self->new_tempfile('extension', $ext)
Truth table0%0/2
A
A= $self->new_tempfile('extension', $ext)
Aresult
11
00
2010 return( $self->pass_error );
2011 0 return( $f );
2012 0 };
2013
2014 0 ▶ if( defined( $len ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $len) { } 0 0 0
2015 {
2016 # Too big, saving it to file; or
2017 # use_content_file is set to true.
2018 0 ▶ if( ( $len > $max_in_memory ) || $self->use_content_file )
Branch: 1 branch
BranchTrueFalseTotal
if ($len > $max_in_memory or $self->use_content_file) { } 0 0 0
Condition0%0/3
$len > $max_in_memory or $self->use_content_file
l!l&&r!l&&!r
000
MC/DC0%0/2
$len > $max_in_memory or $self->use_content_file
$len > $max_in_memory $self->use_content_file
Truth table0%0/3
A or B
A= $len > $max_in_memoryB= $self->use_content_file
ABresult
1X1
011
000
2019 {
2020 0 ▶ $file = $get_temp_file->() || return( $self->pass_error );
Condition0%0/2
&$get_temp_file() || (return $self->pass_error)
l!l
00
MC/DC0%0/1
&$get_temp_file() || (return $self->pass_error)
&$get_temp_file()
Truth table0%0/2
A
A= &$get_temp_file()
Aresult
11
00
2021 0 ▶ my $io = $file->open( '+>', { binmode => 'raw', autoflush => 1 } ) ||
Condition0%0/2
$file->open('+>', {'binmode', 'raw', 'autoflush', 1}) || (return $self->pass_error($file->error))
l!l
00
MC/DC0%0/1
$file->open('+>', {'binmode', 'raw', 'autoflush', 1}) || (return $self->pass_error($file->error))
$file->open('+>', {'binmode', 'raw', 'autoflush', 1})
Truth table0%0/2
A
A= $file->open('+>', {'binmode', 'raw', 'autoflush', 1})
Aresult
11
00
2022 return( $self->pass_error( $file->error ) );
2023 0 my $buff = '';
2024 0 my $bytes;
2025 0 ▶ $chunk_size = $len if( $chunk_size > $len );
Branch: 1 branch
BranchTrueFalseTotal
if $chunk_size > $len 0 0 0
2026 0 ▶ while( $bytes = $reader->read( $buff, $chunk_size ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($bytes = $reader->read($buff, $chunk_size)) 0 0 0
2027 {
2028 0 my $bytes_out = $io->syswrite( $buff );
2029 0 ▶ if( !defined( $bytes_out ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $bytes_out) 0 0 0
2030 {
2031 0 ▶ return( $self->pass_error( $io->error ) ) if( $io->error );
Branch: 1 branch
BranchTrueFalseTotal
if $io->error 0 0 0
2032 0 last;
2033 }
2034 # We do not want to read more than we should
2035 0 ▶ $chunk_size = ( $len - $total_bytes ) if( ( $total_bytes < $len ) && ( ( $total_bytes + $chunk_size ) > $len ) );
Branch: 1 branch
BranchTrueFalseTotal
if $total_bytes < $len and $total_bytes + $chunk_size > $len 0 0 0
Condition0%0/3
$total_bytes < $len and $total_bytes + $chunk_size > $len
!ll&&!rl&&r
000
MC/DC0%0/2
$total_bytes < $len and $total_bytes + $chunk_size > $len
$total_bytes < $len $total_bytes + $chunk_size > $len
Truth table0%0/3
A and B
A= $total_bytes < $lenB= $total_bytes + $chunk_size > $len
ABresult
0X0
100
111
2036 0 $total_bytes += $bytes;
2037 0 ▶ last if( $total_bytes == $len );
Branch: 1 branch
BranchTrueFalseTotal
if $total_bytes == $len 0 0 0
2038 }
2039 0 $io->close;
2040 0 ▶ return( $self->error( "Error reading http body from socket: ", $reader->error ) ) if( !defined( $bytes ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes 0 0 0
2041 }
2042 else
2043 {
2044 0 my $buff = '';
2045 0 my $bytes;
2046 0 ▶ $chunk_size = $len if( $chunk_size > $len );
Branch: 1 branch
BranchTrueFalseTotal
if $chunk_size > $len 0 0 0
2047 0 ▶ while( $bytes = $reader->read( $buff, $chunk_size ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($bytes = $reader->read($buff, $chunk_size)) 0 0 0
2048 {
2049 0 $data .= $buff;
2050 # We do not want to read more than we should
2051 0 ▶ $chunk_size = ( $len - $total_bytes ) if( ( $total_bytes < $len ) && ( ( $total_bytes + $chunk_size ) > $len ) );
Branch: 1 branch
BranchTrueFalseTotal
if $total_bytes < $len and $total_bytes + $chunk_size > $len 0 0 0
Condition0%0/3
$total_bytes < $len and $total_bytes + $chunk_size > $len
!ll&&!rl&&r
000
MC/DC0%0/2
$total_bytes < $len and $total_bytes + $chunk_size > $len
$total_bytes < $len $total_bytes + $chunk_size > $len
Truth table0%0/3
A and B
A= $total_bytes < $lenB= $total_bytes + $chunk_size > $len
ABresult
0X0
100
111
2052 0 $total_bytes += $bytes;
2053 0 ▶ last if( $total_bytes == $len );
Branch: 1 branch
BranchTrueFalseTotal
if $total_bytes == $len 0 0 0
2054 }
2055 0 ▶ return( $self->error( "Error reading HTTP body from socket: ", $reader->error ) ) if( !defined( $bytes ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes 0 0 0
2056 }
2057 0 ▶ warn( "HTTP::Promise: HTTP body size advertised ($len) does not match the size actually read from socket ($total_bytes)\n" ) if( $total_bytes != $len && $self->_warnings_is_enabled );
Branch: 1 branch
BranchTrueFalseTotal
if $total_bytes != $len and $self->_warnings_is_enabled 0 0 0
Condition0%0/3
$total_bytes != $len and $self->_warnings_is_enabled
!ll&&!rl&&r
000
MC/DC0%0/2
$total_bytes != $len and $self->_warnings_is_enabled
$total_bytes != $len $self->_warnings_is_enabled
Truth table0%0/3
A and B
A= $total_bytes != $lenB= $self->_warnings_is_enabled
ABresult
0X0
100
111
2058 }
2059 # No Content-Length defined
2060 else
2061 {
2062 0 my $buff = '';
2063 0 my $bytes = -1;
2064 0 my $io;
2065 0 ▶ while( $bytes )
Branch: 1 branch
BranchTrueFalseTotal
if ($bytes) 0 0 0
2066 {
2067 0 $bytes = $reader->read( $buff, $chunk_size );
2068 0 ▶ return( $self->pass_error( $reader->error ) ) if( !defined( $bytes ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes 0 0 0
2069
2070 0 ▶ if( defined( $io ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $io) { } 0 0 0
elsif (length($data) + length($buff) > $max_in_memory) { } 0 0 0
2071 {
2072 0 my $bytes_out = $io->syswrite( $buff );
2073 0 ▶ return( $self->pass_error( $io->error ) ) if( !defined( $bytes_out ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes_out 0 0 0
2074 }
2075 # The cumulative bytes total for this part exceeds the allowed maximum in memory
2076 elsif( ( length( $data ) + length( $buff ) ) > $max_in_memory )
2077 {
2078 0 ▶ $file = $get_temp_file->() || return( $self->pass_error );
Condition0%0/2
&$get_temp_file() || (return $self->pass_error)
l!l
00
MC/DC0%0/1
&$get_temp_file() || (return $self->pass_error)
&$get_temp_file()
Truth table0%0/2
A
A= &$get_temp_file()
Aresult
11
00
2079 0 ▶ $io = $file->open( '+>', { binmode => 'raw', autoflush => 1 } ) ||
Condition0%0/2
$file->open('+>', {'binmode', 'raw', 'autoflush', 1}) || (return $self->pass_error($file->error))
l!l
00
MC/DC0%0/1
$file->open('+>', {'binmode', 'raw', 'autoflush', 1}) || (return $self->pass_error($file->error))
$file->open('+>', {'binmode', 'raw', 'autoflush', 1})
Truth table0%0/2
A
A= $file->open('+>', {'binmode', 'raw', 'autoflush', 1})
Aresult
11
00
2080 return( $self->pass_error( $file->error ) );
2081 0 my $bytes_out = $io->syswrite( $data );
2082 0 ▶ return( $self->pass_error( $io->error ) ) if( !defined( $bytes_out ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes_out 0 0 0
2083 0 $bytes_out = $io->syswrite( $buff );
2084 0 ▶ return( $self->pass_error( $io->error ) ) if( !defined( $bytes_out ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes_out 0 0 0
2085 0 $data = '';
2086 }
2087 else
2088 {
2089 0 $data .= $buff;
2090 }
2091 }
2092 0 ▶ $total_bytes = defined( $file ) ? $file->length : length( $data );
Branch: 1 branch
BranchTrueFalseTotal
defined $file ? : 0 0 0
2093 }
2094  
2095 # If we used a file and the extension is 'dat', because we were clueless based on
2096 # the provided Content-Type, or maybe even the Content-Type is absent, we use the
2097 # XS module in HTTP::Promise::MIME to guess the mime-type based on the actual file
2098 # content
2099 0 ▶ if( defined( $file ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) { } 0 0 0
2100 {
2101 0 ▶ if( $mime_type eq $default_mime )
Branch: 1 branch
BranchTrueFalseTotal
if ($mime_type eq $default_mime) { } 0 0 0
2102 {
2103 0 ▶ unless( $mime )
Branch: 1 branch
BranchTrueFalseTotal
unless ($mime) 0 0 0
2104 {
2105 0 ▶ $self->_load_class( 'HTTP::Promise::MIME' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::MIME") or return $self->pass_error 0 0 0
2106 0 $mime = HTTP::Promise::MIME->new;
2107 }
2108
2109 # Guess the mime type from the file magic
2110 0 my $mtype = $mime->mime_type( $file );
2111 0 ▶ return( $self->pass_error( $mime->error ) ) if( !defined( $mime_type ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mime_type 0 0 0
2112 0 my( $enc, $enc_ext );
2113 0 ▶ if( $self->ext_vary && ( $enc = $headers->content_encoding ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ext_vary and $enc = $headers->content_encoding) 0 0 0
Condition0%0/3
$self->ext_vary and $enc = $headers->content_encoding
!ll&&!rl&&r
000
MC/DC0%0/2
$self->ext_vary and $enc = $headers->content_encoding
$self->ext_vary $enc = $headers->content_encoding
Truth table0%0/3
A and B
A= $self->ext_varyB= $enc = $headers->content_encoding
ABresult
0X0
100
111
2114 {
2115 0 ▶ $self->_load_class( 'HTTP::Promise::Stream' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Stream") or return $self->pass_error 0 0 0
2116 0 ▶ my $enc_exts = HTTP::Promise::Stream->encoding2suffix( $enc ) ||
Condition0%0/2
'HTTP::Promise::Stream'->encoding2suffix($enc) || (return $self->pass_error('HTTP::Promise::Stream'->error))
l!l
00
MC/DC0%0/1
'HTTP::Promise::Stream'->encoding2suffix($enc) || (return $self->pass_error('HTTP::Promise::Stream'->error))
'HTTP::Promise::Stream'->encoding2suffix($enc)
Truth table0%0/2
A
A= 'HTTP::Promise::Stream'->encoding2suffix($enc)
Aresult
11
00
2117 return( $self->pass_error( HTTP::Promise::Stream->error ) );
2118 0 ▶ $enc_ext = $enc_exts->join( '.' )->scalar if( !$enc_exts->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
unless $enc_exts->is_empty 0 0 0
2119 # Mark body as being encoded if necessary
2120 0 $ent->is_encoded(1);
2121 }
2122 0 ▶ if( $mtype && $mtype ne $default_mime )
Branch: 2 branches
BranchTrueFalseTotal
if ($mtype and $mtype ne $default_mime) { } 0 0 0
elsif (defined $enc_ext) { } 0 0 0
Condition0%0/3
$mtype and $mtype ne $default_mime
!ll&&!rl&&r
000
MC/DC0%0/2
$mtype and $mtype ne $default_mime
$mtype $mtype ne $default_mime
Truth table0%0/3
A and B
A= $mtypeB= $mtype ne $default_mime
ABresult
0X0
100
111
2123 {
2124 0 $mime_type = $mtype;
2125 # Also update the type value in HTTP::Promise::Headers
2126 # It does not affect the actual Content-Type header
2127 0 $headers->type( $mtype );
2128 0 my $new_ext = $mime->suffix( $mtype );
2129 0 ▶ return( $self->pass_error( $mime->error ) ) if( !defined( $new_ext ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $new_ext 0 0 0
2130 0 ▶ if( $new_ext && $new_ext ne $ext )
Branch: 1 branch
BranchTrueFalseTotal
if ($new_ext and $new_ext ne $ext) 0 0 0
Condition0%0/3
$new_ext and $new_ext ne $ext
!ll&&!rl&&r
000
MC/DC0%0/2
$new_ext and $new_ext ne $ext
$new_ext $new_ext ne $ext
Truth table0%0/3
A and B
A= $new_extB= $new_ext ne $ext
ABresult
0X0
100
111
2131 {
2132 0 ▶ $new_ext .= ".${enc_ext}" if( defined( $enc_ext ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $enc_ext 0 0 0
2133 0 ▶ my $new_file = $file->extension( $new_ext ) || return( $self->pass_error( $file->error ) );
Condition0%0/2
$file->extension($new_ext) || (return $self->pass_error($file->error))
l!l
00
MC/DC0%0/1
$file->extension($new_ext) || (return $self->pass_error($file->error))
$file->extension($new_ext)
Truth table0%0/2
A
A= $file->extension($new_ext)
Aresult
11
00
2134 0 ▶ my $this_file = $file->move( $new_file ) || return( $self->pass_error( $file->error ) );
Condition0%0/2
$file->move($new_file) || (return $self->pass_error($file->error))
l!l
00
MC/DC0%0/1
$file->move($new_file) || (return $self->pass_error($file->error))
$file->move($new_file)
Truth table0%0/2
A
A= $file->move($new_file)
Aresult
11
00
2135 0 $file = $this_file;
2136 }
2137 }
2138 elsif( defined( $enc_ext ) )
2139 {
2140 0 my $old_ext = $file->extension;
2141 0 $old_ext .= ".${enc_ext}";
2142 0 ▶ my $new_file = $file->extension( $old_ext ) || return( $self->pass_error( $file->error ) );
Condition0%0/2
$file->extension($old_ext) || (return $self->pass_error($file->error))
l!l
00
MC/DC0%0/1
$file->extension($old_ext) || (return $self->pass_error($file->error))
$file->extension($old_ext)
Truth table0%0/2
A
A= $file->extension($old_ext)
Aresult
11
00
2143 0 ▶ my $this_file = $file->move( $new_file ) || return( $self->pass_error( $file->error ) );
Condition0%0/2
$file->move($new_file) || (return $self->pass_error($file->error))
l!l
00
MC/DC0%0/1
$file->move($new_file) || (return $self->pass_error($file->error))
$file->move($new_file)
Truth table0%0/2
A
A= $file->move($new_file)
Aresult
11
00
2144 0 $file = $this_file;
2145 }
2146 }
2147 else
2148 {
2149 0 my( $enc );
2150 0 ▶ if( $self->ext_vary && ( $enc = $headers->content_encoding ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ext_vary and $enc = $headers->content_encoding) 0 0 0
Condition0%0/3
$self->ext_vary and $enc = $headers->content_encoding
!ll&&!rl&&r
000
MC/DC0%0/2
$self->ext_vary and $enc = $headers->content_encoding
$self->ext_vary $enc = $headers->content_encoding
Truth table0%0/3
A and B
A= $self->ext_varyB= $enc = $headers->content_encoding
ABresult
0X0
100
111
2151 {
2152 0 ▶ $self->_load_class( 'HTTP::Promise::Stream' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Stream") or return $self->pass_error 0 0 0
2153 0 my $old_ext = $file->extension;
2154 0 ▶ my $enc_exts = HTTP::Promise::Stream->encoding2suffix( $enc ) ||
Condition0%0/2
'HTTP::Promise::Stream'->encoding2suffix($enc) || (return $self->pass_error('HTTP::Promise::Stream'->error))
l!l
00
MC/DC0%0/1
'HTTP::Promise::Stream'->encoding2suffix($enc) || (return $self->pass_error('HTTP::Promise::Stream'->error))
'HTTP::Promise::Stream'->encoding2suffix($enc)
Truth table0%0/2
A
A= 'HTTP::Promise::Stream'->encoding2suffix($enc)
Aresult
11
00
2155 return( $self->pass_error( HTTP::Promise::Stream->error ) );
2156 0 ▶ if( !$enc_exts->is_empty )
Branch: 1 branch
BranchTrueFalseTotal
unless ($enc_exts->is_empty) 0 0 0
2157 {
2158 0 $old_ext .= '.' . $enc_exts->join( '.' )->scalar;
2159 0 ▶ my $new_file = $file->extension( $old_ext ) || return( $self->pass_error( $file->error ) );
Condition0%0/2
$file->extension($old_ext) || (return $self->pass_error($file->error))
l!l
00
MC/DC0%0/1
$file->extension($old_ext) || (return $self->pass_error($file->error))
$file->extension($old_ext)
Truth table0%0/2
A
A= $file->extension($old_ext)
Aresult
11
00
2160 0 ▶ my $this_file = $file->move( $new_file ) || return( $self->pass_error( $file->error ) );
Condition0%0/2
$file->move($new_file) || (return $self->pass_error($file->error))
l!l
00
MC/DC0%0/1
$file->move($new_file) || (return $self->pass_error($file->error))
$file->move($new_file)
Truth table0%0/2
A
A= $file->move($new_file)
Aresult
11
00
2161 0 $file = $this_file;
2162 }
2163 # Mark body as being encoded if necessary
2164 0 $ent->is_encoded(1);
2165 }
2166 }
2167
2168 0 ▶ $body = $ent->new_body( file => $file ) ||
Condition0%0/2
$ent->new_body('file', $file) || (return $self->pass_error($ent->error))
l!l
00
MC/DC0%0/1
$ent->new_body('file', $file) || (return $self->pass_error($ent->error))
$ent->new_body('file', $file)
Truth table0%0/2
A
A= $ent->new_body('file', $file)
Aresult
11
00
2169 return( $self->pass_error( $ent->error ) );
2170 0 $self->file( $file );
2171 }
2172 # in memory
2173 else
2174 {
2175 # If this is a application/x-www-form-urlencoded type, we save it as such, and
2176 # the HTTP::Promise::Body::Form makes those data accessible as an hash object
2177 0 ▶ if( $type && $type eq TYPE_URL_ENCODED )
Branch: 1 branch
BranchTrueFalseTotal
if ($type and $type eq 'application/x-www-form-urlencoded') { } 0 0 0
Condition0%0/3
$type and $type eq "application/x-www-form-urlencoded"
!ll&&!rl&&r
000
MC/DC0%0/2
$type and $type eq "application/x-www-form-urlencoded"
$type $type eq "application/x-www-form-urlencoded"
Truth table0%0/3
A and B
A= $typeB= $type eq "application/x-www-form-urlencoded"
ABresult
0X0
100
111
2178 {
2179 0 ▶ $body = $ent->new_body( form => $data ) ||
Condition0%0/2
$ent->new_body('form', $data) || (return $self->pass_error($ent->error))
l!l
00
MC/DC0%0/1
$ent->new_body('form', $data) || (return $self->pass_error($ent->error))
$ent->new_body('form', $data)
Truth table0%0/2
A
A= $ent->new_body('form', $data)
Aresult
11
00
2180 return( $self->pass_error( $ent->error ) );
2181 }
2182 else
2183 {
2184 0 ▶ $body = $ent->new_body( string => $data ) ||
Condition0%0/2
$ent->new_body('string', $data) || (return $self->pass_error($ent->error))
l!l
00
MC/DC0%0/1
$ent->new_body('string', $data) || (return $self->pass_error($ent->error))
$ent->new_body('string', $data)
Truth table0%0/2
A
A= $ent->new_body('string', $data)
Aresult
11
00
2185 return( $self->pass_error( $ent->error ) );
2186 }
2187 }
2188 0 return( $body );
2189 }
2190  
2191 sub _read_body_chunked
2192 0 ▶{
Subroutine _read_body_chunked: not called CC=36 SCAR=71.9
2193 0 my $self = shift( @_ );
2194 0 my $opts = $self->_get_args_as_hash( @_ );
2195 0 ▶ my $timeout = $opts->{timeout} // $self->timeout;
Condition0%0/3
$opts->{"timeout"} // $self->timeout
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"timeout"} // $self->timeout
$opts->{"timeout"} $self->timeout
Truth table0%0/3
A // B
A= $opts->{"timeout"}B= $self->timeout
ABresult
1X1
011
000
2196 0 my $headers = $opts->{headers};
2197 0 ▶ return( $self->error( "Headers object provided is not a HTTP::Promise::Headers object." ) ) if( !$self->_is_a( $headers => 'HTTP::Promise::Headers' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($headers, "HTTP::Promise::Headers") 0 0 0
2198 0 my $ent = $opts->{entity};
2199 0 ▶ return( $self->error( "Entity object provided is not a HTTP::Promise::Entity object." ) ) if( !$self->_is_a( $ent => 'HTTP::Promise::Entity' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($ent, "HTTP::Promise::Entity") 0 0 0
2200 0 my $reader = $opts->{reader};
2201 0 ▶ return( $self->error( "Reader object provided is not a HTTP::Promise::IO object." ) ) if( !$self->_is_a( $reader => 'HTTP::Promise::IO' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($reader, "HTTP::Promise::IO") 0 0 0
2202 0 my $bufsize = $self->buffer_size;
2203 # rfc7231, section 3.1.1.5 says we can assume applicatin/octet-stream if there
2204 # is no Content-Type header
2205 # <https://tools.ietf.org/html/rfc7231#section-3.1.1.5>
2206 0 ▶ my $default_mime = $DEFAULT_MIME_TYPE || 'application/octet-stream';
Condition0%0/2
$HTTP::Promise::DEFAULT_MIME_TYPE || 'application/octet-stream'
l!l
00
MC/DC0%0/1
$HTTP::Promise::DEFAULT_MIME_TYPE || 'application/octet-stream'
$HTTP::Promise::DEFAULT_MIME_TYPE
Truth table0%0/2
A
A= $HTTP::Promise::DEFAULT_MIME_TYPE
Aresult
11
00
2207 0 my $len = $headers->content_length;
2208  
2209 # Guessing extension
2210 0 my $mime_type = $headers->mime_type( $default_mime );
2211 0 ▶ $self->_load_class( 'HTTP::Promise::MIME' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::MIME") or return $self->pass_error 0 0 0
2212 0 my $mime = HTTP::Promise::MIME->new;
2213 0 my $ext;
2214 # rfc6839 <https://www.rfc-editor.org/info/rfc6839/>
2215 0 ▶ if( index( $mime_type, '+' ) != -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($mime_type, '+') != -1) { } 0 0 0
2216 {
2217 0 my( $actual_mime, $file_extension ) = split( /\+/, $mime_type, 2 );
2218 0 $ext = $mime->suffix( $actual_mime );
2219 0 ▶ $ext = $file_extension unless( defined( $ext ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ext 0 0 0
2220 }
2221 else
2222 {
2223 0 $ext = $mime->suffix( $mime_type );
2224 }
2225 0 ▶ return( $self->pass_error( $mime->error ) ) if( !defined( $ext ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ext 0 0 0
2226 0 ▶ $ext ||= 'dat';
Condition0%0/2
$ext ||= "dat"
l!l
00
MC/DC0%0/1
$ext ||= "dat"
$ext
Truth table0%0/2
A
A= $ext
Aresult
11
00
2227 0 my $enc;
2228 0 ▶ if( $self->ext_vary && ( $enc = $headers->content_encoding ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ext_vary and $enc = $headers->content_encoding) 0 0 0
Condition0%0/3
$self->ext_vary and $enc = $headers->content_encoding
!ll&&!rl&&r
000
MC/DC0%0/2
$self->ext_vary and $enc = $headers->content_encoding
$self->ext_vary $enc = $headers->content_encoding
Truth table0%0/3
A and B
A= $self->ext_varyB= $enc = $headers->content_encoding
ABresult
0X0
100
111
2229 {
2230 0 ▶ $self->_load_class( 'HTTP::Promise::Stream' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Stream") or return $self->pass_error 0 0 0
2231 0 ▶ my $enc_ext = HTTP::Promise::Stream->encoding2suffix( $enc ) ||
Condition0%0/2
'HTTP::Promise::Stream'->encoding2suffix($enc) || (return $self->pass_error('HTTP::Promise::Stream'->error))
l!l
00
MC/DC0%0/1
'HTTP::Promise::Stream'->encoding2suffix($enc) || (return $self->pass_error('HTTP::Promise::Stream'->error))
'HTTP::Promise::Stream'->encoding2suffix($enc)
Truth table0%0/2
A
A= 'HTTP::Promise::Stream'->encoding2suffix($enc)
Aresult
11
00
2232 return( $self->pass_error( HTTP::Promise::Stream->error ) );
2233 0 ▶ $ext .= '.' . $enc_ext->join( '.' )->scalar if( !$enc_ext->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
unless $enc_ext->is_empty 0 0 0
2234 }
2235 0 ▶ my $tempfile = $self->new_tempfile( extension => $ext ) ||
Condition0%0/2
$self->new_tempfile('extension', $ext) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_tempfile('extension', $ext) || (return $self->pass_error)
$self->new_tempfile('extension', $ext)
Truth table0%0/2
A
A= $self->new_tempfile('extension', $ext)
Aresult
11
00
2236 return( $self->pass_error );
2237 # HTTP::Promise::Body::File inherits from Module::Generic::File, so we pass it some
2238 # appropriate parameters.
2239 0 ▶ my $body = $ent->new_body( 'file', $tempfile ) ||
Condition0%0/2
$ent->new_body('file', $tempfile) || (return $self->pass_error($ent->error))
l!l
00
MC/DC0%0/1
$ent->new_body('file', $tempfile) || (return $self->pass_error($ent->error))
$ent->new_body('file', $tempfile)
Truth table0%0/2
A
A= $ent->new_body('file', $tempfile)
Aresult
11
00
2240 return( $self->pass_error( $ent->error ) );
2241 0 ▶ my $io = $body->open( '+>', { binmode => 'raw', autoflush => 1 } ) ||
Condition0%0/2
$body->open('+>', {'binmode', 'raw', 'autoflush', 1}) || (return $self->pass_error($body->error))
l!l
00
MC/DC0%0/1
$body->open('+>', {'binmode', 'raw', 'autoflush', 1}) || (return $self->pass_error($body->error))
$body->open('+>', {'binmode', 'raw', 'autoflush', 1})
Truth table0%0/2
A
A= $body->open('+>', {'binmode', 'raw', 'autoflush', 1})
Aresult
11
00
2242 return( $self->pass_error( $body->error ) );
2243 0 my $buff = '';
2244 0 my $bytes = -1;
2245 0 my $te_re = qr{
2246 \A ( # header
2247 ( [0-9a-fA-F]+ ) # next_len (hex number)
2248 (?:;
2249 $HTTP_TOKEN
2250 =
2251 (?: $HTTP_TOKEN | $HTTP_QUOTED_STRING )
2252 )* # optional chunk-extensions
2253 [[:blank:]]* # www.yahoo.com adds spaces here.
2254 # Is this valid?
2255 \015\012 # CR+LF
2256 )
2257 }mxs;
2258
2259 0 ▶ READ_LOOP: while( $bytes )
Branch: 1 branch
BranchTrueFalseTotal
if ($bytes) 0 0 0
2260 {
2261 # If we do not find anything within the maximum allocable memory size, this will
2262 # return an error, so we can bank on it
2263 0 my $hdr = $reader->read_until_in_memory( $te_re, include => 1 );
2264 0 ▶ return( $self->pass_error( $reader->error ) ) if( !defined( $hdr ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hdr 0 0 0
2265 0 ▶ last if( !length( $hdr ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $hdr 0 0 0
2266
2267 0 my( $header, $hex_len ) = ( $hdr =~ m/$te_re/ );
2268 # remove header from buffer
2269 # $hdr = substr( $hdr, 0, length( $header ), '' );
2270 0 my $len = hex( $hex_len );
2271 0 ▶ if( $len == 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($len == 0) 0 0 0
2272 {
2273 0 last READ_LOOP;
2274 }
2275 # $reader->unread( $hdr ) if( length( $hdr ) );
2276  
2277 0 my $chunk_size = $bufsize;
2278 0 ▶ $chunk_size = $len if( $chunk_size > $len );
Branch: 1 branch
BranchTrueFalseTotal
if $chunk_size > $len 0 0 0
2279 0 my $total_bytes = 0;
2280 0 ▶ READ_CHUNK: while( $bytes = $reader->read( $buff, $chunk_size ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($bytes = $reader->read($buff, $chunk_size)) 0 0 0
2281 {
2282 0 ▶ if( $ent->is_binary( $buff ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($ent->is_binary($buff)) { } 0 0 0
2283 {
2284 0 ▶ if( -t( STDIN ) )
Branch: 1 branch
BranchTrueFalseTotal
if (-t STDIN) { } 0 0 0
2285 {
2286 0 $self->message_colour( 5, '<green>[' . length( $buff ) . ' bytes of binary data not shown here]</>', { prefix => '<<<' } );
2287 }
2288 else
2289 {
2290 0 $self->message_colour( 5, '[' . length( $buff ) . ' bytes of binary data not shown here]', { prefix => '<<<' } );
2291 }
2292 }
2293 else
2294 {
2295 }
2296  
2297 0 my $bytes_out = $io->syswrite( $buff );
2298 0 ▶ return( $self->pass_error( $io->error ) ) if( !defined( $bytes_out ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes_out 0 0 0
2299  
2300 0 ▶ if( $bytes_out != $bytes )
Branch: 1 branch
BranchTrueFalseTotal
if ($bytes_out != $bytes) 0 0 0
2301 {
2302 0 return( $self->error( "Error writing to body $body: bytes read ($bytes) do not equate to bytes writen ($bytes_out)" ) );
2303 }
2304 0 $total_bytes += $bytes;
2305 0 ▶ last READ_CHUNK if( $total_bytes == $len );
Branch: 1 branch
BranchTrueFalseTotal
if $total_bytes == $len 0 0 0
2306 # We do not want to read more than we should
2307 0 ▶ $chunk_size = ( $len - $total_bytes ) if( ( $total_bytes < $len ) && ( ( $total_bytes + $chunk_size ) > $len ) );
Branch: 1 branch
BranchTrueFalseTotal
if $total_bytes < $len and $total_bytes + $chunk_size > $len 0 0 0
Condition0%0/3
$total_bytes < $len and $total_bytes + $chunk_size > $len
!ll&&!rl&&r
000
MC/DC0%0/2
$total_bytes < $len and $total_bytes + $chunk_size > $len
$total_bytes < $len $total_bytes + $chunk_size > $len
Truth table0%0/3
A and B
A= $total_bytes < $lenB= $total_bytes + $chunk_size > $len
ABresult
0X0
100
111
2308 }
2309 0 ▶ return( $self->error( "Error reading http body from socket: ", $reader->error ) ) if( !defined( $bytes ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes 0 0 0
2310 # consume the trailing CRLF sequence
2311 0 my $trash = $reader->read_until_in_memory( qr/${CRLF}/, include => 1 );
2312 0 ▶ return( $self->pass_error( $reader->error ) ) if( !defined( $trash ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $trash 0 0 0
2313 }
2314 0 $io->close;
2315 # consume the final CRLF sequence
2316 0 my $trash = $reader->read_until_in_memory( qr/${CRLF}/, include => 1 );
2317 # Mark body as being encoded if necessary
2318 0 ▶ $ent->is_encoded( ( defined( $enc ) && CORE::length( $enc ) ) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
defined $enc && length $enc ? : 0 0 0
Condition0%0/3
defined $enc and length $enc
!ll&&!rl&&r
000
MC/DC0%0/2
defined $enc and length $enc
defined $enc length $enc
Truth table0%0/3
A and B
A= defined $encB= length $enc
ABresult
0X0
100
111
2319 0 return( $body );
2320 }
2321  
2322 # NOTE: sub FREEZE is inherited
2323  
2324 0 ▶sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: not called CC=1 SCAR=6.9
Pod undocumented
2325  
2326 0 ▶sub STORABLE_thaw { CORE::return( CORE::shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: not called CC=1 SCAR=6.9
Pod undocumented
2327  
2328 # NOTE: sub THAW is inherited
2329  
2330 2 1;
2331 # NOTE: POD
2332 __END__
↑ Summary Promise/Request.pm »