Promise/Message.pm

filter: Statementstmt 33.4% 190 / 568 Branchbran 20.7% 78 / 376 Conditioncond 16.3% 41 / 251 MC/DCmcdc 3.0% 4 / 130 Subroutinesub 53.8% 28 / 52 Podpod 88.8% 32 / 36 totaltotal 26.4% 373 / 1413 CC 288 SCAR 55.5
CC
288
Cov
26%
_make_parts
992.0
content
650.0
parts
650.0
CRAP 258.4
« Promise/IO.pm ↑ Summary Promise/Parser.pm »
1 ##----------------------------------------------------------------------------
2 ## Asynchronous HTTP Request and Promise - ~/lib/HTTP/Promise/Message.pm
3 ## Version v0.3.3
4 ## Copyright(c) 2025 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2022/03/21
7 ## Modified 2026/03/08
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::Message;
15 BEGIN
16 5 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 warnings::register_categories( 'HTTP::Promise' );
20 5 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶ use vars qw( $DEBUG $AUTOLOAD $CRLF $HTTP_VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 ▶ use Data::UUID;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 5 require HTTP::Promise::Headers;
24 # use Nice::Try;
25 5 ▶ use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 5 our $CRLF = "\015\012";
27 # HTTP/1.0, HTTP/1.1, HTTP/2
28 5 our $HTTP_VERSION = qr/(?<http_protocol>HTTP\/(?<http_version>(?<http_vers_major>[0-9])(?:\.(?<http_vers_minor>[0-9]))?))/;
29 5 our $VERSION = 'v0.3.3';
30 };
31  
32 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 sub init
36 28 ▶{
Subroutine init: called CC=40 SCAR=46.1
Pod documented
37 28 my $self = shift( @_ );
38 28 my( $headers, $content );
39 28 ▶ if( @_ == 1 && ref( $_[0] ) eq 'HASH' )
Branch: 3 branches
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 12 16 28
elsif (@_ >= 1 and $self->_is_array($_[0]) || $self->_is_a($_[0], 'HTTP::Promise::Headers') || $self->_is_a($_[0], 'HTTP::Headers') || !defined($_[0])) { } 11 5 16
elsif (@_ and ref $_[0] ne 'HASH') { } 0 10 10
Condition66%2/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
16012
MC/DC50%1/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
40 {
41 12 my $opts = shift( @_ );
42 12 ( $headers, $content ) = CORE::delete( @$opts{qw( headers content )} );
43 12 @_ = %$opts;
44 }
45 ▶ elsif( @_ >= 1 &&
Condition50%6/12
@_ >= 1 and $self->_is_array($_[0]) || $self->_is_a($_[0], "HTTP::Promise::Headers") || $self->_is_a($_[0], "HTTP::Headers") || !defined($_[0])
!ll&&!rl&&r
5011
$self->_is_array($_[0]) or $self->_is_a($_[0], "HTTP::Promise::Headers") or $self->_is_a($_[0], "HTTP::Headers") or not defined $_[0]
l!l&&r!l&&!r
1100
$self->_is_array($_[0]) or $self->_is_a($_[0], "HTTP::Promise::Headers") or $self->_is_a($_[0], "HTTP::Headers")
l!l&&r!l&&!r
1100
$self->_is_array($_[0]) or $self->_is_a($_[0], "HTTP::Promise::Headers")
l!l&&r!l&&!r
650
MC/DC20%1/5
@_ >= 1 and $self->_is_array($_[0]) || $self->_is_a($_[0], "HTTP::Promise::Headers") || $self->_is_a($_[0], "HTTP::Headers") || !defined($_[0])
@_ >= 1 $self->_is_array($_[0]) $self->_is_a($_[0], "HTTP::Promise::Headers") $self->_is_a($_[0], "HTTP::Headers") not defined $_[0]
Truth table50%3/6
A and B or C or D or not(E)
A= @_ >= 1B= $self->_is_array($_[0])C= $self->_is_a($_[0], "HTTP::Promise::Headers")D= $self->_is_a($_[0], "HTTP::Headers")E= not defined $_[0]
ABCDEresult
0XXXX0
100000
11XXX1
101XX1
1001X1
100011
46 ( $self->_is_array( $_[0] ) ||
47 $self->_is_a( $_[0], 'HTTP::Promise::Headers' ) ||
48 $self->_is_a( $_[0], 'HTTP::Headers' ) ||
49 # HTTP::Promise::Message->new( undef, "some\ncontent" );
50 !defined( $_[0] )
51 ) )
52 {
53 11 $headers = shift( @_ );
54 # Odd number of arguments and following argument is not an hash; or
55 # next argument is an hash
56 # this means the next parameter is the content
57 # $r->init( $headers, $content, name1 => value1, name2 => value2 );
58 # $r->init( $headers, $content, { name1 => value1, name2 => value2 } );
59 # First value must be either not a ref or a ref that stringifies
60 11 ▶ if( ( !ref( $_[0] ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (!ref($_[0]) || ref $_[0] && overload::Method($_[0], "\"\"") || $self->_is_a($_[0], "HTTP::Promise::Body") || $self->_is_a($_[0], "HTTP::Promise::Body::Form") and @_ == 1 || @_ > 2 && @_ % 2 && ref $_[1] ne "HASH" || @_ == 2 && ref $_[1] eq "HASH") 6 5 11
Condition36%11/30
!ref($_[0]) || ref $_[0] && overload::Method($_[0], "\"\"") || $self->_is_a($_[0], "HTTP::Promise::Body") || $self->_is_a($_[0], "HTTP::Promise::Body::Form") and @_ == 1 || @_ > 2 && @_ % 2 && ref $_[1] ne "HASH" || @_ == 2 && ref $_[1] eq "HASH"
!ll&&!rl&&r
506
not ref $_[0] or ref $_[0] and overload::Method($_[0], "\"\"") or $self->_is_a($_[0], "HTTP::Promise::Body") or $self->_is_a($_[0], "HTTP::Promise::Body::Form")
l!l&&r!l&&!r
605
not ref $_[0] or ref $_[0] and overload::Method($_[0], "\"\"") or $self->_is_a($_[0], "HTTP::Promise::Body")
l!l&&r!l&&!r
605
not ref $_[0] or ref $_[0] and overload::Method($_[0], "\"\"")
l!l&&r!l&&!r
605
ref $_[0] and overload::Method($_[0], "\"\"")
!ll&&!rl&&r
050
@_ == 1 or @_ > 2 and @_ % 2 and ref $_[1] ne "HASH" or @_ == 2 and ref $_[1] eq "HASH"
l!l&&r!l&&!r
600
@_ == 1 or @_ > 2 and @_ % 2 and ref $_[1] ne "HASH"
l!l&&r!l&&!r
600
@_ > 2 and @_ % 2 and ref $_[1] ne "HASH"
!ll&&!rl&&r
000
@_ > 2 and @_ % 2
!ll&&!rl&&r
000
@_ == 2 and ref $_[1] eq "HASH"
!ll&&!rl&&r
000
MC/DC9%1/11
!ref($_[0]) || ref $_[0] && overload::Method($_[0], "\"\"") || $self->_is_a($_[0], "HTTP::Promise::Body") || $self->_is_a($_[0], "HTTP::Promise::Body::Form") and @_ == 1 || @_ > 2 && @_ % 2 && ref $_[1] ne "HASH" || @_ == 2 && ref $_[1] eq "HASH"
not ref $_[0] ref $_[0] overload::Method($_[0], "\"\"") $self->_is_a($_[0], "HTTP::Promise::Body") $self->_is_a($_[0], "HTTP::Promise::Body::Form") @_ == 1 @_ > 2 @_ % 2 ref $_[1] ne "HASH" @_ == 2 ref $_[1] eq "HASH"
Truth table2%2/68
not(A) or B and C or D or E and F or G and H and I or J and K
A= not ref $_[0]B= ref $_[0]C= overload::Method($_[0], "\"\"")D= $self->_is_a($_[0], "HTTP::Promise::Body")E= $self->_is_a($_[0], "HTTP::Promise::Body::Form")F= @_ == 1G= @_ > 2H= @_ % 2I= ref $_[1] ne "HASH"J= @_ == 2K= ref $_[1] eq "HASH"
ABCDEFGHIJKresult
00X00XXXXXX0
01000XXXXXX0
1XXXX00XX0X0
1XXXX00XX100
1XXXX010X0X0
1XXXX010X100
1XXXX01100X0
1XXXX0110100
011XX00XX0X0
011XX00XX100
011XX010X0X0
011XX010X100
011XX01100X0
011XX0110100
00X1X00XX0X0
00X1X00XX100
00X1X010X0X0
00X1X010X100
00X1X01100X0
00X1X0110100
0101X00XX0X0
0101X00XX100
0101X010X0X0
0101X010X100
0101X01100X0
0101X0110100
00X0100XX0X0
00X0100XX100
00X01010X0X0
00X01010X100
00X0101100X0
00X010110100
0100100XX0X0
0100100XX100
01001010X0X0
01001010X100
0100101100X0
010010110100
1XXXX1XXXXX1
1XXXX0111XX1
1XXXX00XX111
1XXXX010X111
1XXXX0110111
011XX1XXXXX1
011XX0111XX1
011XX00XX111
011XX010X111
011XX0110111
00X1X1XXXXX1
00X1X0111XX1
00X1X00XX111
00X1X010X111
00X1X0110111
0101X1XXXXX1
0101X0111XX1
0101X00XX111
0101X010X111
0101X0110111
00X011XXXXX1
00X010111XX1
00X0100XX111
00X01010X111
00X010110111
010011XXXXX1
010010111XX1
0100100XX111
01001010X111
010010110111
61 ( ref( $_[0] ) && overload::Method( $_[0] => '""' ) ) ||
62 ( $self->_is_a( $_[0] => 'HTTP::Promise::Body' ) ) ||
63 ( $self->_is_a( $_[0] => 'HTTP::Promise::Body::Form' ) )
64 ) &&
65 (
66 @_ == 1 ||
67 # Odd number of parameters and the second one is not an hash ref:
68 # e.g.: $content, name1 => value1, name2 => value2
69 ( @_ > 2 && ( @_ % 2 ) && ref( $_[1] ) ne 'HASH' ) ||
70 # 2 params left and the second one is an hash reference:
71 # e.g.: $content, { name1 => value1, name2 => value2 }
72 ( @_ == 2 && ref( $_[1] ) eq 'HASH' )
73 )
74 )
75 {
76 6 $content = shift( @_ );
77 }
78 }
79 ▶ elsif( @_ && ref( $_[0] ) ne 'HASH' )
Condition33%1/3
@_ and ref $_[0] ne "HASH"
!ll&&!rl&&r
500
MC/DC0%0/2
@_ and ref $_[0] ne "HASH"
@_ ref $_[0] ne "HASH"
Truth table33%1/3
A and B
A= @_B= ref $_[0] ne "HASH"
ABresult
0X0
100
111
80 {
81 0 return( $self->error( "Bad header argument. I was expecting an headers object, or an hash reference, but got: ", $_[0] ) );
82 }
83
84 28 ▶ if( defined( $headers ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $headers) { } 11 17 28
85 {
86 11 ▶ if( $self->_is_a( $headers, 'HTTP::Promise::Headers' ) || $self->_is_a( $headers, 'HTTP::Headers' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_a($headers, 'HTTP::Promise::Headers') or $self->_is_a($headers, 'HTTP::Headers')) { } 5 6 11
elsif ($self->_is_array($headers)) { } 6 0 6
Condition66%2/3
$self->_is_a($headers, "HTTP::Promise::Headers") or $self->_is_a($headers, "HTTP::Headers")
l!l&&r!l&&!r
506
MC/DC50%1/2
$self->_is_a($headers, "HTTP::Promise::Headers") or $self->_is_a($headers, "HTTP::Headers")
$self->_is_a($headers, "HTTP::Promise::Headers") $self->_is_a($headers, "HTTP::Headers")
Truth table66%2/3
A or B
A= $self->_is_a($headers, "HTTP::Promise::Headers")B= $self->_is_a($headers, "HTTP::Headers")
ABresult
1X1
011
000
87 {
88 5 $headers = $headers->clone;
89 5 $headers = bless( $headers => 'HTTP::Promise::Headers' );
90 }
91 elsif( $self->_is_array( $headers ) )
92 {
93 6 $headers = HTTP::Promise::Headers->new( @$headers );
94 }
95 else
96 {
97 0 return( $self->error( "Unknown headers value passed. I was expecting an HTTP::Promise::Headers, or HTTP::Headers object or an array reference, but instead I got '$headers' (", overload::StrVal( $headers ), ")." ) );
98 }
99 }
100 else
101 {
102 17 $headers = HTTP::Promise::Headers->new;
103 }
104
105 28 ▶ if( !defined( $content ) && $headers->exists( 'Content' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $content and $headers->exists("Content")) 0 28 28
Condition66%2/3
not defined $content and $headers->exists("Content")
!ll&&!rl&&r
6220
MC/DC0%0/2
not defined $content and $headers->exists("Content")
not defined $content $headers->exists("Content")
Truth table66%2/3
not(A) and B
A= not defined $contentB= $headers->exists("Content")
ABresult
0X0
100
111
106 {
107 0 ( $content ) = $headers->remove_header( 'Content' );
108 # $content = $headers->header( 'Content' );
109 # $headers->remove_header( 'Content' );
110 }
111
112 28 ▶ if( defined( $content ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content) 6 22 28
113 {
114 6 ▶ $self->_utf8_downgrade( $content ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_utf8_downgrade($content) or return $self->pass_error 6 0 6
115 }
116
117 # $self->{content} = $content;
118 28 ▶ $self->{entity} = undef unless( CORE::exists( $self->{entity} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"entity"} 28 0 28
119 28 $self->{headers} = $headers;
120 28 ▶ $self->{protocol} = undef unless( exists( $self->{protocol} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"protocol"} 28 0 28
121 28 ▶ $self->{version} = '' unless( exists( $self->{version} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"version"} 26 2 28
122 28 $self->{_init_strict_use_sub} = 1;
123 28 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 28 0 28
124 28 my $ent = $self->entity;
125 28 ▶ unless( $ent )
Branch: 1 branch
BranchTrueFalseTotal
unless ($ent) 28 0 28
126 {
127 28 ▶ $self->_load_class( 'HTTP::Promise::Entity' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Entity") or return $self->pass_error 28 0 28
128 28 $ent = HTTP::Promise::Entity->new( headers => $headers, debug => $self->debug );
129 28 $self->entity( $ent );
130 }
131 28 $ent->http_message( $self );
132 28 $ent->debug( $self->debug );
133 28 $headers->debug( $self->debug );
134
135 # Even if it is zero bytes big, we still create the body
136 # If a $content was provided, we store it in a in-memory body
137 # If the user
138 28 ▶ if( defined( $content ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content) 6 22 28
139 {
140 6 ▶ if( $self->_is_a( $content => [qw( HTTP::Promise::Body HTTP::Promise::Body::Form )] ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($content, ['HTTP::Promise::Body', 'HTTP::Promise::Body::Form'])) { } 0 6 6
141 {
142 0 ▶ $ent->body( $content ) || return( $self->pass_error( $ent->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$ent->body($content) or return $self->pass_error($ent->error) 0 0 0
143 }
144 else
145 {
146 6 my $body = $ent->new_body( string => \$content );
147 6 ▶ return( $self->pass_error( $ent->error ) ) if( !defined( $body ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $body 0 6 6
148 6 $ent->body( $body );
149 }
150 # If Content-Encoding is set, then set is_encoded to true
151 6 ▶ if( $headers->content_encoding->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($headers->content_encoding->length) 2 4 6
152 {
153 2 $ent->is_encoded(1);
154 }
155 }
156 # There is no parts in this object. Everything is held in HTTP::Promise::Entity
157 # $self->{_parts} = [];
158 28 return( $self );
159 }
160  
161 sub add_content
162 0 ▶{
Subroutine add_content: not called CC=9 SCAR=45.0
Pod documented
163 0 my $self = shift( @_ );
164 0 ▶ if( defined( $_[0] ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]) 0 0 0
165 {
166 0 ▶ $self->_utf8_downgrade( $self->_is_scalar( $_[0] ) ? ${$_[0]} : $_[0] ) ||
Branch: 2 branches
BranchTrueFalseTotal
$self->_utf8_downgrade($self->_is_scalar($_[0]) ? ${$_[0];} : $_[0]) or return $self->pass_error 0 0 0
$self->_is_scalar($_[0]) ? : 0 0 0
167 return( $self->pass_error );
168 }
169 0 my( $ent, $body );
170 0 ▶ unless( $ent = $self->entity )
Branch: 1 branch
BranchTrueFalseTotal
unless ($ent = $self->entity) 0 0 0
171 {
172 0 ▶ $self->_load_class( 'HTTP::Promise::Entity' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Entity") or return $self->pass_error 0 0 0
173 0 $ent = HTTP::Promise::Entity->new( debug => $self->debug );
174 }
175
176 0 $body = $ent->body;
177 0 ▶ if( $body )
Branch: 1 branch
BranchTrueFalseTotal
if ($body) { } 0 0 0
178 {
179 0 ▶ return( $self->error( "Unable to append to an entity body other than a HTTP::Promise::Body::Scalar" ) ) if( !$self->_is_a( $body => 'HTTP::Promise::Body::Scalar' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($body, "HTTP::Promise::Body::Scalar") 0 0 0
180 0 $body->append( $_[0] );
181 }
182 else
183 {
184 0 ▶ $body = $ent->new_body( string => $_[0] ) ||
Condition0%0/2
$ent->new_body('string', $_[0]) || (return $self->pass_error($ent->error))
l!l
00
MC/DC0%0/1
$ent->new_body('string', $_[0]) || (return $self->pass_error($ent->error))
$ent->new_body('string', $_[0])
Truth table0%0/2
A
A= $ent->new_body('string', $_[0])
Aresult
11
00
185 return( $self->pass_error( $ent->error ) );
186 0 $ent->body( $body );
187 }
188 0 return( $body );
189 }
190  
191 sub add_content_utf8
192 0 ▶{
Subroutine add_content_utf8: not called CC=1 SCAR=6.9
Pod documented
193 0 my( $self, $buff ) = @_;
194 0 utf8::upgrade( $buff );
195 0 utf8::encode( $buff );
196 0 return( $self->add_content( $buff ) );
197 }
198  
199 # Adding part will automatically makes it a multipart/form-data if not set already
200 # There is no such thing as multipart/mixed in HTTP
201 sub add_part
202 0 ▶{
Subroutine add_part: not called CC=21 SCAR=61.4
Pod documented
203 0 my $self = shift( @_ );
204 0 my $ent = $self->entity;
205 0 my $headers = $self->headers;
206 0 ▶ unless( $ent )
Branch: 1 branch
BranchTrueFalseTotal
unless ($ent) 0 0 0
207 {
208 0 ▶ $self->_load_class( 'HTTP::Promise::Entity' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Entity") or return $self->pass_error 0 0 0
209 0 $ent = HTTP::Promise::Entity->new( headers => $headers, debug => $self->debug );
210 0 $self->entity( $ent );
211 }
212 0 ▶ if( ( $self->content_type || '' ) !~ m,^multipart/, )
Branch: 3 branches
BranchTrueFalseTotal
if (not +($self->content_type || '') =~ m[^multipart/]) { } 0 0 0
elsif ($ent->parts->is_empty and ($ent->body and not $ent->body->is_empty)) { } 0 0 0
elsif ($self->content_type->index('boundary') == -1) { } 0 0 0
Condition0%0/2
$self->content_type || ''
l!l
00
MC/DC0%0/1
$self->content_type || ''
$self->content_type
Truth table0%0/2
A
A= $self->content_type
Aresult
11
00
213 {
214 0 ▶ $ent->make_multipart( 'form-data' ) || return( $self->pass_error( $ent->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$ent->make_multipart("form-data") or return $self->pass_error($ent->error) 0 0 0
215 }
216 # elsif( $self->_parts->is_empty && ( $self->entity && $self->entity->body && !$self->entity->body->is_empty ) )
217 ▶ elsif( $ent->parts->is_empty && ( $ent->body && !$ent->body->is_empty ) )
Condition0%0/6
$ent->parts->is_empty and ($ent->body and not $ent->body->is_empty)
!ll&&!rl&&r
000
$ent->body and not $ent->body->is_empty
!ll&&!rl&&r
000
MC/DC0%0/3
$ent->parts->is_empty and ($ent->body and not $ent->body->is_empty)
$ent->parts->is_empty $ent->body not $ent->body->is_empty
Truth table0%0/4
A and B and not(C)
A= $ent->parts->is_emptyB= $ent->bodyC= not $ent->body->is_empty
ABCresult
0XX0
10X0
1100
1111
218 {
219 # Should really use HTTP::Promise::Entity->make_multipart
220 0 $self->_make_parts;
221 }
222 elsif( $self->content_type->index( 'boundary' ) == -1 )
223 {
224 0 my $ct = $headers->new_field( 'Content-Type' => $self->content_type );
225 0 $ct->boundary( $self->make_boundary );
226 0 $self->content_type( $ct );
227 }
228
229 0 my @new = ();
230 0 my $name;
231 0 ▶ for( my $i = 0; $i < scalar( @_ ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @_) 0 0 0
232 {
233 0 my $this = $_[$i];
234 # If this is a string or a scalar reference
235 0 ▶ if( defined( $this ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $this and !ref($this) || $self->_is_scalar($this) && overload::Method($this, "\"\"")) 0 0 0
Condition0%0/9
defined $this and !ref($this) || $self->_is_scalar($this) && overload::Method($this, "\"\"")
!ll&&!rl&&r
000
not ref $this or $self->_is_scalar($this) and overload::Method($this, "\"\"")
l!l&&r!l&&!r
000
$self->_is_scalar($this) and overload::Method($this, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/4
defined $this and !ref($this) || $self->_is_scalar($this) && overload::Method($this, "\"\"")
defined $this not ref $this $self->_is_scalar($this) overload::Method($this, "\"\"")
Truth table0%0/5
A and not(B) or C and D
A= defined $thisB= not ref $thisC= $self->_is_scalar($this)D= overload::Method($this, "\"\"")
ABCDresult
0XXX0
100X0
10100
11XX1
10111
236 ( !ref( $this ) || ( $self->_is_scalar( $this ) && overload::Method( $this => '""' ) ) ) )
237 {
238 0 $name = $this;
239 0 next;
240 }
241
242 # Either a HTTP::Promise::Request, or a HTTP::Promise::Response, or even a HTTP::Promise::Message
243 0 ▶ unless( $self->_is_a( $this => 'HTTP::Promise::Entity' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($this, "HTTP::Promise::Entity")) 0 0 0
244 {
245 0 ▶ return( $self->error( "Part object provided (", overload::StrVal( $this ), ") is neither a HTTP::Promise::Entity or a HTTP::Promise::Message object." ) ) if( !$self->_is_a( $this => 'HTTP::Promise::Message' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($this, "HTTP::Promise::Message") 0 0 0
246 0 my $part_ent = $this->entity;
247 0 ▶ unless( $part_ent )
Branch: 1 branch
BranchTrueFalseTotal
unless ($part_ent) 0 0 0
248 {
249 0 ▶ $part_ent = HTTP::Promise::Entity->new( headers => $this->headers, debug => $self->debug ) ||
Condition0%0/2
'HTTP::Promise::Entity'->new('headers', $this->headers, 'debug', $self->debug) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
'HTTP::Promise::Entity'->new('headers', $this->headers, 'debug', $self->debug) || (return $self->pass_error)
'HTTP::Promise::Entity'->new('headers', $this->headers, 'debug', $self->debug)
Truth table0%0/2
A
A= 'HTTP::Promise::Entity'->new('headers', $this->headers, 'debug', $self->debug)
Aresult
11
00
250 return( $self->pass_error );
251 0 $this->entity( $part_ent );
252 }
253 0 ▶ $part_ent->name( $name ) if( defined( $name ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 0 0 0
254 0 push( @new, $part_ent );
255 0 undef( $name );
256 0 next;
257 }
258 0 ▶ $this->name( $name ) if( defined( $name ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 0 0 0
259 0 undef( $name );
260 0 push( @new, $this );
261 }
262
263 0 $ent->parts->push( @new );
264 0 return( $self );
265 }
266  
267 sub as_form_data
268 0 ▶{
Subroutine as_form_data: not called CC=14 SCAR=53.5
Pod documented
269 0 my( $self, $eol ) = @_;
270 0 my $type = $self->headers->type;
271 0 ▶ $type = 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
272 0 ▶ $self->_load_class( 'HTTP::Promise::Body::Form' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Body::Form") or return $self->pass_error 0 0 0
273 0 my $payload = $self->decoded_content_utf8->scalar;
274 0 my $uri;
275 0 ▶ if( $type eq 'multipart/form-data' )
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'multipart/form-data') { } 0 0 0
elsif ($type eq 'application/json') { } 0 0 0
elsif ($self->can('uri') and $uri = $self->uri and $uri->query and not defined $payload && length $payload) { } 0 0 0
276 {
277 0 return( $self->entity->as_form_data );
278 }
279 elsif( $type eq 'application/json' )
280 {
281 0 ▶ return( HTTP::Promise::Body::Form->new ) unless( length( $payload ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $payload 0 0 0
282 0 my $form;
283 # try-catch
284 0 local $@;
285 eval
286 0 {
287 0 my $hash = $self->new_json->decode( $payload );
288 0 $form = HTTP::Promise::Body::Form->new( $hash );
289 };
290 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
291 {
292 0 return( $self->error( "Error trying to decode the JSON payload: $@" ) );
293 }
294 0 return( $form );
295 }
296 ▶ elsif( $self->can( 'uri' ) &&
Condition0%0/12
$self->can("uri") and $uri = $self->uri and $uri->query and not defined $payload && length $payload
!ll&&!rl&&r
000
$self->can("uri") and $uri = $self->uri and $uri->query
!ll&&!rl&&r
000
$self->can("uri") and $uri = $self->uri
!ll&&!rl&&r
000
defined $payload && length $payload
!ll&&!rl&&r
000
MC/DC0%0/5
$self->can("uri") and $uri = $self->uri and $uri->query and not defined $payload && length $payload
$self->can("uri") $uri = $self->uri $uri->query defined $payload length $payload
Truth table0%0/6
A and B and C and not(D && E)
A= $self->can("uri")B= $uri = $self->uriC= $uri->queryD= defined $payloadE= length $payload
ABCDEresult
0XXXX0
10XXX0
110XX0
111110
1110X1
111101
297 ( $uri = $self->uri ) &&
298 $uri->query &&
299 ( !defined( $payload ) || !length( $payload ) ) )
300 {
301 0 my $hash = $uri->query_form_hash;
302 0 return( HTTP::Promise::Body::Form->new( $hash ) );
303 }
304 # elsif( $type eq 'application/x-www-form-urlencoded' )
305 else
306 {
307 0 ▶ return( length( $payload // '' ) ? HTTP::Promise::Body::Form->new( $payload ) : HTTP::Promise::Body::Form->new );
Branch: 1 branch
BranchTrueFalseTotal
length($payload // '') ? : 0 0 0
Condition0%0/2
$payload // ""
l!l
00
MC/DC0%0/1
$payload // ""
$payload
Truth table0%0/2
A
A= $payload
Aresult
11
00
308 }
309 }
310  
311 sub as_string
312 3 ▶{
Subroutine as_string: called CC=3 SCAR=11.4
Pod documented
313 3 my( $self, $eol ) = @_;
314 3 ▶ $eol = $CRLF unless( defined( $eol ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $eol 3 0 3
315 3 my $ent = $self->entity;
316 # If there is no entity, we just print the headers and that's it.
317 3 ▶ return( $ent ? $ent->as_string( $eol ) : join( $eol, $self->start_line( $eol ), $self->headers->as_string( $eol ) ) . $eol );
Branch: 1 branch
BranchTrueFalseTotal
$ent ? : 3 0 3
318 }
319  
320 0 ▶sub boundary { return( shift->headers->boundary ); }
Subroutine boundary: not called CC=1 SCAR=6.9
Pod documented
321  
322 sub can
323 29 ▶{
Subroutine can: called CC=6 SCAR=19.9
Pod documented
324 29 my( $self, $method ) = @_;
325  
326 29 ▶ if( my $own_method = $self->SUPER::can( $method ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $own_method = $self->SUPER::can($method)) 26 3 29
327 {
328 26 return( $own_method );
329 }
330  
331 3 ▶ my $headers = ref( $self ) ? $self->headers : 'HTTP::Promise::Headers';
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 3 0 3
332 3 my $trace = '';
333 3 ▶ my $debug = $self->debug // 0;
Condition50%1/2
$self->debug // 0
l!l
03
MC/DC0%0/1
$self->debug // 0
$self->debug
Truth table50%1/2
A
A= $self->debug
Aresult
11
00
334 3 ▶ if( $headers->can( $method ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($headers->can($method)) { } 0 3 3
335 {
336 # We create the function here so that it will not need to be
337 # autoloaded or recreated the next time.
338 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
339 0 eval( <<EOT );
340 sub $method { return( shift->headers->$method( \@_ ) ); }
341 EOT
342 0 ▶ my $ref = $self->UNIVERSAL::can( $method ) || die( "AUTOLOAD inconsistency error for dynamic sub \"$method\"." );
Condition0%0/2
$self->UNIVERSAL::can($method) || die(qq[AUTOLOAD inconsistency error for dynamic sub "$method".])
l!l
00
MC/DC0%0/1
$self->UNIVERSAL::can($method) || die(qq[AUTOLOAD inconsistency error for dynamic sub "$method".])
$self->UNIVERSAL::can($method)
Truth table0%0/2
A
A= $self->UNIVERSAL::can($method)
Aresult
11
00
343 0 return( $ref );
344 }
345 else
346 {
347 }
348 3 return;
349 }
350  
351 sub clear
352 0 ▶{
Subroutine clear: not called CC=4 SCAR=30.0
Pod documented
353 0 my $self = shift( @_ );
354 0 $self->headers->clear;
355 0 ▶ $self->entity->body->empty if( $self->entity && $self->entity->body );
Branch: 1 branch
BranchTrueFalseTotal
if $self->entity and $self->entity->body 0 0 0
Condition0%0/3
$self->entity and $self->entity->body
!ll&&!rl&&r
000
MC/DC0%0/2
$self->entity and $self->entity->body
$self->entity $self->entity->body
Truth table0%0/3
A and B
A= $self->entityB= $self->entity->body
ABresult
0X0
100
111
356 # $self->_parts->reset;
357 0 ▶ $self->entity->parts->reset if( $self->entity );
Branch: 1 branch
BranchTrueFalseTotal
if $self->entity 0 0 0
358 0 return;
359 }
360  
361 sub clone
362 0 ▶{
Subroutine clone: not called CC=8 SCAR=42.8
Pod documented
363 0 my $self = shift( @_ );
364 0 my $opts = $self->_get_args_as_hash( @_ );
365 0 ▶ $opts->{clone_entity} //= 1;
Condition0%0/2
$opts->{"clone_entity"} //= 1
l!l
00
MC/DC0%0/1
$opts->{"clone_entity"} //= 1
$opts->{"clone_entity"}
Truth table0%0/2
A
A= $opts->{"clone_entity"}
Aresult
11
00
366 # my $new = $self->new( [], undef );
367 0 my $new = $self->SUPER::clone;
368 0 my $new_headers;
369 my $ent;
370 0 ▶ if( ( $ent = $self->entity ) && $opts->{clone_entity} )
Branch: 1 branch
BranchTrueFalseTotal
if ($ent = $self->entity and $opts->{'clone_entity'}) { } 0 0 0
Condition0%0/3
$ent = $self->entity and $opts->{"clone_entity"}
!ll&&!rl&&r
000
MC/DC0%0/2
$ent = $self->entity and $opts->{"clone_entity"}
$ent = $self->entity $opts->{"clone_entity"}
Truth table0%0/3
A and B
A= $ent = $self->entityB= $opts->{"clone_entity"}
ABresult
0X0
100
111
371 {
372 0 my $new_ent = $ent->clone( clone_message => 0 );
373 0 $new_headers = $new_ent->headers;
374 0 $new_ent->http_message( $new );
375 0 $new->entity( $new_ent );
376 }
377 else
378 {
379 0 $new_headers = $self->headers->clone;
380 }
381 0 $new->headers( $new_headers );
382 0 my $proto = $self->protocol;
383 0 my $vers = $self->version;
384 0 ▶ $new->protocol( "$proto" ) if( defined( $proto ) && length( $proto ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $proto and length $proto 0 0 0
Condition0%0/3
defined $proto and length $proto
!ll&&!rl&&r
000
MC/DC0%0/2
defined $proto and length $proto
defined $proto length $proto
Truth table0%0/3
A and B
A= defined $protoB= length $proto
ABresult
0X0
100
111
385 0 ▶ $new->version( "$vers" ) if( defined( $vers ) && length( $vers ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $vers and length $vers 0 0 0
Condition0%0/3
defined $vers and length $vers
!ll&&!rl&&r
000
MC/DC0%0/2
defined $vers and length $vers
defined $vers length $vers
Truth table0%0/3
A and B
A= defined $versB= length $vers
ABresult
0X0
100
111
386 0 $new->debug( $self->debug );
387 0 return( $new );
388 }
389  
390 sub content
391 0 ▶{
Subroutine content: not called CC=25 SCAR=64.8
Pod documented
392 0 my $self = shift( @_ );
393 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
394 {
395 0 my $has_ref = 0;
396 0 for( @_ )
397 {
398 0 ▶ next unless( defined( $_ ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 0 0
399 0 ▶ return( $self->error( "I was expecting a string or a scalar reference, but instead got ", ref( $_ ) ) ) if( ref( $_ ) && !$self->_is_scalar( $_ ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ and not $self->_is_scalar($_) 0 0 0
Condition0%0/3
ref $_ and not $self->_is_scalar($_)
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_ and not $self->_is_scalar($_)
ref $_ not $self->_is_scalar($_)
Truth table0%0/3
A and not(B)
A= ref $_B= not $self->_is_scalar($_)
ABresult
0X0
100
111
400 # This affects how we set the content
401 0 ▶ $has_ref++ if( $self->_is_scalar( $_ ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_scalar($_) 0 0 0
402 0 ▶ $self->_utf8_downgrade( $self->_is_scalar( $_ ) ? $$_ : $_ ) ||
Branch: 2 branches
BranchTrueFalseTotal
$self->_utf8_downgrade($self->_is_scalar($_) ? $$_ : $_) or return $self->pass_error 0 0 0
$self->_is_scalar($_) ? : 0 0 0
403 return( $self->pass_error );
404 }
405 # $self->_parts->reset;
406 0 my $ent = $self->entity;
407 0 ▶ unless( $ent )
Branch: 1 branch
BranchTrueFalseTotal
unless ($ent) 0 0 0
408 {
409 0 my $headers = $self->headers;
410 0 ▶ $self->_load_class( 'HTTP::Promise::Entity' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Entity") or return $self->pass_error 0 0 0
411 0 $ent = HTTP::Promise::Entity->new( headers => $headers, debug => $self->debug );
412 0 $self->entity( $ent );
413 }
414 0 my $body = $ent->body;
415 0 ▶ unless( $body )
Branch: 1 branch
BranchTrueFalseTotal
unless ($body) 0 0 0
416 {
417 0 $body = $ent->new_body( string => '' );
418 0 ▶ return( $self->pass_error( $ent->error ) ) if( !defined( $body ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $body 0 0 0
419 # $ent->body( $body ) || return( $self->pass_error( $ent->error ) );
420 0 my $rv = $ent->body( $body );
421 0 ▶ if( !defined( $rv ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $rv) 0 0 0
422 {
423 }
424 0 ▶ return( $self->pass_error( $ent->error ) ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 0 0
425 }
426
427 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
428 return( $self->pass_error( $body->error ) );
429 0 ▶ if( $has_ref > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_ref > 1) { } 0 0 0
430 {
431 0 for( @_ )
432 {
433 0 ▶ $io->print( $self->_is_scalar( $_ ) ? $$_ : $_ ) || return( $self->pass_error( $io->error ) );
Branch: 2 branches
BranchTrueFalseTotal
$io->print($self->_is_scalar($_) ? $$_ : $_) or return $self->pass_error($io->error) 0 0 0
$self->_is_scalar($_) ? : 0 0 0
434 }
435 }
436 else
437 {
438 0 ▶ $io->print( ( @_ == 1 && $self->_is_scalar( $_[0] ) ) ? ${$_[0]} : @_ ) || return( $self->pass_error( $io->error ) );
Branch: 2 branches
BranchTrueFalseTotal
$io->print(@_ == 1 && $self->_is_scalar($_[0]) ? ${$_[0];} : @_) or return $self->pass_error($io->error) 0 0 0
@_ == 1 && $self->_is_scalar($_[0]) ? : 0 0 0
Condition0%0/3
@_ == 1 and $self->_is_scalar($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and $self->_is_scalar($_[0])
@_ == 1 $self->_is_scalar($_[0])
Truth table0%0/3
A and B
A= @_ == 1B= $self->_is_scalar($_[0])
ABresult
0X0
100
111
439 }
440 0 $io->close;
441 0 $ent->parts->reset;
442 0 return( $body );
443 }
444 else
445 {
446 0 my $ent = $self->entity;
447 0 ▶ return( '' ) if( !$ent );
Branch: 1 branch
BranchTrueFalseTotal
unless $ent 0 0 0
448 0 my $body = $ent->body;
449 0 ▶ return( '' ) if( !$body );
Branch: 1 branch
BranchTrueFalseTotal
unless $body 0 0 0
450 # This is a real bad idea if the body is huge...
451 # NOTE: content() returns a scalar object (Module::Generic::Scalar)
452 0 return( $body->as_string );
453 }
454 }
455  
456 # NOTE: an outdated method since nowadays everyone use UTF-8
457 sub content_charset
458 0 ▶{
Subroutine content_charset: not called CC=2 SCAR=17.9
Pod documented
459 0 my $self = shift( @_ );
460 0 my $ent = $self->entity;
461 0 ▶ return( '' ) unless( $ent );
Branch: 1 branch
BranchTrueFalseTotal
unless $ent 0 0 0
462 0 return( $ent->content_charset );
463 }
464  
465 sub content_ref
466 0 ▶{
Subroutine content_ref: not called CC=3 SCAR=24.8
Pod documented
467 0 my $self = shift( @_ );
468 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
469 {
470 0 ▶ return( $self->error( "Value provided is not a scalar reference." ) ) unless( $self->_is_scalar( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_scalar($_[0]) 0 0 0
471 0 return( $self->content( @_ ) );
472 }
473 else
474 {
475 0 my $content = $self->content;
476 0 return( $content );
477 }
478 }
479  
480 sub decodable
481 1 ▶{
Subroutine decodable: called CC=3 SCAR=11.3
Pod documented
482 1 my $self = shift( @_ );
483 1 local $@;
484 1 ▶ $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 1 0 1
485 1 ▶ my $all = HTTP::Promise::Stream->decodable( 'browser' ) ||
Condition50%1/2
'HTTP::Promise::Stream'->decodable('browser') || (return $self->error('HTTP::Promise::Stream'->pass_error))
l!l
10
MC/DC0%0/1
'HTTP::Promise::Stream'->decodable('browser') || (return $self->error('HTTP::Promise::Stream'->pass_error))
'HTTP::Promise::Stream'->decodable('browser')
Truth table50%1/2
A
A= 'HTTP::Promise::Stream'->decodable('browser')
Aresult
11
00
486 return( $self->error( HTTP::Promise::Stream->pass_error ) );
487 1 return( $all );
488 }
489  
490 sub decode
491 0 ▶{
Subroutine decode: not called CC=6 SCAR=37.4
Pod documented
492 0 my $self = shift( @_ );
493 0 my $headers = $self->headers;
494 0 my $ce = $headers->content_encoding;
495 0 ▶ return(1) if( !$ce || $ce->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if not $ce or $ce->is_empty 0 0 0
Condition0%0/3
not $ce or $ce->is_empty
l!l&&r!l&&!r
000
MC/DC0%0/2
not $ce or $ce->is_empty
not $ce $ce->is_empty
Truth table0%0/3
not(A) or B
A= not $ceB= $ce->is_empty
ABresult
1X1
011
000
496 0 ▶ my $ent = $self->entity || return(1);
Condition0%0/2
$self->entity || (return 1)
l!l
00
MC/DC0%0/1
$self->entity || (return 1)
$self->entity
Truth table0%0/2
A
A= $self->entity
Aresult
11
00
497 0 my $encodings = $ce->split( qr/[[:blank:]]*,[[:blank:]]*/ )->reverse->object;
498 0 ▶ return(1) if( $encodings->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $encodings->is_empty 0 0 0
499 0 ▶ my $body = $ent->decode_body( $encodings ) || return( $self->pass_error( $ent->error ) );
Condition0%0/2
$ent->decode_body($encodings) || (return $self->pass_error($ent->error))
l!l
00
MC/DC0%0/1
$ent->decode_body($encodings) || (return $self->pass_error($ent->error))
$ent->decode_body($encodings)
Truth table0%0/2
A
A= $ent->decode_body($encodings)
Aresult
11
00
500 # Altering existing headers value is really really bad. This is done in HTTP::Message,
501 # but not in our class
502 # $self->remove_header( qw( Content-Encoding Content-Length Content-MD5 ) );
503 0 return(1);
504 }
505  
506 sub decode_content
507 4 ▶{
Subroutine decode_content: called CC=7 SCAR=29.2
Pod documented
508 4 my $self = shift( @_ );
509 4 ▶ my $ent = $self->entity || return(0);
Condition50%1/2
$self->entity || (return 0)
l!l
40
MC/DC0%0/1
$self->entity || (return 0)
$self->entity
Truth table50%1/2
A
A= $self->entity
Aresult
11
00
510 4 my $opts = $self->_get_args_as_hash( @_ );
511 4 ▶ my $body = $ent->body || return(0);
Condition50%1/2
$ent->body || (return 0)
l!l
40
MC/DC0%0/1
$ent->body || (return 0)
$ent->body
Truth table50%1/2
A
A= $ent->body
Aresult
11
00
512 4 ▶ return( $body ) if( !$ent->is_encoded );
Branch: 1 branch
BranchTrueFalseTotal
unless $ent->is_encoded 4 0 4
513 0 my $ce = $self->headers->content_encoding;
514 0 ▶ if( $ce )
Branch: 1 branch
BranchTrueFalseTotal
if ($ce) 0 0 0
515 {
516 # object(9 is a noop to ensure an object is returned and not a list
517 0 ▶ $body = $ent->decode_body( $ce->split( qr/[[:blank:]\h]*\,[[:blank:]\h]*/ )->reverse->object, ( scalar( keys( %$opts ) ) ? $opts : () ) ) || return( $self->pass_error( $ent->error ) );
Branch: 1 branch
BranchTrueFalseTotal
scalar keys %$opts ? : 0 0 0
Condition0%0/2
$ent->decode_body($ce->split(qr/[[:blank:]\h]*\,[[:blank:]\h]*/)->reverse->object, scalar keys %$opts ? $opts : ()) || (return $self->pass_error($ent->error))
l!l
00
MC/DC0%0/1
$ent->decode_body($ce->split(qr/[[:blank:]\h]*\,[[:blank:]\h]*/)->reverse->object, scalar keys %$opts ? $opts : ()) || (return $self->pass_error($ent->error))
$ent->decode_body($ce->split(qr/[[:blank:]\h]*\,[[:blank:]\h]*/)->reverse->object, scalar keys %$opts ? $opts : ())
Truth table0%0/2
A
A= $ent->decode_body($ce->split(qr/[[:blank:]\h]*\,[[:blank:]\h]*/)->reverse->object, scalar keys %$opts ? $opts : ())
Aresult
11
00
518 # $ent->is_decoded(1);
519 }
520 0 return( $body );
521 }
522  
523 sub decoded_content
524 4 ▶{
Subroutine decoded_content: called CC=20 SCAR=37.2
Pod documented
525 4 my $self = shift( @_ );
526 4 my $opts = $self->_get_args_as_hash( @_ );
527 4 ▶ $opts->{charset_strict} //= 0;
Condition50%1/2
$opts->{"charset_strict"} //= 0
l!l
04
MC/DC0%0/1
$opts->{"charset_strict"} //= 0
$opts->{"charset_strict"}
Truth table50%1/2
A
A= $opts->{"charset_strict"}
Aresult
11
00
528 4 my $old_fatal = $self->fatal;
529 4 ▶ $self->fatal( $opts->{raise_error} ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'raise_error'} ? : 0 4 4
530 4 ▶ my $body = $self->decode_content( ( scalar( keys( %$opts ) ) ? $opts : () ) );
Branch: 1 branch
BranchTrueFalseTotal
scalar keys %$opts ? : 4 0 4
531 4 ▶ return( $self->pass_error ) if( !defined( $body ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $body 0 4 4
532 # There is no entity or no body
533 4 ▶ if( !$body )
Branch: 1 branch
BranchTrueFalseTotal
unless ($body) 0 4 4
534 {
535 0 return( $self->new_scalar );
536 }
537 4 $self->fatal( $old_fatal );
538 4 my $dummy = '';
539 4 ▶ return( $opts->{ref} ? \$dummy : $dummy ) if( $body->is_empty );
Branch: 2 branches
BranchTrueFalseTotal
if $body->is_empty 0 4 4
$opts->{'ref'} ? : 0 0 0
540 4 ▶ unless( $opts->{binmode} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"binmode"}) 4 0 4
541 {
542 # Need to explicitly provide the body to get the encoding from, otherwise, io_encoding()
543 # would get the default one, which might not yet be replaced with its decoded version.
544 4 my $enc = $self->entity->io_encoding( body => $body, charset_strict => $opts->{charset_strict} );
545 4 ▶ $opts->{binmode} = $enc if( $enc );
Branch: 1 branch
BranchTrueFalseTotal
if $enc 4 0 4
546 }
547
548 # Because of an edge case where open with :binmode(utf-8) layer does not decode properly \x{FF}
549 # but Encode::decode( 'utf-8', $buff ) does, and since the body is loaded into a string
550 # anyway, we first read the data as raw and then decode it with Encode
551 4 my $binmode;
552 4 ▶ if( exists( $opts->{binmode} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"binmode"} and length $opts->{"binmode"} and lc substr($opts->{"binmode"}, 0, 3) eq "utf") 4 0 4
Condition33%2/6
exists $opts->{"binmode"} and length $opts->{"binmode"} and lc substr($opts->{"binmode"}, 0, 3) eq "utf"
!ll&&!rl&&r
004
exists $opts->{"binmode"} and length $opts->{"binmode"}
!ll&&!rl&&r
004
MC/DC0%0/3
exists $opts->{"binmode"} and length $opts->{"binmode"} and lc substr($opts->{"binmode"}, 0, 3) eq "utf"
exists $opts->{"binmode"} length $opts->{"binmode"} lc substr($opts->{"binmode"}, 0, 3) eq "utf"
Truth table25%1/4
A and B and C
A= exists $opts->{"binmode"}B= length $opts->{"binmode"}C= lc substr($opts->{"binmode"}, 0, 3) eq "utf"
ABCresult
0XX0
10X0
1100
1111
553 length( $opts->{binmode} ) &&
554 lc( substr( $opts->{binmode}, 0, 3 ) ) eq 'utf' )
555 {
556 4 $binmode = delete( $opts->{binmode} );
557 4 $opts->{binmode} = 'raw';
558 }
559 4 ▶ my $content = $body->as_string( ( scalar( keys( %$opts ) ) ? $opts : () ) );
Branch: 1 branch
BranchTrueFalseTotal
scalar keys %$opts ? : 4 0 4
560 4 ▶ if( !defined( $content ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $content) 0 4 4
561 {
562 0 return( $self->pass_error( $body->error ) );
563 }
564 4 ▶ if( defined( $binmode ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $binmode) 4 0 4
565 {
566 4 ▶ $self->_load_class( 'Encode' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Encode") or return $self->pass_error 4 0 4
567 # try-catch
568 4 local $@;
569 eval
570 4 {
571 4 $$content = Encode::decode( $binmode, $$content, ( Encode::FB_DEFAULT | Encode::LEAVE_SRC ) );
572 };
573 4 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 4 4
574 {
575 0 return( $self->error( "Error decoding body content with character encoding '$binmode': $@" ) );
576 }
577 }
578
579 # $content is a scalar object that stringifies
580 4 ▶ if( $self->headers->content_is_xml )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->headers->content_is_xml) 0 4 4
581 {
582 # Get rid of the XML encoding declaration if present (\x{FEFF})
583 0 ▶ $$content =~ s/^\N{BOM}//;
Subroutine BEGIN: called CC=1 SCAR=0.2
584 0 ▶ if( $$content =~ m/^(?<decl>[[:blank:]\h\v]*<\?xml(.*?)\?>)/is )
Branch: 1 branch
BranchTrueFalseTotal
if ($$content =~ /^(?<decl>[[:blank:]\h\v]*<\?xml(.*?)\?>)/is) 0 0 0
585 {
586 0 substr( $$content, 0, length( $+{decl} ) ) =~ s{
587 [[:blank:]\h\v]+
588 encoding[[:blank:]\h\v]*=[[:blank:]\h\v]*
589 (?<quote>["'])
590 (?<encoding>(?>\\\g{quote}|(?!\g{quote}).)*+)
591 \g{quote}
592 }
593 {}xmis;
594 }
595 }
596 4 return( $content );
597 }
598  
599 sub decoded_content_utf8
600 0 ▶{
Subroutine decoded_content_utf8: not called CC=5 SCAR=34.0
Pod documented
601 0 my $self = shift( @_ );
602 0 my $opts = $self->_get_args_as_hash( @_ );
603 0 $opts->{binmode} = 'utf-8';
604 0 my $data = $self->decoded_content( $opts );
605 0 ▶ if( !defined( $data ) && $self->error )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $data and $self->error) 0 0 0
Condition0%0/3
not defined $data and $self->error
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $data and $self->error
not defined $data $self->error
Truth table0%0/3
not(A) and B
A= not defined $dataB= $self->error
ABresult
0X0
100
111
606 {
607 0 return( $self->pass_error );
608 }
609  
610 0 ▶ if( $self->headers->content_is_xml )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->headers->content_is_xml) 0 0 0
611 {
612 # Get rid of the XML encoding declaration if present
613 0 $$data =~ s/^\x{FEFF}//;
614
615 0 ▶ if( $$data =~ /^(\s*<\?xml[^\x00]*?\?>)/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($$data =~ /^(\s*<\?xml[^\x00]*?\?>)/) 0 0 0
616 {
617 0 substr( $$data, 0, length($1)) =~ s/\sencoding\s*=\s*(["']).*?\1//;
618 }
619 }
620 0 return( $data );
621 }
622  
623 sub decoded_json
624 0 ▶{
Subroutine decoded_json: not called CC=7 SCAR=40.3
Pod documented
625 0 my $self = shift( @_ );
626 0 my $opts = $self->_get_args_as_hash( @_ );
627 0 $opts->{binmode} = 'utf-8';
628 0 my $data = $self->decoded_content_utf8( $opts );
629 0 ▶ return( $self->pass_error ) if( !defined( $data ) && $self->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $data and $self->error 0 0 0
Condition0%0/3
not defined $data and $self->error
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $data and $self->error
not defined $data $self->error
Truth table0%0/3
not(A) and B
A= not defined $dataB= $self->error
ABresult
0X0
100
111
630 0 ▶ return if( !defined( $data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 0 0 0
631 0 ▶ if( $self->headers->content_is_json )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->headers->content_is_json) 0 0 0
632 {
633 0 local $@;
634 # try-catch
635 0 my $ref = $self->new_json_safe->relaxed->decode( $$data );
636 0 ▶ if( !defined( $ref ) && $self->error )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $ref and $self->error) 0 0 0
Condition0%0/3
not defined $ref and $self->error
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $ref and $self->error
not defined $ref $self->error
Truth table0%0/3
not(A) and B
A= not defined $refB= $self->error
ABresult
0X0
100
111
637 {
638 0 my $err = $self->error->message;
639 0 return( $self->error( "Error decoding JSON payload: $err\nPayload was: $$data" ) );
640 }
641 0 return( $ref );
642 }
643 0 return( $$data );
644 }
645  
646 sub dump
647 3 ▶{
Subroutine dump: called CC=14 SCAR=39.5
Pod documented
648 3 my $self = shift( @_ );
649 3 my $opts = $self->_get_args_as_hash( @_ );
650 3 my $content = '';
651 3 my $ent = $self->entity;
652 3 my $maxlen = $opts->{maxlength};
653 3 ▶ $maxlen = 512 unless( defined( $maxlen ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $maxlen 3 0 3
654 3 my $no_content = $opts->{no_content};
655 3 ▶ $no_content = "(no content)" unless( defined( $no_content ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $no_content 3 0 3
656 3 ▶ if( $ent && $ent->body )
Branch: 1 branch
BranchTrueFalseTotal
if ($ent and $ent->body) 0 3 3
Condition33%1/3
$ent and $ent->body
!ll&&!rl&&r
030
MC/DC0%0/2
$ent and $ent->body
$ent $ent->body
Truth table33%1/3
A and B
A= $entB= $ent->body
ABresult
0X0
100
111
657 {
658 0 ▶ my $io = $ent->body->open( '<', { binmode => 'raw' } ) ||
Condition0%0/2
$ent->body->open('<', {'binmode', 'raw'}) || (return $self->pass_error($ent->error))
l!l
00
MC/DC0%0/1
$ent->body->open('<', {'binmode', 'raw'}) || (return $self->pass_error($ent->error))
$ent->body->open('<', {'binmode', 'raw'})
Truth table0%0/2
A
A= $ent->body->open('<', {'binmode', 'raw'})
Aresult
11
00
659 return( $self->pass_error( $ent->error ) );
660 0 my $bytes = $io->read( $content, $maxlen );
661 0 ▶ return( $self->pass_error( $io->error ) ) if( !defined( $bytes ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes 0 0 0
662 0 $io->close;
663 }
664 3 my $chopped = 0;
665 3 ▶ if( length( $content ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $content) { } 0 3 3
666 {
667 0 ▶ if( $ent->body->length > $maxlen )
Branch: 1 branch
BranchTrueFalseTotal
if ($ent->body->length > $maxlen) 0 0 0
668 {
669 0 $content .= '...';
670 0 $chopped = $ent->body->length - $maxlen;
671 }
672 0 $content =~ s/\\/\\\\/g;
673 0 $content =~ s/\t/\\t/g;
674 0 $content =~ s/\r/\\r/g;
675  
676 # no need for 3 digits in escape for these
677 0 $content =~ s/([\0-\11\13-\037])(?!\d)/sprintf('\\%o',ord($1))/eg;
678  
679 0 $content =~ s/([\0-\11\13-\037\177-\377])/sprintf('\\x%02X',ord($1))/eg;
680 0 $content =~ s/([^\12\040-\176])/sprintf('\\x{%X}',ord($1))/eg;
681  
682 # remaining whitespace
683 0 $content =~ s/( +)\n/("\\40" x length($1)) . "\n"/eg;
684 0 $content =~ s/(\n+)\n/("\\n" x length($1)) . "\n"/eg;
685 0 $content =~ s/\n\z/\\n/;
686 0 ▶ if( $content eq $no_content )
Branch: 1 branch
BranchTrueFalseTotal
if ($content eq $no_content) 0 0 0
687 {
688 # escape our $no_content marker
689 0 $content =~ s/^(.)/sprintf('\\x%02X',ord($1))/eg;
690 }
691 }
692 else
693 {
694 3 $content = $no_content;
695 }
696
697 3 my @dump;
698 3 ▶ push( @dump, $opts->{preheader} ) if( $opts->{preheader} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"preheader"} 3 0 3
699 3 push( @dump, $self->headers->as_string, $content );
700 3 ▶ push( @dump, "(+ $chopped more bytes not shown)" ) if( $chopped );
Branch: 1 branch
BranchTrueFalseTotal
if $chopped 0 3 3
701  
702 3 my $dump = join( "\n", @dump, '' );
703 3 ▶ $dump =~ s/^/$opts->{prefix}/gm if( $opts->{prefix} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"prefix"} 0 3 3
704  
705 3 ▶ print( $dump ) unless( defined( wantarray() ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 1 2 3
706 3 return( $dump );
707 }
708  
709 sub encode
710 0 ▶{
Subroutine encode: not called CC=12 SCAR=50.5
Pod documented
711 0 my $self = shift( @_ );
712 0 my $opts = $self->_get_args_as_hash( \@_, args_list => [qw( update_header )] );
713 0 my( @enc ) = @_;
714 0 ▶ $opts->{update_header} //= 1;
Condition0%0/2
$opts->{"update_header"} //= 1
l!l
00
MC/DC0%0/1
$opts->{"update_header"} //= 1
$opts->{"update_header"}
Truth table0%0/2
A
A= $opts->{"update_header"}
Aresult
11
00
715  
716 0 ▶ return( $self->error( "Cannot encode multipart/* messages" ) ) if( $self->content_type =~ m,^multipart/, );
Branch: 1 branch
BranchTrueFalseTotal
if $self->content_type =~ m[^multipart/] 0 0 0
717 0 ▶ return( $self->error( "Cannot encode message/* messages" ) ) if( $self->content_type =~ m,^message/, );
Branch: 1 branch
BranchTrueFalseTotal
if $self->content_type =~ m[^message/] 0 0 0
718 0 my $headers = $self->headers;
719 0 my $e = $headers->content_encoding->split( qr/[[:blank:]\h]*,[[:blank:]\h]*/ );
720 0 my $source = 'argv';
721 0 my $encodings;
722 0 ▶ if( @enc )
Branch: 1 branch
BranchTrueFalseTotal
if (@enc) { } 0 0 0
723 {
724 0 $encodings = $self->new_array( \@enc );
725 }
726 else
727 {
728 0 $source = 'header';
729 0 $encodings = $e;
730 }
731 # nothing to do
732 0 ▶ return(1) if( !$encodings || $encodings->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if not $encodings or $encodings->is_empty 0 0 0
Condition0%0/3
not $encodings or $encodings->is_empty
l!l&&r!l&&!r
000
MC/DC0%0/2
not $encodings or $encodings->is_empty
not $encodings $encodings->is_empty
Truth table0%0/3
not(A) or B
A= not $encodingsB= $encodings->is_empty
ABresult
1X1
011
000
733 0 ▶ my $ent = $self->entity || return(1);
Condition0%0/2
$self->entity || (return 1)
l!l
00
MC/DC0%0/1
$self->entity || (return 1)
$self->entity
Truth table0%0/2
A
A= $self->entity
Aresult
11
00
734 0 $encodings->unique(1);
735 0 ▶ my $body = $ent->encode_body( $encodings ) || return( $self->pass_error( $ent->error ) );
Condition0%0/2
$ent->encode_body($encodings) || (return $self->pass_error($ent->error))
l!l
00
MC/DC0%0/1
$ent->encode_body($encodings) || (return $self->pass_error($ent->error))
$ent->encode_body($encodings)
Truth table0%0/2
A
A= $ent->encode_body($encodings)
Aresult
11
00
736 0 $ent->is_encoded(1);
737 0 ▶ if( $opts->{update_header} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"update_header"}) 0 0 0
738 {
739 0 ▶ if( $source eq 'argv' )
Branch: 1 branch
BranchTrueFalseTotal
if ($source eq "argv") 0 0 0
740 {
741 0 ▶ if( $e )
Branch: 1 branch
BranchTrueFalseTotal
if ($e) { } 0 0 0
742 {
743 0 $e->push( $encodings->list );
744 }
745 else
746 {
747 0 $e = $encodings;
748 }
749 0 $e->unique(1);
750 }
751 0 $headers->content_encoding( $e->join( ', ' )->scalar );
752 0 $headers->remove_header( qw( Content-Length Content-MD5 ) );
753 }
754 0 return(1);
755 }
756  
757 # sub entity { return( shift->_set_get_object_without_init( 'entity', 'HTTP::Promise::Entity', @_ ) ); }
758 sub entity
759 75 ▶{
Subroutine entity: called CC=4 SCAR=14.3
Pod documented
760 75 my $self = shift( @_ );
761 75 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 33 42 75
762 {
763 33 return( $self->_set_get_object_without_init( 'entity', 'HTTP::Promise::Entity', @_ ) );
764 }
765 42 ▶ if( $self->_is_a( $self->{entity} => 'HTTP::Promise::Entity' ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($self->{"entity"}, "HTTP::Promise::Entity") and not $self->{"entity"}{"http_message"}) 0 42 42
Condition66%2/3
$self->_is_a($self->{"entity"}, "HTTP::Promise::Entity") and not $self->{"entity"}{"http_message"}
!ll&&!rl&&r
28140
MC/DC0%0/2
$self->_is_a($self->{"entity"}, "HTTP::Promise::Entity") and not $self->{"entity"}{"http_message"}
$self->_is_a($self->{"entity"}, "HTTP::Promise::Entity") not $self->{"entity"}{"http_message"}
Truth table66%2/3
A and not(B)
A= $self->_is_a($self->{"entity"}, "HTTP::Promise::Entity")B= not $self->{"entity"}{"http_message"}
ABresult
0X0
100
111
766 !$self->{entity}->{http_message} )
767 {
768 0 $self->{entity}->{http_message} = $self;
769 }
770 42 return( $self->_set_get_object_without_init( 'entity', 'HTTP::Promise::Entity' ) );
771 }
772  
773 6 ▶sub header { return( shift->headers->header( @_ ) ); }
Subroutine header: called CC=1 SCAR=0.0
Pod documented
774  
775 sub headers
776 32 ▶{
Subroutine headers: called CC=6 SCAR=30.9
Pod documented
777 32 my $self = shift( @_ );
778 32 ▶ if( @_ )
Branch: 2 branches
BranchTrueFalseTotal
if (@_) { } 0 32 32
elsif (not $self->{'headers'}) { } 0 32 32
779 {
780 0 my $v = shift( @_ );
781 0 ▶ if( $self->_is_a( $v, 'HTTP::Promise::Headers' ) )
Branch: 3 branches
BranchTrueFalseTotal
if ($self->_is_a($v, 'HTTP::Promise::Headers')) { } 0 0 0
elsif ($self->_is_a($v, 'HTTP::Headers')) { } 0 0 0
elsif ($self->_is_array($v)) { } 0 0 0
782 {
783 0 $self->{headers} = $v;
784 }
785 elsif( $self->_is_a( $v, 'HTTP::Headers' ) )
786 {
787 0 my $h = $v->clone;
788 0 $self->{headers} = bless( $h => 'HTTP::Promise::Headers' );
789 }
790 elsif( $self->_is_array( $v ) )
791 {
792 0 $self->{headers} = HTTP::Promise::Headers->new( @$v );
793 }
794 else
795 {
796 0 return( $self->error( "Bad value for headers. I was expecting either an array reference or a HTTP::Promise::Headers or a HTTP::Headers object and I got instead '", overload::StrVal( $v ), "'." ) );
797 }
798 }
799 elsif( !$self->{headers} )
800 {
801 0 $self->{headers} = HTTP::Promise::Headers->new;
802 }
803 32 return( $self->{headers} );
804 }
805  
806 0 ▶sub headers_as_string { return( shift->headers->as_string( @_ ) ); }
Subroutine headers_as_string: not called CC=1 SCAR=6.9
Pod documented
807  
808 sub is_encoding_supported
809 0 ▶{
Subroutine is_encoding_supported: not called CC=4 SCAR=30.0
Pod documented
810 0 my $self = shift( @_ );
811 0 my $enc = shift( @_ );
812 0 ▶ return( $self->error( "No encoding provided." ) ) if( !defined( $enc ) || !length( $enc ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $enc and 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
813 0 ▶ $self->_load_class( 'HTTP::Promise::Stream' ) || return( $self->error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Stream") or return $self->error 0 0 0
814 0 return( HTTP::Promise::Stream->supported( lc( $enc ) ) );
815 }
816  
817 sub make_boundary
818 0 ▶{
Subroutine make_boundary: not called CC=1 SCAR=6.9
Pod documented
819 0 my $self = shift( @_ );
820 0 my $uuid = Data::UUID->new;
821 0 my $boundary = $uuid->create_str;
822 0 return( "$boundary" );
823 }
824  
825 sub parse
826 0 ▶{
Subroutine parse: not called CC=9 SCAR=45.0
Pod documented
827 0 my $self = shift( @_ );
828 0 my $str = shift( @_ );
829 0 ▶ return( $self->error( "No http headers string was provided to parse." ) ) if( !defined( $str ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 0 0 0
830 0 my $opts = $self->_get_args_as_hash( @_ );
831 0 ▶ $opts->{debug} = $self->debug if( !CORE::exists( $opts->{debug} ) && ref( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
if not exists $opts->{"debug"} and ref $self 0 0 0
Condition0%0/3
not exists $opts->{"debug"} and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
not exists $opts->{"debug"} and ref $self
not exists $opts->{"debug"} ref $self
Truth table0%0/3
not(A) and B
A= not exists $opts->{"debug"}B= ref $self
ABresult
0X0
100
111
832 # Nothing to parse, we return a dummy object in line with legacy api of HTTP::Message
833 0 ▶ if( !length( "${str}" ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (length "$str") 0 0 0
834 {
835 0 return( HTTP::Promise::Message->new( { debug => $opts->{debug} } ) );
836 }
837 0 ▶ $self = HTTP::Promise::Message->new( { debug => $opts->{debug} } ) if( !ref( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
838 0 ▶ $self->_load_class( 'HTTP::Promise::Parser' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Parser") or return $self->pass_error 0 0 0
839 0 my $p = HTTP::Promise::Parser->new( debug => $opts->{debug} );
840 0 my $copy = $str;
841 0 $copy =~ s/\r/\\r/g;
842 0 $copy =~ s/\n/\\n/g;
843 0 my $ent = $p->parse( \$str );
844 0 ▶ if( !defined( $ent ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ent) 0 0 0
845 {
846 # We do not support the legacy way of accepting an HTTP message that has no header
847 0 return( $self->pass_error( $p->error ) );
848 }
849 0 my $msg = $ent->http_message;
850 0 ▶ unless( $msg )
Branch: 1 branch
BranchTrueFalseTotal
unless ($msg) 0 0 0
851 {
852 0 my $headers = $ent->headers;
853 0 $msg = HTTP::Promise::Message->new( $headers );
854 0 $msg->entity( $ent );
855 }
856 0 return( $msg );
857 }
858  
859 # NOTE: parts() will parse the current content and break it down into parts if applicable
860 # otherwise, it will simply return the array object $parts, which would be empty.
861 # It would be nice to come up with some efficient caching mechanism to avoid the if..elsif
862 # at the beginning of the subroutine.
863 sub parts
864 0 ▶{
Subroutine parts: not called CC=25 SCAR=64.8
Pod documented
865 0 my $self = shift( @_ );
866 0 my $ent = $self->entity;
867 0 ▶ if( $ent &&
Branch: 2 branches
BranchTrueFalseTotal
if ($ent and $ent->parts->is_empty and $ent->body and not $ent->body->is_empty) { } 0 0 0
elsif ($ent and $ent->parts->is_empty and $ent->body and $ent->body->is_empty) { } 0 0 0
Condition0%0/9
$ent and $ent->parts->is_empty and $ent->body and not $ent->body->is_empty
!ll&&!rl&&r
000
$ent and $ent->parts->is_empty and $ent->body
!ll&&!rl&&r
000
$ent and $ent->parts->is_empty
!ll&&!rl&&r
000
MC/DC0%0/4
$ent and $ent->parts->is_empty and $ent->body and not $ent->body->is_empty
$ent $ent->parts->is_empty $ent->body not $ent->body->is_empty
Truth table0%0/5
A and B and C and not(D)
A= $entB= $ent->parts->is_emptyC= $ent->bodyD= not $ent->body->is_empty
ABCDresult
0XXX0
10XX0
110X0
11100
11111
868 $ent->parts->is_empty &&
869 $ent->body &&
870 !$ent->body->is_empty )
871 {
872 0 ▶ $self->_make_parts || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_make_parts or return $self->pass_error 0 0 0
873 }
874 ▶ elsif( $ent &&
Condition0%0/9
$ent and $ent->parts->is_empty and $ent->body and $ent->body->is_empty
!ll&&!rl&&r
000
$ent and $ent->parts->is_empty and $ent->body
!ll&&!rl&&r
000
$ent and $ent->parts->is_empty
!ll&&!rl&&r
000
MC/DC0%0/4
$ent and $ent->parts->is_empty and $ent->body and $ent->body->is_empty
$ent $ent->parts->is_empty $ent->body $ent->body->is_empty
Truth table0%0/5
A and B and C and D
A= $entB= $ent->parts->is_emptyC= $ent->bodyD= $ent->body->is_empty
ABCDresult
0XXX0
10XX0
110X0
11100
11111
875 $ent->parts->is_empty &&
876 $ent->body &&
877 $ent->body->is_empty )
878 {
879 0 $ent->body( undef );
880 }
881
882 0 ▶ unless( $ent )
Branch: 1 branch
BranchTrueFalseTotal
unless ($ent) 0 0 0
883 {
884 0 ▶ $self->_load_class( 'HTTP::Promise::Entity' ) || return( $self->_pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Entity") or return $self->_pass_error 0 0 0
885 0 ▶ $ent = HTTP::Promise::Entity->new( headers => $self->headers, debug => $self->debug ) ||
Condition0%0/2
'HTTP::Promise::Entity'->new('headers', $self->headers, 'debug', $self->debug) || (return $self->pass_error('HTTP::Promise::Entity'->error))
l!l
00
MC/DC0%0/1
'HTTP::Promise::Entity'->new('headers', $self->headers, 'debug', $self->debug) || (return $self->pass_error('HTTP::Promise::Entity'->error))
'HTTP::Promise::Entity'->new('headers', $self->headers, 'debug', $self->debug)
Truth table0%0/2
A
A= 'HTTP::Promise::Entity'->new('headers', $self->headers, 'debug', $self->debug)
Aresult
11
00
886 return( $self->pass_error( HTTP::Promise::Entity->error ) );
887 0 $self->entity( $ent );
888 }
889
890 # Parts have been provided, add them if suitable
891 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
892 {
893 0 ▶ my @parts = map{ $self->_is_array( $_ ) ? @$_ : $_ } @_;
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_array($_) ? : 0 0 0
894 0 ▶ my $ct = $self->content_type || '';
Condition0%0/2
$self->content_type || ''
l!l
00
MC/DC0%0/1
$self->content_type || ''
$self->content_type
Truth table0%0/2
A
A= $self->content_type
Aresult
11
00
895 0 ▶ if( $ct =~ m,^message/, )
Branch: 2 branches
BranchTrueFalseTotal
if ($ct =~ m[^message/]) { } 0 0 0
elsif (not $ct =~ m[^multipart/]) { } 0 0 0
896 {
897 0 ▶ return( $self->error( "Only one part allowed for $ct content" ) ) if( @parts > 1 );
Branch: 1 branch
BranchTrueFalseTotal
if @parts > 1 0 0 0
898 }
899 elsif( $ct !~ m,^multipart/, )
900 {
901 0 $self->remove_content_headers;
902 0 $self->content_type( 'multipart/mixed' );
903 }
904 # $self->_parts( \@parts );
905 0 ▶ $self->_load_class( 'HTTP::Promise::Entity' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Entity") or return $self->pass_error 0 0 0
906 0 my @new = ();
907 0 for( @parts )
908 {
909 # Either a HTTP::Promise::Request, or a HTTP::Promise::Response, or even a HTTP::Promise::Message
910 0 ▶ unless( $self->_is_a( $_ => 'HTTP::Promise::Entity' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($_, "HTTP::Promise::Entity")) 0 0 0
911 {
912 0 ▶ return( $self->error( "Part object provided (", overload::StrVal( $_ ), ") is neither a HTTP::Promise::Entity or a HTTP::Promise::Message object." ) ) if( !$self->_is_a( $_ => 'HTTP::Promise::Message' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($_, "HTTP::Promise::Message") 0 0 0
913 0 my $ent = $_->entity;
914 0 ▶ unless( $ent )
Branch: 1 branch
BranchTrueFalseTotal
unless ($ent) 0 0 0
915 {
916 0 ▶ $ent = HTTP::Promise::Entity->new( headers => $_->headers, debug => $self->debug ) ||
Condition0%0/2
'HTTP::Promise::Entity'->new('headers', $_->headers, 'debug', $self->debug) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
'HTTP::Promise::Entity'->new('headers', $_->headers, 'debug', $self->debug) || (return $self->pass_error)
'HTTP::Promise::Entity'->new('headers', $_->headers, 'debug', $self->debug)
Truth table0%0/2
A
A= 'HTTP::Promise::Entity'->new('headers', $_->headers, 'debug', $self->debug)
Aresult
11
00
917 return( $self->pass_error );
918 0 $_->entity( $ent );
919 }
920 0 push( @new, $ent );
921 0 next;
922 }
923 0 push( @new, $_ );
924 }
925 0 $ent->parts( \@new );
926 }
927 0 my $parts = $ent->parts;
928 0 return( $parts );
929 }
930  
931 sub protocol
932 16 ▶{
Subroutine protocol: called CC=3 SCAR=11.1
Pod documented
933 16 my $self = shift( @_ );
934 16 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 7 9 16
935 {
936 7 my $v = shift( @_ );
937 7 $v =~ s/^[[:blank:]\h]+|[[:blank:]\h]+$//g;
938 7 ▶ if( $v =~ m,^${HTTP_VERSION}$, )
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /^$HTTP::Promise::Message::HTTP_VERSION$/) { } 7 0 7
939 {
940 7 $self->version( $+{http_version} );
941 }
942 else
943 {
944 0 return( $self->error( "Bad protocol value \"$v\". It should be something like HTTP/1.1" ) );
945 }
946 7 return( $self->_set_get_scalar_as_object( protocol => $v ) );
947 }
948 9 return( $self->_set_get_scalar_as_object( 'protocol' ) );
949 }
950  
951 # NOTE: This method is superseded by the one in HTTP::Promise::Request or HTTP::Promise::Response
952 0 ▶sub start_line { return( '' ) }
Subroutine start_line: not called CC=1 SCAR=6.9
Pod documented
953  
954 12 ▶sub version { return( shift->_set_get_number( 'version', @_ ) ); }
Subroutine version: called CC=1 SCAR=0.0
Pod documented
955  
956 # NOTE: _make_parts() is different from HTTP::Promise::Entity::make_multipart()
957 # This creates private parts attribute from current content (current entity body)
958 # whereas HTTP::Promise::Entity::make_multipart keeps and transforms the current content
959 # into multipart representation.
960 sub _make_parts
961 0 ▶{
Subroutine _make_parts: not called CC=31 SCAR=69.0
962 0 my $self = shift( @_ );
963 0 my $type = $self->headers->type;
964 # my $parts = $self->_parts;
965 0 ▶ my $ent = $self->entity ||
Condition0%0/2
$self->entity || (return $self->error('No entity object is set.'))
l!l
00
MC/DC0%0/1
$self->entity || (return $self->error('No entity object is set.'))
$self->entity
Truth table0%0/2
A
A= $self->entity
Aresult
11
00
966 return( $self->error( "No entity object is set." ) );
967 0 my $body = $ent->body;
968 0 my $parts = $ent->parts;
969 0 ▶ return( $parts ) unless( defined( $type ) && length( $type ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and length $type 0 0 0
Condition0%0/3
defined $type and length $type
!ll&&!rl&&r
000
MC/DC0%0/2
defined $type and length $type
defined $type length $type
Truth table0%0/3
A and B
A= defined $typeB= length $type
ABresult
0X0
100
111
970 0 my $toptype = lc( [split( '/', $type, 2 )]->[0] );
971 # Nothing to do
972 0 ▶ return( $parts ) if( !$body );
Branch: 1 branch
BranchTrueFalseTotal
unless $body 0 0 0
973 0 ▶ if( $toptype eq 'multipart' )
Branch: 3 branches
BranchTrueFalseTotal
if ($toptype eq 'multipart') { } 0 0 0
elsif ($type eq 'message/http') { } 0 0 0
elsif ($toptype eq 'message') { } 0 0 0
974 {
975 # Now parse the raw data saved earlier
976 0 ▶ my $fh = $body->open( '+<', { binmode => 'raw' } ) ||
Condition0%0/2
$body->open('+<', {'binmode', 'raw'}) || (return $self->pass_error($ent->body->error))
l!l
00
MC/DC0%0/1
$body->open('+<', {'binmode', 'raw'}) || (return $self->pass_error($ent->body->error))
$body->open('+<', {'binmode', 'raw'})
Truth table0%0/2
A
A= $body->open('+<', {'binmode', 'raw'})
Aresult
11
00
977 return( $self->pass_error( $ent->body->error ) );
978 0 ▶ $self->_load_class( 'HTTP::Promise::IO' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::IO") or return $self->pass_error 0 0 0
979 0 ▶ my $reader = HTTP::Promise::IO->new( $fh, max_read_buffer => 4096, debug => $self->debug ) ||
Condition0%0/2
'HTTP::Promise::IO'->new($fh, 'max_read_buffer', 4096, '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', 4096, 'debug', $self->debug) || (return $self->pass_error('HTTP::Promise::IO'->error))
'HTTP::Promise::IO'->new($fh, 'max_read_buffer', 4096, 'debug', $self->debug)
Truth table0%0/2
A
A= 'HTTP::Promise::IO'->new($fh, 'max_read_buffer', 4096, 'debug', $self->debug)
Aresult
11
00
980 return( $self->pass_error( HTTP::Promise::IO->error ) );
981 0 ▶ $self->_load_class( 'HTTP::Promise::Parser' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Parser") or return $self->pass_error 0 0 0
982 0 my $parser = HTTP::Promise::Parser->new( debug => $self->debug );
983
984 # Request body can be one of 3 types:
985 # application/x-www-form-urlencoded
986 # multipart/form-data
987 # text/plain or other mime types
988 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST>
989 0 ▶ my $part_ent = $parser->parse_multi_part( entity => $ent, reader => $reader ) ||
Condition0%0/2
$parser->parse_multi_part('entity', $ent, 'reader', $reader) || (return $parser->pass_error)
l!l
00
MC/DC0%0/1
$parser->parse_multi_part('entity', $ent, 'reader', $reader) || (return $parser->pass_error)
$parser->parse_multi_part('entity', $ent, 'reader', $reader)
Truth table0%0/2
A
A= $parser->parse_multi_part('entity', $ent, 'reader', $reader)
Aresult
11
00
990 return( $parser->pass_error );
991 0 $ent->body( undef );
992 }
993 # See rfc7230, section 8.3.1
994 # <https://tools.ietf.org/html/rfc7230#section-8.3.1>
995 elsif( $type eq 'message/http' )
996 {
997 0 ▶ my $fh = $body->open( '+<', { binmode => 'raw' } ) ||
Condition0%0/2
$body->open('+<', {'binmode', 'raw'}) || (return $self->pass_error($ent->body->error))
l!l
00
MC/DC0%0/1
$body->open('+<', {'binmode', 'raw'}) || (return $self->pass_error($ent->body->error))
$body->open('+<', {'binmode', 'raw'})
Truth table0%0/2
A
A= $body->open('+<', {'binmode', 'raw'})
Aresult
11
00
998 return( $self->pass_error( $ent->body->error ) );
999 0 ▶ $self->_load_class( 'HTTP::Promise::IO' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::IO") or return $self->pass_error 0 0 0
1000 0 ▶ my $reader = HTTP::Promise::IO->new( $fh, max_read_buffer => 4096, debug => $self->debug ) ||
Condition0%0/2
'HTTP::Promise::IO'->new($fh, 'max_read_buffer', 4096, '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', 4096, 'debug', $self->debug) || (return $self->pass_error('HTTP::Promise::IO'->error))
'HTTP::Promise::IO'->new($fh, 'max_read_buffer', 4096, 'debug', $self->debug)
Truth table0%0/2
A
A= 'HTTP::Promise::IO'->new($fh, 'max_read_buffer', 4096, 'debug', $self->debug)
Aresult
11
00
1001 return( $self->pass_error( HTTP::Promise::IO->error ) );
1002 # "It is RECOMMENDED that all HTTP senders and recipients support, at a minimum, request-line lengths of 8000 octets."
1003 # Ref: <https://tools.ietf.org/html/rfc7230#section-3.1.1>
1004 # getline() returns a scalar object
1005 0 my $buff = $reader->getline( max_read_buffer => 8192 );
1006 0 ▶ return( $self->pass_error( $reader->error ) ) if( !defined( $buff ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $buff 0 0 0
1007 0 ▶ $self->_load_class( 'HTTP::Promise::Parser' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Parser") or return $self->pass_error 0 0 0
1008 0 my $parser = HTTP::Promise::Parser->new( debug => $self->debug );
1009 0 my $def = $parser->looks_like_what( $buff );
1010 0 ▶ warn( "Part found of type message/http, but its content does not match a HTTP request or response.\n" ) if( !$def && warnings::enabled( 'HTTP::Promise' ) );
Branch: 1 branch
BranchTrueFalseTotal
if not $def and warnings::enabled("HTTP::Promise") 0 0 0
Condition0%0/3
not $def and warnings::enabled("HTTP::Promise")
!ll&&!rl&&r
000
MC/DC0%0/2
not $def and warnings::enabled("HTTP::Promise")
not $def warnings::enabled("HTTP::Promise")
Truth table0%0/3
not(A) and B
A= not $defB= warnings::enabled("HTTP::Promise")
ABresult
0X0
100
111
1011 0 ▶ return( $self->pass_error( $parser->error ) ) if( !defined( $def ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $def 0 0 0
1012 # Give back what we just read to the reader for later use
1013 0 $reader->unread( $buff );
1014 # We parse it even if it may be a defective message/http part
1015 0 ▶ my $sub_ent = $parser->parse( $fh, reader => $reader ) || return( $self->pass_error( $parser->error ) );
Condition0%0/2
$parser->parse($fh, 'reader', $reader) || (return $self->pass_error($parser->error))
l!l
00
MC/DC0%0/1
$parser->parse($fh, 'reader', $reader) || (return $self->pass_error($parser->error))
$parser->parse($fh, 'reader', $reader)
Truth table0%0/2
A
A= $parser->parse($fh, 'reader', $reader)
Aresult
11
00
1016 0 ▶ if( $def )
Branch: 1 branch
BranchTrueFalseTotal
if ($def) 0 0 0
1017 {
1018 0 my $headers = $sub_ent->headers;
1019 0 my $msg;
1020 0 ▶ if( $def->{type} eq 'request' )
Branch: 2 branches
BranchTrueFalseTotal
if ($def->{'type'} eq 'request') { } 0 0 0
elsif ($def->{'type'} eq 'response') { } 0 0 0
1021 {
1022 0 ▶ $self->_load_class( 'HTTP::Promise::Request' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Request") or return $self->pass_error 0 0 0
1023 0 ▶ $msg = HTTP::Promise::Request->new( @$def{qw( method uri )}, $headers, { protocol => $def->{protocol}, version => $def->{http_version} } ) || return( $self->pass_error( HTTP::Promise::Request->error ) );
Condition0%0/2
'HTTP::Promise::Request'->new(@$def{'method', 'uri'}, $headers, {'protocol', $def->{'protocol'}, 'version', $def->{'http_version'}}) || (return $self->pass_error('HTTP::Promise::Request'->error))
l!l
00
MC/DC0%0/1
'HTTP::Promise::Request'->new(@$def{'method', 'uri'}, $headers, {'protocol', $def->{'protocol'}, 'version', $def->{'http_version'}}) || (return $self->pass_error('HTTP::Promise::Request'->error))
'HTTP::Promise::Request'->new(@$def{'method', 'uri'}, $headers, {'protocol', $def->{'protocol'}, 'version', $def->{'http_version'}})
Truth table0%0/2
A
A= 'HTTP::Promise::Request'->new(@$def{'method', 'uri'}, $headers, {'protocol', $def->{'protocol'}, 'version', $def->{'http_version'}})
Aresult
11
00
1024 }
1025 elsif( $def->{type} eq 'response' )
1026 {
1027 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
1028 0 ▶ $msg = HTTP::Promise::Response->new( @$def{qw( code status )}, $headers, { protocol => $def->{protocol}, version => $def->{http_version} } ) || return( $self->pass_error( HTTP::Promise::Response->error ) );
Condition0%0/2
'HTTP::Promise::Response'->new(@$def{'code', 'status'}, $headers, {'protocol', $def->{'protocol'}, 'version', $def->{'http_version'}}) || (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->{'http_version'}}) || (return $self->pass_error('HTTP::Promise::Response'->error))
'HTTP::Promise::Response'->new(@$def{'code', 'status'}, $headers, {'protocol', $def->{'protocol'}, 'version', $def->{'http_version'}})
Truth table0%0/2
A
A= 'HTTP::Promise::Response'->new(@$def{'code', 'status'}, $headers, {'protocol', $def->{'protocol'}, 'version', $def->{'http_version'}})
Aresult
11
00
1029 }
1030 else
1031 {
1032 0 return( $self->error( "Something is wrong with the parser who returned HTTP message type '$def->{type}', which I do not recognise." ) );
1033 }
1034
1035 0 $msg->entity( $sub_ent );
1036 0 $sub_ent->http_message( $msg );
1037 }
1038 0 $parts->set( $sub_ent );
1039 0 $ent->body( undef );
1040 }
1041 elsif( $toptype eq 'message' )
1042 {
1043 0 ▶ my $fh = $body->open( '+<', { binmode => 'raw' } ) ||
Condition0%0/2
$body->open('+<', {'binmode', 'raw'}) || (return $self->pass_error($ent->body->error))
l!l
00
MC/DC0%0/1
$body->open('+<', {'binmode', 'raw'}) || (return $self->pass_error($ent->body->error))
$body->open('+<', {'binmode', 'raw'})
Truth table0%0/2
A
A= $body->open('+<', {'binmode', 'raw'})
Aresult
11
00
1044 return( $self->pass_error( $ent->body->error ) );
1045 0 my $parser = HTTP::Promise::Parser->new( debug => $self->debug );
1046 0 ▶ my $ent = $parser->parse( $fh ) || return( $self->pass_error( $parser->error ) );
Condition0%0/2
$parser->parse($fh) || (return $self->pass_error($parser->error))
l!l
00
MC/DC0%0/1
$parser->parse($fh) || (return $self->pass_error($parser->error))
$parser->parse($fh)
Truth table0%0/2
A
A= $parser->parse($fh)
Aresult
11
00
1047 0 $parts->set( $ent );
1048 0 $ent->body( undef );
1049 }
1050 # Any other is not a multipart as per HTTP protocol
1051 0 return( $parts );
1052 }
1053  
1054 sub _set_content
1055 0 ▶{
Subroutine _set_content: not called CC=4 SCAR=30.0
1056 0 my $self = shift( @_ );
1057 0 ▶ $self->_utf8_downgrade( $_[0] ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_utf8_downgrade($_[0]) or return $self->pass_error 0 0 0
1058 0 $self->content( $_[0] );
1059 0 ▶ $self->entity->parts->reset unless( !$self->entity || $_[1] );
Branch: 1 branch
BranchTrueFalseTotal
unless not $self->entity or $_[1] 0 0 0
Condition0%0/3
not $self->entity or $_[1]
l!l&&r!l&&!r
000
MC/DC0%0/2
not $self->entity or $_[1]
not $self->entity $_[1]
Truth table0%0/3
not(A) or B
A= not $self->entityB= $_[1]
ABresult
1X1
011
000
1060 }
1061  
1062 sub _utf8_downgrade
1063 6 ▶{
Subroutine _utf8_downgrade: called CC=4 SCAR=14.6
1064 6 my $self = shift( @_ );
1065 6 my $rv;
1066 # try-catch
1067 6 local $@;
1068 eval
1069 6 {
1070 6 ▶ if( defined( &utf8::downgrade ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined &utf8::downgrade) 6 0 6
1071 {
1072 6 $rv = utf8::downgrade( $_[0], 1 );
1073 }
1074 };
1075 6 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 6 6
1076 {
1077 0 return( $self->error( "Error downgrading utf8 data: $@" ) );
1078 }
1079 6 ▶ $rv || return( $self->error( 'HTTP::Promise::Message content must be bytes' ) );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return $self->error("HTTP::Promise::Message content must be bytes") 6 0 6
1080 }
1081  
1082 sub AUTOLOAD
1083 0 ▶{
Subroutine AUTOLOAD: not called CC=2 SCAR=17.9
1084 0 my( $package, $method ) = $AUTOLOAD =~ m/\A(.+)::([^:]*)\z/;
1085 0 my $code = $_[0]->can( $method );
1086 0 ▶ goto( &$code ) if( $code );
Branch: 1 branch
BranchTrueFalseTotal
if $code 0 0 0
1087 # Give a chance to our parent AUTOLOAD to kick in
1088 0 $Module::Generic::AUTOLOAD = $AUTOLOAD;
1089 0 goto( &Module::Generic::AUTOLOAD );
1090 }
1091  
1092 # sub CARP_TRACE { return( shift->_get_stack_trace ); }
1093  
1094 # avoid AUTOLOADing it
1095 0 ▶sub DESTROY { }
Subroutine DESTROY: not called CC=1 SCAR=0.0
1096  
1097 # NOTE: sub FREEZE is inherited
1098  
1099 3 ▶sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: called CC=1 SCAR=0.0
Pod undocumented
1100  
1101 3 ▶sub STORABLE_thaw { CORE::return( CORE::shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: called CC=1 SCAR=0.0
Pod undocumented
1102  
1103 # NOTE: sub THAW is inherited
1104 sub THAW
1105 6 ▶{
Subroutine THAW: called CC=16 SCAR=36.0
Pod undocumented
1106 6 my( $self, $serialiser, @args ) = @_;
1107 6 ▶ my $ref = ( CORE::scalar( @args ) == 1 && CORE::ref( $args[0] ) eq 'ARRAY' ) ? CORE::shift( @args ) : \@args;
Branch: 1 branch
BranchTrueFalseTotal
scalar @args == 1 && ref $args[0] eq 'ARRAY' ? : 0 6 6
Condition33%1/3
scalar @args == 1 and ref $args[0] eq "ARRAY"
!ll&&!rl&&r
600
MC/DC0%0/2
scalar @args == 1 and ref $args[0] eq "ARRAY"
scalar @args == 1 ref $args[0] eq "ARRAY"
Truth table33%1/3
A and B
A= scalar @args == 1B= ref $args[0] eq "ARRAY"
ABresult
0X0
100
111
1108 6 ▶ my $class = ( CORE::defined( $ref ) && CORE::ref( $ref ) eq 'ARRAY' && CORE::scalar( @$ref ) > 1 ) ? CORE::shift( @$ref ) : ( CORE::ref( $self ) || $self );
Branch: 1 branch
BranchTrueFalseTotal
defined $ref && ref $ref eq 'ARRAY' && scalar @$ref > 1 ? : 6 0 6
Condition22%2/9
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
!ll&&!rl&&r
006
defined $ref and ref $ref eq "ARRAY"
!ll&&!rl&&r
006
ref $self or $self
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
defined $ref ref $ref eq "ARRAY" scalar @$ref > 1
MC/DC0%0/2
ref $self or $self
ref $self $self
Truth table25%1/4
A and B and C
A= defined $refB= ref $ref eq "ARRAY"C= scalar @$ref > 1
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
A or B
A= ref $selfB= $self
ABresult
1X1
011
000
1109 6 ▶ my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 6 0 6
1110 6 my $new;
1111 # Storable pattern requires to modify the object it created rather than returning a new one
1112 6 ▶ if( CORE::ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 3 3 6
1113 {
1114 3 foreach( CORE::keys( %$hash ) )
1115 {
1116 63 $self->{ $_ } = CORE::delete( $hash->{ $_ } );
1117 }
1118
1119 # Need to make sure the headers object, which is an XS one is properly post processed, because Storable does not handle well XS objects, as of version 3.26
1120 3 ▶ if( CORE::exists( $self->{headers} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"headers"} and defined $self->{"headers"} and ref $self->{"headers"} and $self->{"headers"}->isa("HTTP::Promise::Headers")) 3 0 3
Condition33%3/9
exists $self->{"headers"} and defined $self->{"headers"} and ref $self->{"headers"} and $self->{"headers"}->isa("HTTP::Promise::Headers")
!ll&&!rl&&r
003
exists $self->{"headers"} and defined $self->{"headers"} and ref $self->{"headers"}
!ll&&!rl&&r
003
exists $self->{"headers"} and defined $self->{"headers"}
!ll&&!rl&&r
003
MC/DC0%0/4
exists $self->{"headers"} and defined $self->{"headers"} and ref $self->{"headers"} and $self->{"headers"}->isa("HTTP::Promise::Headers")
exists $self->{"headers"} defined $self->{"headers"} ref $self->{"headers"} $self->{"headers"}->isa("HTTP::Promise::Headers")
Truth table20%1/5
A and B and C and D
A= exists $self->{"headers"}B= defined $self->{"headers"}C= ref $self->{"headers"}D= $self->{"headers"}->isa("HTTP::Promise::Headers")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1121 CORE::defined( $self->{headers} ) &&
1122 CORE::ref( $self->{headers} ) &&
1123 $self->{headers}->isa( 'HTTP::Promise::Headers' ) )
1124 {
1125 3 $self->{headers} = $self->{headers}->STORABLE_thaw_post_processing;
1126 }
1127 # The headers object in HTTP::Promise::Message must be the same shared on in HTTP::Promise::Entity
1128 3 ▶ if( CORE::exists( $self->{entity} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"entity"} and exists $self->{"entity"}{"headers"}) 3 0 3
Condition33%1/3
exists $self->{"entity"} and exists $self->{"entity"}{"headers"}
!ll&&!rl&&r
003
MC/DC0%0/2
exists $self->{"entity"} and exists $self->{"entity"}{"headers"}
exists $self->{"entity"} exists $self->{"entity"}{"headers"}
Truth table33%1/3
A and B
A= exists $self->{"entity"}B= exists $self->{"entity"}{"headers"}
ABresult
0X0
100
111
1129 CORE::exists( $self->{entity}->{headers} ) )
1130 {
1131 3 $self->{entity}->{headers} = $self->{headers};
1132 }
1133 3 $new = $self;
1134 }
1135 else
1136 {
1137 3 $new = bless( $hash => $class );
1138 }
1139 6 CORE::return( $new );
1140 }
1141  
1142 # NOTE: only here to avoid triggering HTTP::Promise::Headers::STORABLE_thaw_post_processing which we inherit when we did 'require HTTP::Promise::Headers'
1143 3 ▶sub STORABLE_thaw_post_processing { CORE::return( $_[0] ); }
Subroutine STORABLE_thaw_post_processing: called CC=1 SCAR=0.0
Pod undocumented
1144  
1145 5 1;
1146 # NOTE: POD
1147 __END__
« Promise/IO.pm ↑ Summary Promise/Parser.pm »