Promise.pm

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