Promise/Headers.pm

filter: Statementstmt 53.2% 565 / 1062 Branchbran 33.8% 201 / 594 Conditioncond 21.9% 108 / 493 MC/DCmcdc 4.7% 13 / 275 Subroutinesub 49.0% 98 / 200 Podpod 89.4% 127 / 142 totaltotal 40.2% 1112 / 2766 CC 477 SCAR 59.5
CC
477
Cov
41%
message
2415.7
pass_error
1620.5
error
727.8
CRAP 384.2
« Promise/Stream.pm ↑ Summary Promise/Entity.pm »
1 ##----------------------------------------------------------------------------
2 ## Asynchronous HTTP Request and Promise - ~/lib/HTTP/Promise/Headers.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/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::Headers;
15 BEGIN
16 12 ▶{
Subroutine BEGIN: called CC=3 SCAR=11.2
17 12 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 12 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 12 warnings::register_categories( 'HTTP::Promise' );
20 12 ▶ use parent qw( HTTP::XSHeaders );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 12 ▶ use vars qw( $VERSION $EXCEPTION_CLASS $MOD_PERL $SUPPORTED $MOD_PATH );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 12 ▶ use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 12 ▶ use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 12 ▶ use HTTP::Promise::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 12 ▶ use HTTP::XSHeaders 0.400004;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 12 ▶ use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 12 ▶ use Module::Generic::Global qw( :const );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 12 ▶ use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 12 ▶ use URI::Escape::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
30 12 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 12 ▶ if( exists( $ENV{MOD_PERL} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"MOD_PERL"} and $HTTP::Promise::Headers::MOD_PERL = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]) 0 12 12
Condition33%1/3
exists $ENV{"MOD_PERL"} and $HTTP::Promise::Headers::MOD_PERL = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]
!ll&&!rl&&r
1200
MC/DC0%0/2
exists $ENV{"MOD_PERL"} and $HTTP::Promise::Headers::MOD_PERL = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]
exists $ENV{"MOD_PERL"} $HTTP::Promise::Headers::MOD_PERL = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]
Truth table33%1/3
A and B
A= exists $ENV{"MOD_PERL"}B= $HTTP::Promise::Headers::MOD_PERL = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]
ABresult
0X0
100
111
32 &&
33 ( $MOD_PERL = $ENV{MOD_PERL} =~ /^mod_perl\/(\d+\.[\d\.]+)/ ) )
34 {
35 0 select( ( select( STDOUT ), $| = 1 )[ 0 ] );
36 0 require Apache2::Log;
37 # For _is_class_loaded method
38 0 require Apache2::Module;
39 0 require Apache2::ServerUtil;
40 0 require Apache2::RequestUtil;
41 0 require Apache2::ServerRec;
42 0 require ModPerl::Util;
43 0 require Apache2::Const;
44 0 Apache2::Const->import( compile => qw( :log OK ) );
45 }
46 12 ▶ use constant CRLF => "\015\012";
Subroutine BEGIN: called CC=1 SCAR=0.0
47 12 our $EXCEPTION_CLASS = 'HTTP::Promise::Exception';
48 12 our $SUPPORTED = {};
49 12 our $VERSION = 'v0.3.3';
50 };
51  
52 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 12 my $stderr = IO::File->new;
56 12 $stderr->fdopen( fileno( STDERR ), 'w' );
57 12 $stderr->binmode( ':utf8' );
58 12 $stderr->autoflush( 1 );
59 12 my $stderr_raw = IO::File->new;
60 12 $stderr_raw->fdopen( fileno( STDERR ), 'w' );
61 12 $stderr_raw->binmode( ':raw' );
62 12 $stderr_raw->autoflush( 1 );
63  
64 12 our $MOD_PATH = Cwd::abs_path( $INC{ ( __PACKAGE__ =~ s{::}{/}gr ) . '.pm' } );
65  
66 # for mod in `ls -1 ./lib/HTTP/Promise/Headers`; do printf "%-32s => 'HTTP::Promise::Headers::%s',\n" $(echo $(basename $mod ".pm")|tr "[:upper:]" "[:lower:]") $(basename $mod ".pm"); done
67 # or
68 # perl -MModule::Generic::File=file -lE 'my $d=file("./lib/HTTP/Promise/Headers"); my $files=$d->content; $files->for(sub{ my$f=file($_); printf("%-32s => ''HTTP::Promise::Headers::%s'',\n", $f->basename(".pm")->lc, $f->basename(".pm")) })'
69 12 our $SUPPORTED =
70 {
71 accept => 'HTTP::Promise::Headers::Accept',
72 acceptencoding => 'HTTP::Promise::Headers::AcceptEncoding',
73 acceptlanguage => 'HTTP::Promise::Headers::AcceptLanguage',
74 altsvc => 'HTTP::Promise::Headers::AltSvc',
75 cachecontrol => 'HTTP::Promise::Headers::CacheControl',
76 clearsitedata => 'HTTP::Promise::Headers::ClearSiteData',
77 contentdisposition => 'HTTP::Promise::Headers::ContentDisposition',
78 contentrange => 'HTTP::Promise::Headers::ContentRange',
79 contentsecuritypolicy => 'HTTP::Promise::Headers::ContentSecurityPolicy',
80 contentsecuritypolicyreportonly => 'HTTP::Promise::Headers::ContentSecurityPolicyReportOnly',
81 contenttype => 'HTTP::Promise::Headers::ContentType',
82 cookie => 'HTTP::Promise::Headers::Cookie',
83 expectct => 'HTTP::Promise::Headers::ExpectCT',
84 forwarded => 'HTTP::Promise::Headers::Forwarded',
85 generic => 'HTTP::Promise::Headers::Generic',
86 keepalive => 'HTTP::Promise::Headers::KeepAlive',
87 link => 'HTTP::Promise::Headers::Link',
88 range => 'HTTP::Promise::Headers::Range',
89 servertiming => 'HTTP::Promise::Headers::ServerTiming',
90 stricttransportsecurity => 'HTTP::Promise::Headers::StrictTransportSecurity',
91 te => 'HTTP::Promise::Headers::TE',
92 wantdigest => 'HTTP::Promise::Headers::WantDigest',
93 };
94  
95 sub new
96 136 ▶{
Subroutine new: called CC=4 SCAR=13.9
Pod documented
97 136 my $this = shift( @_ );
98 136 my $opts = {};
99 136 ▶ $opts = pop( @_ ) if( ref( $_[-1] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 19 117 136
100 136 my $self;
101 # try-catch
102 136 local $@;
103 eval
104 136 {
105 136 $self = $this->SUPER::new( @_ );
106 };
107 136 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 136 136
108 {
109 0 return( $this->error( "Error instantiating an HTTP::Promise::Headers object: $@" ) );
110 }
111 136 $self->{default_type} = undef;
112 136 $self->{_init_strict_use_sub} = 1;
113 136 $self->{_exception_class} = $EXCEPTION_CLASS;
114 136 ▶ $self->debug( $opts->{debug} ) if( CORE::exists( $opts->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"debug"} 19 117 136
115 136 $self->{_ctype_cached} = '';
116 136 return( $self );
117 }
118  
119 # e.g. text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
120 sub accept
121 0 ▶{
Subroutine accept: not called CC=2 SCAR=17.9
Pod documented
122 0 my $self = shift( @_ );
123 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
124 {
125 0 my $types = $self->_get_args_as_array( @_ );
126 0 $self->header( accept => $types );
127 0 CORE::delete( $self->{acceptables} );
128 }
129 0 return( $self->_set_get_one( 'Accept' ) );
130 }
131  
132 # Obsolete header that should not be used
133 0 ▶sub accept_charset { return( shift->_set_get_one( 'Accept-Charset', @_ ) ); }
Subroutine accept_charset: not called CC=1 SCAR=6.9
Pod documented
134  
135 # e.g. gzip, deflate, br
136 0 ▶sub accept_encoding { return( shift->_set_get_multi( 'Accept-Encoding', @_ ) ); }
Subroutine accept_encoding: not called CC=1 SCAR=6.9
Pod documented
137  
138 # e.g.: en-GB,fr-FR;q=0.8,fr;q=0.6,ja;q=0.4,en;q=0.2
139 0 ▶sub accept_language { return( shift->_set_get_multi( 'Accept-Language', @_ ) ); }
Subroutine accept_language: not called CC=1 SCAR=6.9
Pod documented
140  
141 # NOTE: Accept-Patch is a response header
142 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Patch>
143 0 ▶sub accept_patch { return( shift->_set_get_one( 'Accept-Patch', @_ ) ); }
Subroutine accept_patch: not called CC=1 SCAR=6.9
Pod documented
144  
145 # NOTE: Accept-Post is a response header
146 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Post>
147 0 ▶sub accept_post { return( shift->_set_get_multi( 'Accept-Post', @_ ) ); }
Subroutine accept_post: not called CC=1 SCAR=6.9
Pod documented
148  
149 # NOTE: Accept-Tanges is a response header
150 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Ranges>
151 0 ▶sub accept_ranges { return( shift->_set_get_multi( 'Accept-Ranges', @_ ) ); }
Subroutine accept_ranges: not called CC=1 SCAR=6.9
Pod documented
152  
153 sub acceptables
154 0 ▶{
Subroutine acceptables: not called CC=4 SCAR=30.0
Pod documented
155 0 my $self = shift( @_ );
156 0 ▶ return( $self->{acceptables} ) if( $self->{acceptables} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"acceptables"} 0 0 0
157 0 my $accept_raw = $self->accept;
158 0 ▶ if( $accept_raw )
Branch: 1 branch
BranchTrueFalseTotal
if ($accept_raw) 0 0 0
159 {
160 0 ▶ my $f = $self->new_field( accept => $accept_raw ) ||
Condition0%0/2
$self->new_field('accept', $accept_raw) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_field('accept', $accept_raw) || (return $self->pass_error)
$self->new_field('accept', $accept_raw)
Truth table0%0/2
A
A= $self->new_field('accept', $accept_raw)
Aresult
11
00
161 return( $self->pass_error );
162 0 $self->{acceptables} = $f;
163 }
164 0 return( $self->{acceptables} );
165 }
166  
167 1 ▶sub add { return( shift->push_header( @_ ) ); }
Subroutine add: called CC=1 SCAR=0.0
Pod documented
168  
169 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Age>
170 0 ▶sub age { return( shift->_set_get_one( 'Age', @_ ) ); }
Subroutine age: not called CC=1 SCAR=6.9
Pod documented
171  
172 # NOTE: Allow is a response header
173 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Allow>
174 0 ▶sub allow { return( shift->_set_get_multi( 'Allow', @_ ) ); }
Subroutine allow: not called CC=1 SCAR=6.9
Pod documented
175  
176 # Response header: <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials>
177 0 ▶sub allow_credentials { return( shift->_set_get_one( 'Access-Control-Allow-Credentials', @_ ) ); }
Subroutine allow_credentials: not called CC=1 SCAR=6.9
Pod documented
178  
179 # Response header <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers>
180 0 ▶sub allow_headers { return( shift->_set_get_multi( 'Access-Control-Allow-Headers', @_ ) ); }
Subroutine allow_headers: not called CC=1 SCAR=6.9
Pod documented
181  
182 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods>
183 0 ▶sub allow_methods { return( shift->_set_get_one( 'Access-Control-Allow-Methods', @_ ) ); }
Subroutine allow_methods: not called CC=1 SCAR=6.9
Pod documented
184  
185 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin>
186 0 ▶sub allow_origin { return( shift->_set_get_one( 'Access-Control-Allow-Origin', @_ ) ); }
Subroutine allow_origin: not called CC=1 SCAR=6.9
Pod documented
187  
188 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Alt-Svc>
189 0 ▶sub alt_svc { return( shift->_set_get_multi( 'Alt-Svc', @_ ) ); }
Subroutine alt_svc: not called CC=1 SCAR=6.9
Pod documented
190  
191 sub alternate_server
192 0 ▶{
Subroutine alternate_server: not called CC=4 SCAR=30.0
Pod documented
193 0 my $self = shift( @_ );
194 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
195 {
196 # { name => 'h2', value => 'alt.example.com:443', ma => 2592000, persist => 1
197 0 my $def = $self->_get_args_as_hash( @_ );
198 0 my $name = CORE::delete( $def->{name} );
199 0 my $value = CORE::delete( $def->{value} );
200 0 ▶ my $f = $self->new_field( alt_svc => [$name => $value], $def ) ||
Condition0%0/2
$self->new_field('alt_svc', [$name, $value], $def) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_field('alt_svc', [$name, $value], $def) || (return $self->pass_error)
$self->new_field('alt_svc', [$name, $value], $def)
Truth table0%0/2
A
A= $self->new_field('alt_svc', [$name, $value], $def)
Aresult
11
00
201 return( $self->pass_error );
202 0 $self->push_header( 'Alt-Svc' => "$f" );
203 }
204 else
205 {
206 0 my $all = $self->alt_svc;
207 0 ▶ return( $all ) if( !$all->length );
Branch: 1 branch
BranchTrueFalseTotal
unless $all->length 0 0 0
208 0 my $a = $self->new_array;
209 $all->foreach(sub
210 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
211 0 ▶ my $f = $self->new_field( alt_svc => $_ ) ||
Condition0%0/2
$self->new_field('alt_svc', $_) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_field('alt_svc', $_) || (return $self->pass_error)
$self->new_field('alt_svc', $_)
Truth table0%0/2
A
A= $self->new_field('alt_svc', $_)
Aresult
11
00
212 return( $self->pass_error );
213 0 $a->push( $f );
214 0 });
215 0 return( $a );
216 }
217 }
218  
219 # NOTE: as_string() is inherited
220 # NOTE: unfortunately, HTTP::XSHeaders is not dealing with as_string properly
221 # It takes the given eol and replace simply any instance in-between line of \n with it,
222 # thus if you have something like: foo\r\nbar\r\n, it will end up with
223 # foo\r\r\nbar\r\n instead of foot\r\nbar\r\n
224 # Bug report #10 <https://github.com/p5pclub/http-xsheaders/issues/10>
225 # sub as_string { return( shift->SUPER::as_string( @_ ? @_ : ( CRLF ) ) ); }
226 sub as_string
227 51 ▶{
Subroutine as_string: called CC=6 SCAR=19.3
Pod documented
228 51 my $self = shift( @_ );
229 51 my $type = $self->type;
230 # If the type is multipart, ensure we have a boundary set.
231 # This is a convenience for the user, who only needs to set the mime-type
232 # without having to worry about generating a boundary.
233 51 ▶ if( defined( $type ) && lc( [split( '/', $type, 2 )]->[0] ) eq 'multipart' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type and lc [split(m[/], $type, 2)]->[0] eq "multipart") 2 49 51
Condition100%3/3
defined $type and lc [split(m[/], $type, 2)]->[0] eq "multipart"
!ll&&!rl&&r
28212
MC/DC100%2/2
defined $type and lc [split(m[/], $type, 2)]->[0] eq "multipart"
defined $type lc [split(m[/], $type, 2)]->[0] eq "multipart"
Truth table100%3/3
A and B
A= defined $typeB= lc [split(m[/], $type, 2)]->[0] eq "multipart"
ABresult
0X0
100
111
234 {
235 2 my $boundary = $self->multipart_boundary;
236 2 ▶ unless( $boundary )
Branch: 1 branch
BranchTrueFalseTotal
unless ($boundary) 0 2 2
237 {
238 0 $boundary = $self->make_boundary;
239 0 my $ct = $self->new_field( 'Content-Type' => $type );
240 0 $ct->boundary( $boundary );
241 0 $self->content_type( "$ct" );
242 }
243 }
244 51 ▶ my $str = $self->SUPER::as_string( @_ ? @_ : ( CRLF ) );
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 24 27 51
245 51 ▶ if( index( $str, "\r\r\n" ) != -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($str, "\r\r\n") != -1) 0 51 51
246 {
247 0 $str =~ s/\r\r\n/\r\n/g;
248 }
249 51 return( $str );
250 }
251  
252 # NOTE: authorization() is inherited
253 1 ▶sub authorization { return( shift->_set_get_one( 'Authorization', @_ ) ); }
Subroutine authorization: called CC=1 SCAR=0.0
Pod documented
254  
255 # NOTE: authorization_basic() is inherited
256 7 ▶sub authorization_basic { return( shift->_basic_auth( 'Authorization', @_ ) ); }
Subroutine authorization_basic: called CC=1 SCAR=0.0
Pod documented
257  
258 sub boundary
259 1 ▶{
Subroutine boundary: called CC=7 SCAR=33.9
Pod documented
260 1 my $self = shift( @_ );
261 1 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
262 {
263 0 my $boundary = shift( @_ );
264 0 my $ct = $self->content_type;
265 0 $self->{boundary} = $boundary;
266 # If there is a content type set, add the charset to it; otherwise, just return
267 # User should set the content type before setting the charset
268 0 ▶ return( '' ) if( !length( $ct ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $ct 0 0 0
269 0 ▶ my $f = $self->new_field( content_type => $ct ) ||
Condition0%0/2
$self->new_field('content_type', $ct) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_field('content_type', $ct) || (return $self->pass_error)
$self->new_field('content_type', $ct)
Truth table0%0/2
A
A= $self->new_field('content_type', $ct)
Aresult
11
00
270 return( $self->pass_error );
271 0 $f->param( boundary => $boundary );
272 0 $self->{type} = $f->type;
273 0 $self->content_type( $f );
274 0 $self->{_ctype_cached} = "$f";
275 }
276 1 ▶ unless( length( $self->{boundary} ) && $self->{_ctype_cached} eq $self->content_type )
Branch: 1 branch
BranchTrueFalseTotal
unless (length $self->{"boundary"} and $self->{"_ctype_cached"} eq $self->content_type) 0 1 1
Condition33%1/3
length $self->{"boundary"} and $self->{"_ctype_cached"} eq $self->content_type
!ll&&!rl&&r
001
MC/DC0%0/2
length $self->{"boundary"} and $self->{"_ctype_cached"} eq $self->content_type
length $self->{"boundary"} $self->{"_ctype_cached"} eq $self->content_type
Truth table33%1/3
A and B
A= length $self->{"boundary"}B= $self->{"_ctype_cached"} eq $self->content_type
ABresult
0X0
100
111
277 {
278 0 my $ct = $self->content_type;
279 0 ▶ my $f = $self->new_field( content_type => ( defined( $ct ) ? "$ct" : () ) );
Branch: 1 branch
BranchTrueFalseTotal
defined $ct ? : 0 0 0
280 0 $self->{boundary} = $f->boundary;
281 0 $self->{type} = $f->type;
282 0 $self->{_ctype_cached} = $ct;
283 }
284 1 return( $self->{boundary} );
285 }
286  
287 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control>
288 2 ▶sub cache_control { return( shift->_set_get_one( 'Cache-Control', @_ ) ); }
Subroutine cache_control: called CC=1 SCAR=0.0
Pod documented
289  
290 sub charset
291 0 ▶{
Subroutine charset: not called CC=5 SCAR=34.0
Pod documented
292 0 my $self = shift( @_ );
293 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
294 {
295 0 my $charset = shift( @_ );
296 0 my $ct = $self->content_type;
297 0 $self->{charset} = $charset;
298 # If there is a content type set, add the charset to it; otherwise, just return
299 # User should set the content type before setting the charset
300 0 ▶ return( '' ) if( !length( $ct ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $ct 0 0 0
301 0 ▶ my $f = $self->new_field( content_type => $ct ) || return( $self->pass_error );
Condition0%0/2
$self->new_field('content_type', $ct) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_field('content_type', $ct) || (return $self->pass_error)
$self->new_field('content_type', $ct)
Truth table0%0/2
A
A= $self->new_field('content_type', $ct)
Aresult
11
00
302 0 $f->param( charset => $charset );
303 0 $self->content_type( $f );
304 }
305 0 ▶ unless( length( $self->{charset} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (length $self->{"charset"}) 0 0 0
306 {
307 0 my $ct = $self->content_type;
308 0 my $f = $self->new_field( content_type => $ct );
309 0 $self->{charset} = $f->charset;
310 }
311 0 return( $self->{charset} );
312 }
313  
314 # NOTE: clear() is inherited
315  
316 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Clear-Site-Data>
317 0 ▶sub clear_site_data { return( shift->_set_get_multi( 'Clear-Site-Data', @_ ) ); }
Subroutine clear_site_data: not called CC=1 SCAR=6.9
Pod documented
318  
319 0 ▶sub client_date { return( shift->_date_header( 'Client-Date', @_ ) ); }
Subroutine client_date: not called CC=1 SCAR=6.9
Pod undocumented
320  
321 # NOTE: clone() is inherited
322  
323 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Connection>
324 0 ▶sub connection { return( shift->_set_get_one( 'Connection', @_ ) ); }
Subroutine connection: not called CC=1 SCAR=6.9
Pod documented
325  
326 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition>
327 63 ▶sub content_disposition { return( shift->_set_get_one( 'Content-Disposition', @_ ) ); }
Subroutine content_disposition: called CC=1 SCAR=0.0
Pod documented
328  
329 # NOTE: content_encoding() is implemented in our parent class, but our implementation differs
330 61 ▶sub content_encoding { return( shift->_set_get_one( 'Content-Encoding', @_ ) ); }
Subroutine content_encoding: called CC=1 SCAR=0.0
Pod documented
331  
332 # NOTE: content_is_html() is already implemented by our parent class, but our implementation of content_type() differs
333 sub content_is_html
334 2 ▶{
Subroutine content_is_html: called CC=4 SCAR=15.0
Pod documented
335 2 my $self = shift( @_ );
336 2 my $type = $self->type;
337 2 ▶ return(0) if( !defined( $type ) || !length( "$type" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and length "$type" 0 2 2
Condition33%1/3
defined $type and length "$type"
!ll&&!rl&&r
002
MC/DC0%0/2
defined $type and length "$type"
defined $type length "$type"
Truth table33%1/3
A and B
A= defined $typeB= length "$type"
ABresult
0X0
100
111
338 2 $type = lc( $type );
339 2 ▶ return( $type eq 'text/html' || $self->content_is_xhtml );
Condition66%2/3
$type eq 'text/html' || $self->content_is_xhtml
l!l&&r!l&&!r
110
MC/DC0%0/2
$type eq 'text/html' || $self->content_is_xhtml
$type eq 'text/html' $self->content_is_xhtml
Truth table66%2/3
A || B
A= $type eq 'text/html'B= $self->content_is_xhtml
ABresult
1X1
011
000
340 }
341  
342 sub content_is_json
343 0 ▶{
Subroutine content_is_json: not called CC=4 SCAR=30.0
Pod documented
344 0 my $self = shift( @_ );
345 0 my $type = $self->type;
346 0 ▶ return(0) if( !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
347 0 $type = lc( $type );
348 # Standard API error payload as per RFC9457: application/problem+json
349 0 ▶ return( $type eq 'application/json' || $type =~ m,^application/\w+\+json, );
Condition0%0/3
$type eq 'application/json' || $type =~ m[^application/\w+\+json]
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq 'application/json' || $type =~ m[^application/\w+\+json]
$type eq 'application/json' $type =~ m[^application/\w+\+json]
Truth table0%0/3
A || B
A= $type eq 'application/json'B= $type =~ m[^application/\w+\+json]
ABresult
1X1
011
000
350 }
351  
352 sub content_is_text
353 8 ▶{
Subroutine content_is_text: called CC=3 SCAR=12.0
Pod documented
354 8 my $self = shift( @_ );
355 8 my $type = $self->content_type;
356 8 ▶ return(0) if( !defined( $type ) || !length( "$type" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and length "$type" 0 8 8
Condition33%1/3
defined $type and length "$type"
!ll&&!rl&&r
008
MC/DC0%0/2
defined $type and length "$type"
defined $type length "$type"
Truth table33%1/3
A and B
A= defined $typeB= length "$type"
ABresult
0X0
100
111
357 8 return( $$type =~ m,^text/,i );
358 }
359  
360 # NOTE: content_is_xhtml() is already implemented by our parent class, but our implementation of content_type() differs
361 sub content_is_xhtml
362 3 ▶{
Subroutine content_is_xhtml: called CC=4 SCAR=15.0
Pod documented
363 3 my $self = shift( @_ );
364 3 my $type = $self->type;
365 3 ▶ return(0) if( !defined( $type ) || !length( "$type" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and length "$type" 0 3 3
Condition33%1/3
defined $type and length "$type"
!ll&&!rl&&r
003
MC/DC0%0/2
defined $type and length "$type"
defined $type length "$type"
Truth table33%1/3
A and B
A= defined $typeB= length "$type"
ABresult
0X0
100
111
366 3 $type = lc( $type );
367 3 ▶ return( $type eq 'application/xhtml+xml' || $type eq 'application/vnd.wap.xhtml+xml' );
Condition66%2/3
$type eq 'application/xhtml+xml' || $type eq 'application/vnd.wap.xhtml+xml'
l!l&&r!l&&!r
201
MC/DC50%1/2
$type eq 'application/xhtml+xml' || $type eq 'application/vnd.wap.xhtml+xml'
$type eq 'application/xhtml+xml' $type eq 'application/vnd.wap.xhtml+xml'
Truth table66%2/3
A || B
A= $type eq 'application/xhtml+xml'B= $type eq 'application/vnd.wap.xhtml+xml'
ABresult
1X1
011
000
368 }
369  
370 # NOTE: content_is_xml() is already implemented by our parent class, but our implementation of content_type() differs
371 sub content_is_xml
372 10 ▶{
Subroutine content_is_xml: called CC=6 SCAR=19.0
Pod documented
373 10 my $self = shift( @_ );
374 10 my $type = $self->type;
375 10 ▶ return(0) if( !defined( $type ) || !length( "$type" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and length "$type" 0 10 10
Condition33%1/3
defined $type and length "$type"
!ll&&!rl&&r
0010
MC/DC0%0/2
defined $type and length "$type"
defined $type length "$type"
Truth table33%1/3
A and B
A= defined $typeB= length "$type"
ABresult
0X0
100
111
376 10 $type = lc( $type );
377 10 ▶ return(1) if( $type eq 'text/xml' );
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "text/xml" 0 10 10
378 10 ▶ return(1) if( $type eq 'application/xml' );
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "application/xml" 0 10 10
379 10 ▶ return(1) if( $type =~ /\+xml$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $type =~ /\+xml$/ 1 9 10
380 9 return(0);
381 }
382  
383 # NOTE: content_language() is implemented in our parent class, but our implementation differs
384 3 ▶sub content_language { return( shift->_set_get_multi( 'Content-Language', @_ ) ); }
Subroutine content_language: called CC=1 SCAR=0.0
Pod documented
385  
386 # NOTE: content_length() is implemented in our parent class, but our implementation differs
387 17 ▶sub content_length { return( shift->_set_get_one_number( 'Content-Length', @_ ) ); }
Subroutine content_length: called CC=1 SCAR=0.0
Pod documented
388  
389 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Location>
390 0 ▶sub content_location { return( shift->_set_get_one( 'Content-Location', @_ ) ); }
Subroutine content_location: not called CC=1 SCAR=6.9
Pod documented
391  
392 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range>
393 0 ▶sub content_range { return( shift->_set_get_one( 'Content-Range', @_ ) ); }
Subroutine content_range: not called CC=1 SCAR=6.9
Pod documented
394  
395 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy>
396 0 ▶sub content_security_policy { return( shift->_set_get_one( 'Content-Security-Policy', @_ ) ); }
Subroutine content_security_policy: not called CC=1 SCAR=6.9
Pod documented
397  
398 0 ▶sub content_security_policy_report_only { return( shift->_set_get_one( 'Content-Security-Policy-Report-Only', @_ ) ); }
Subroutine content_security_policy_report_only: not called CC=1 SCAR=6.9
Pod documented
399  
400 # NOTE: content_type() is already implemented by our parent class, but we our implementation is more straightforward in line with the idea of setting and getting exactly the header field value.
401 # Arguably, it is wrong to expect the return value of content_type to be only the mime_type, thus there is the type() method for that
402 sub content_type
403 221 ▶{
Subroutine content_type: called CC=7 SCAR=19.7
Pod documented
404 221 my $self = shift( @_ );
405 221 my $v;
406 221 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 26 195 221
407 {
408 26 $v = shift( @_ );
409 26 $self->header( content_type => $v );
410 # Simple value, set the type() cache
411 26 ▶ if( index( $v, ';' ) == -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($v, ';') == -1) { } 11 15 26
412 {
413 11 $self->{type} = $v;
414 }
415 # Force type() to find the mime-type
416 else
417 {
418 15 $self->{type} = '';
419 }
420  
421 26 ▶ return( $self->new_scalar( ref( $v ) ? "$v" : \$v ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $v ? : 0 26 26
422 }
423 else
424 {
425 195 $v = $self->header( 'Content-Type' );
426 }
427  
428 195 ▶ if( defined( $v ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $v) { } 131 64 195
elsif (want('OBJECT')) { } 0 64 64
429 {
430 131 ▶ return( $self->new_scalar( ref( $v ) ? "$v" : \$v ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $v ? : 0 131 131
431 }
432 elsif( want( 'OBJECT' ) )
433 {
434 0 return( Module::Generic::Null->new );
435 }
436 else
437 {
438 64 return;
439 }
440 }
441  
442 # NOTE: content_type_charset() is inherited
443  
444 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Embedder-Policy>
445 0 ▶sub cross_origin_embedder_policy { return( shift->_set_get_one( 'Cross-Origin-Embedder-Policy', @_ ) ); }
Subroutine cross_origin_embedder_policy: not called CC=1 SCAR=6.9
Pod documented
446  
447 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy>
448 0 ▶sub cross_origin_opener_policy { return( shift->_set_get_one( 'Cross-Origin-Opener-Policy', @_ ) ); }
Subroutine cross_origin_opener_policy: not called CC=1 SCAR=6.9
Pod documented
449  
450 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy>
451 0 ▶sub cross_origin_resource_policy { return( shift->_set_get_one( 'Cross-Origin-Resource-Policy', @_ ) ); }
Subroutine cross_origin_resource_policy: not called CC=1 SCAR=6.9
Pod documented
452  
453 0 ▶sub cspro { return( shift->content_security_policy_report_only( @_ ) ); }
Subroutine cspro: not called CC=1 SCAR=6.9
Pod documented
454  
455 # NOTE: date() is already implemented by our parent class, but our implementation is more versatile and better
456 5 ▶sub date { return( shift->_date_header( 'Date', @_ ) ); }
Subroutine date: called CC=1 SCAR=0.0
Pod documented
457  
458 # rfc2231 <https://datatracker.ietf.org/doc/html/rfc2231>
459 sub decode_filename
460 8 ▶{
Subroutine decode_filename: called CC=21 SCAR=53.8
Pod documented
461 8 my $self = shift( @_ );
462 8 my $fname = shift( @_ );
463 8 ▶ return( $fname ) if( !defined( $fname ) || !length( $fname ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fname and length $fname 0 8 8
Condition33%1/3
defined $fname and length $fname
!ll&&!rl&&r
008
MC/DC0%0/2
defined $fname and length $fname
defined $fname length $fname
Truth table33%1/3
A and B
A= defined $fnameB= length $fname
ABresult
0X0
100
111
464 8 my( $charset, $lang );
465 8 ▶ if( $fname =~ /^(.*?)\'([^\']*)\'(.*?)$/ )
Branch: 2 branches
BranchTrueFalseTotal
if ($fname =~ /^(.*?)\'([^\']*)\'(.*?)$/) { } 1 7 8
elsif ($fname =~ /^=\?(.+?)\?(.+?)\?(.+)\?=$/) { } 0 7 7
466 {
467 1 ( $charset, $lang, my $encoded_fname ) = ( $1, $2, $3 );
468 1 ▶ unless( lc( $charset ) eq 'utf8' || lc( $charset ) eq 'utf-8' )
Branch: 1 branch
BranchTrueFalseTotal
unless (lc $charset eq "utf8" or lc $charset eq "utf-8") 0 1 1
Condition33%1/3
lc $charset eq "utf8" or lc $charset eq "utf-8"
l!l&&r!l&&!r
010
MC/DC0%0/2
lc $charset eq "utf8" or lc $charset eq "utf-8"
lc $charset eq "utf8" lc $charset eq "utf-8"
Truth table33%1/3
A or B
A= lc $charset eq "utf8"B= lc $charset eq "utf-8"
ABresult
1X1
011
000
469 {
470 0 return( $self->error( "Character set '$charset' is not supported for file name '$encoded_fname'" ) );
471 }
472 # The language parameter, if any, is discarded
473 1 $fname = Encode::decode_utf8( URI::Escape::XS::uri_unescape( $encoded_fname ) );
474 }
475 # rfc2047 encoded?
476 elsif( $fname =~ /^=\?(.+?)\?(.+?)\?(.+)\?=$/ )
477 {
478 0 $charset = $1;
479 0 my $encoding = uc( $2 );
480 0 my $encfile = $3;
481  
482 0 ▶ if( $encoding eq 'Q' || $encoding eq 'B' )
Branch: 1 branch
BranchTrueFalseTotal
if ($encoding eq "Q" or $encoding eq "B") 0 0 0
Condition0%0/3
$encoding eq "Q" or $encoding eq "B"
l!l&&r!l&&!r
000
MC/DC0%0/2
$encoding eq "Q" or $encoding eq "B"
$encoding eq "Q" $encoding eq "B"
Truth table0%0/3
A or B
A= $encoding eq "Q"B= $encoding eq "B"
ABresult
1X1
011
000
483 {
484 eval
485 0 {
486 0 ▶ if( $encoding eq 'Q' )
Branch: 1 branch
BranchTrueFalseTotal
if ($encoding eq 'Q') { } 0 0 0
487 {
488 0 $encfile =~ s/_/ /g;
489 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
490 0 ▶ my $s = HTTP::Promise::Stream->new( \$encfile, { decoding => 'quoted-printable' } ) ||
Condition0%0/2
'HTTP::Promise::Stream'->new(\$encfile, {'decoding', 'quoted-printable'}) || (return $self->pass_error('HTTP::Promise::Stream'->error))
l!l
00
MC/DC0%0/1
'HTTP::Promise::Stream'->new(\$encfile, {'decoding', 'quoted-printable'}) || (return $self->pass_error('HTTP::Promise::Stream'->error))
'HTTP::Promise::Stream'->new(\$encfile, {'decoding', 'quoted-printable'})
Truth table0%0/2
A
A= 'HTTP::Promise::Stream'->new(\$encfile, {'decoding', 'quoted-printable'})
Aresult
11
00
491 return( $self->pass_error( HTTP::Promise::Stream->error ) );
492 0 my $decoded = $s->decode;
493 0 ▶ return( $self->pass_error( $s->error ) ) if( !defined( $decoded ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $decoded 0 0 0
494 0 $encfile = $decoded;
495 }
496 # $encoding eq 'B'
497 else
498 {
499 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
500 0 $encfile = Crypt::Misc::decode_b64( $encfile );
501 }
502 };
503  
504 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
505 {
506 # return( $self->error( "Error decoding content disposition file name: $e" ) );
507 0 ▶ warn( "Error decoding content disposition file name: $@" ) if( warnings::enabled( 'HTTP::Promise' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("HTTP::Promise") 0 0 0
508 }
509  
510 eval
511 0 {
512 0 ▶ $self->_load_class( 'Encode' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Encode") or return $self->pass_error 0 0 0
513 0 ▶ $self->_load_class( 'Encode::Locale' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Encode::Locale") or return $self->pass_error 0 0 0
514 0 Encode::from_to( $encfile, $charset, 'locale_fs' );
515 0 $fname = $encfile;
516 };
517  
518 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
519 {
520 # return( $self->error( "Error encoding content disposition file name: $e" ) );
521 0 ▶ warn( "Error encoding content disposition file name from '$charset' to 'locale_fs': $@" ) if( warnings::enabled( 'HTTP::Promise' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("HTTP::Promise") 0 0 0
522 }
523 }
524 }
525 8 ▶ return( wantarray() ? ( $fname, $charset, $lang ) : $fname );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 7 1 8
526 }
527  
528 sub debug
529 47 ▶{
Subroutine debug: called CC=6 SCAR=20.4
Pod documented
530 47 my $self = shift( @_ );
531 47 ▶ my $class = ( ref( $self ) || $self );
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
4700
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
532 12 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
533 47 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 47 0 47
534 {
535 47 my $flag = shift( @_ );
536 47 $self->{debug} = $flag;
537 47 ▶ if( $self->{debug} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"} and not $self->{"debug_level"}) 0 47 47
Condition33%1/3
$self->{"debug"} and not $self->{"debug_level"}
!ll&&!rl&&r
4700
MC/DC0%0/2
$self->{"debug"} and not $self->{"debug_level"}
$self->{"debug"} not $self->{"debug_level"}
Truth table33%1/3
A and not(B)
A= $self->{"debug"}B= not $self->{"debug_level"}
ABresult
0X0
100
111
538 !$self->{debug_level} )
539 {
540 0 $self->{debug_level} = $self->{debug};
541 }
542 }
543 47 ▶ return( $self->{debug} || ${"$class\:\:DEBUG"} );
Condition33%1/3
$self->{'debug'} || ${"${class}::DEBUG";}
l!l&&r!l&&!r
0470
MC/DC0%0/2
$self->{'debug'} || ${"${class}::DEBUG";}
$self->{'debug'} ${"${class}::DEBUG";}
Truth table33%1/3
A || B
A= $self->{'debug'}B= ${"${class}::DEBUG";}
ABresult
1X1
011
000
544 }
545  
546 40 ▶sub default_type { return( shift->_set_get( 'default_type', @_ ) ); }
Subroutine default_type: called CC=1 SCAR=0.0
Pod documented
547  
548 0 ▶sub delete { return( shift->remove_header( @_ ) ); }
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
549  
550 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Device-Memory>
551 0 ▶sub device_memory { return( shift->_set_get_one( 'Device-Memory', @_ ) ); }
Subroutine device_memory: not called CC=1 SCAR=6.9
Pod documented
552  
553 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Digest>
554 0 ▶sub digest { return( shift->_set_get_multi( 'Digest', @_ ) ); }
Subroutine digest: not called CC=1 SCAR=6.9
Pod documented
555  
556 # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/DNT
557 0 ▶sub dnt { return( shift->_set_get_one( dnt => @_ ) ); }
Subroutine dnt: not called CC=1 SCAR=6.9
Pod documented
558  
559 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Early-Data>
560 0 ▶sub early_data { return( shift->_set_get_one( 'Early-Data', @_ ) ); }
Subroutine early_data: not called CC=1 SCAR=6.9
Pod documented
561  
562 # rfc2231 <https://datatracker.ietf.org/doc/html/rfc2231>
563 sub encode_filename
564 3 ▶{
Subroutine encode_filename: called CC=3 SCAR=11.6
Pod documented
565 3 my $self = shift( @_ );
566 3 my $fname = shift( @_ );
567 3 my $lang = shift( @_ );
568 3 ▶ if( $fname =~ /[^\w\.]+/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($fname =~ /[^\w\.]+/) 3 0 3
569 {
570 3 ▶ $lang = '' if( !defined( $lang ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lang 3 0 3
571 3 return( sprintf( "UTF-8'${lang}'%s", $self->uri_escape_utf8( $fname ) ) );
572 }
573 # Nothing to be done. We return undef on purpose to indicate nothing was done
574 0 return;
575 }
576  
577 # Copied here from Module::Generic
578 sub error
579 2 ▶{
Subroutine error: called CC=54 SCAR=65.9
Pod documented
580 2 my $self = shift( @_ );
581 2 ▶ my $class = ref( $self ) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
200
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
582 2 ▶ my $i_am_blessed = Scalar::Util::blessed( $self ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($self) ? : 2 0 2
583 12 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
584 2 our $MOD_PERL;
585 2 my $o;
586 12 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
587 12 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
588 my $want_return =
589 {
590 array => sub
591 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
592 0 return( [] );
593 },
594 code => sub
595 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
596 0 ▶ return( sub{} );
Subroutine __ANON__: not called CC=1 SCAR=6.9
597 },
598 'glob' => sub
599 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
600 0 my $dummy = '';
601 0 open( my $tmp, '>', \$dummy );
602 0 return( $tmp );
603 },
604 hash => sub
605 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
606 0 return( {} );
607 },
608 object => sub
609 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
610 0 ▶ $self->_load_class( 'Module::Generic::Null' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Null") or die "Unable to load Module::Generic::Null" 0 0 0
611 die( "Unable to load Module::Generic::Null" );
612 0 my $null = Module::Generic::Null->new( $o, { debug => $self->{debug}, has_error => 1, wants => 'object' });
613 0 return( $null );
614 },
615 'scalar' => sub
616 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
617 0 my $dummy = undef;
618 0 return( \$dummy );
619 },
620 2 };
621  
622 2 my $want_what = Wanted::wantref();
623  
624 # Ensure this is lowercase and at the same time that this is defined
625 2 ▶ $want_what = lc( $want_what // '' );
Condition50%1/2
$want_what // ""
l!l
20
MC/DC0%0/1
$want_what // ""
$want_what
Truth table50%1/2
A
A= $want_what
Aresult
11
00
626 # What type of expected value we support to prevent perl error upon undef.
627 # By default: object
628 2 my $want_ok = [qw( object )];
629  
630 2 ▶ my $err_key = HAS_THREADS ? join( ';', $class, $$, threads->tid ) : join( ';', $class, $$ );
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 0 2 2
631 2 my $repo = Module::Generic::Global->new( 'errors' => $class, key => $err_key );
632 2 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
633 {
634 1 my $args = {};
635 # We got an object as first argument. It could be a child from our exception package or from another package
636 # Either way, we use it as it is
637 1 ▶ if( ( Scalar::Util::blessed( $_[0] ) && $_[0]->isa( 'Module::Generic::Exception' ) ) ||
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($_[0]) and $_[0]->isa('Module::Generic::Exception') or builtin::blessed($_[0])) { } 0 1 1
elsif (ref $_[0] eq 'HASH') { } 0 1 1
Condition33%2/6
builtin::blessed($_[0]) and $_[0]->isa("Module::Generic::Exception") or builtin::blessed($_[0])
l!l&&r!l&&!r
001
builtin::blessed($_[0]) and $_[0]->isa("Module::Generic::Exception")
!ll&&!rl&&r
100
MC/DC0%0/3
builtin::blessed($_[0]) and $_[0]->isa("Module::Generic::Exception") or builtin::blessed($_[0])
builtin::blessed($_[0]) $_[0]->isa("Module::Generic::Exception") builtin::blessed($_[0])
Truth table20%1/5
A and B or C
A= builtin::blessed($_[0])B= $_[0]->isa("Module::Generic::Exception")C= builtin::blessed($_[0])
ABCresult
11X1
0X11
1011
0X00
1000
638 Scalar::Util::blessed( $_[0] ) )
639 {
640 0 $o = shift( @_ );
641 }
642 elsif( ref( $_[0] ) eq 'HASH' )
643 {
644 0 $args = shift( @_ );
645 }
646 else
647 {
648 1 ▶ $args->{message} = join( '', map( ( ref( $_ ) eq 'CODE' && !$self->{_msg_no_exec_sub} ) ? $_->() : $_, @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' && !$self->{'_msg_no_exec_sub'} ? : 0 1 1
Condition33%1/3
ref $_ eq "CODE" and not $self->{"_msg_no_exec_sub"}
!ll&&!rl&&r
100
MC/DC0%0/2
ref $_ eq "CODE" and not $self->{"_msg_no_exec_sub"}
ref $_ eq "CODE" not $self->{"_msg_no_exec_sub"}
Truth table33%1/3
A and not(B)
A= ref $_ eq "CODE"B= not $self->{"_msg_no_exec_sub"}
ABresult
0X0
100
111
649 }
650 1 ▶ $args->{class} //= '';
Condition50%1/2
$args->{"class"} //= ""
l!l
01
MC/DC0%0/1
$args->{"class"} //= ""
$args->{"class"}
Truth table50%1/2
A
A= $args->{"class"}
Aresult
11
00
651 my $max_len = ( CORE::exists( $self->{error_max_length} ) && $self->{error_max_length} =~ /^[-+]?\d+$/ )
652 ? $self->{error_max_length}
653 1 ▶ : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'error_max_length'} && $self->{'error_max_length'} =~ /^[-+]?\d+$/ ? : 0 1 1
Condition33%1/3
exists $self->{"error_max_length"} and $self->{"error_max_length"} =~ /^[-+]?\d+$/
!ll&&!rl&&r
100
MC/DC0%0/2
exists $self->{"error_max_length"} and $self->{"error_max_length"} =~ /^[-+]?\d+$/
exists $self->{"error_max_length"} $self->{"error_max_length"} =~ /^[-+]?\d+$/
Truth table33%1/3
A and B
A= exists $self->{"error_max_length"}B= $self->{"error_max_length"} =~ /^[-+]?\d+$/
ABresult
0X0
100
111
654 1 ▶ $args->{message} = substr( $args->{message}, 0, $self->{error_max_length} ) if( $max_len > 0 && length( $args->{message} ) > $max_len );
Branch: 1 branch
BranchTrueFalseTotal
if $max_len > 0 and length $args->{"message"} > $max_len 0 1 1
Condition33%1/3
$max_len > 0 and length $args->{"message"} > $max_len
!ll&&!rl&&r
100
MC/DC0%0/2
$max_len > 0 and length $args->{"message"} > $max_len
$max_len > 0 length $args->{"message"} > $max_len
Truth table33%1/3
A and B
A= $max_len > 0B= length $args->{"message"} > $max_len
ABresult
0X0
100
111
655 # Reset it
656 1 $self->{_msg_no_exec_sub} = 0;
657 # Note Taken from Carp to find the right point in the stack to start from
658 1 my $caller_func;
659 0 ▶ $caller_func = \&{"CORE::GLOBAL::caller"} if( defined( &{"CORE::GLOBAL::caller"} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined &{"CORE::GLOBAL::caller";} 0 1 1
660 1 ▶ if( !defined( $o ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $o) 1 0 1
661 {
662 my $ex_class = CORE::length( $args->{class} )
663 ? $args->{class}
664 : ( CORE::exists( $self->{_exception_class} ) && CORE::length( $self->{_exception_class} ) )
665 ? $self->{_exception_class}
666 1 ▶ : 'Module::Generic::Exception';
Branch: 2 branches
BranchTrueFalseTotal
length $args->{'class'} ? : 0 1 1
exists $self->{'_exception_class'} && length $self->{'_exception_class'} ? : 1 0 1
Condition33%1/3
exists $self->{"_exception_class"} and length $self->{"_exception_class"}
!ll&&!rl&&r
001
MC/DC0%0/2
exists $self->{"_exception_class"} and length $self->{"_exception_class"}
exists $self->{"_exception_class"} length $self->{"_exception_class"}
Truth table33%1/3
A and B
A= exists $self->{"_exception_class"}B= length $self->{"_exception_class"}
ABresult
0X0
100
111
667 0 ▶ unless( $self->_is_class_loaded( $ex_class ) || scalar( keys( %{"${ex_class}\::"} ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_class_loaded($ex_class) or scalar keys %{"${ex_class}::";}) 0 1 1
Condition50%1/2
$self->_is_class_loaded($ex_class) or scalar keys %{"${ex_class}::";}
l!l
10
MC/DC0%0/1
$self->_is_class_loaded($ex_class) or scalar keys %{"${ex_class}::";}
$self->_is_class_loaded($ex_class)
Truth table50%1/2
A
A= $self->_is_class_loaded($ex_class)
Aresult
11
00
668 {
669 0 my $pl = "use $ex_class;";
670 0 ▶ local $SIG{__DIE__} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
671 0 eval( $pl );
672 # We have to die, because we have an error within another error
673 0 ▶ die( __PACKAGE__ . "::error() is unable to load exception class \"$ex_class\": $@" ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
674 }
675 # $o = $self->{error} = ${ $class . '::ERROR' } = $ex_class->new( $args );
676 1 $o = $ex_class->new( $args );
677 }
678 1 $self->{error} = $o;
679 1 $repo->set( $o );
680 # For backward compatibility, so the user can access $My::Module::ERROR
681 1 ${ $class . '::ERROR' } = $o;
682  
683 1 my $r;
684 1 ▶ if( $MOD_PERL )
Branch: 1 branch
BranchTrueFalseTotal
if ($HTTP::Promise::Headers::MOD_PERL) 0 1 1
685 {
686 # try-catch
687 0 local $@;
688 eval
689 0 {
690 0 $r = Apache2::RequestUtil->request;
691 0 ▶ $r->warn( $o->as_string ) if( $r );
Branch: 1 branch
BranchTrueFalseTotal
if $r 0 0 0
692 };
693 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
694 {
695 0 print( STDERR "Error trying to get the global Apache2::ApacheRec: $@\n" );
696 }
697 }
698  
699 1 ▶ if( $r )
Branch: 3 branches
BranchTrueFalseTotal
if ($r) { } 0 1 1
elsif ($self->{'fatal'} or defined ${"${class}::FATAL_ERROR";} and ${"${class}::FATAL_ERROR";}) { } 0 1 1
elsif (warnings::enabled('HTTP::Promise')) { } 0 1 1
700 {
701 0 ▶ if( my $log_handler = $r->get_handlers( 'PerlPrivateErrorHandler' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $log_handler = $r->get_handlers('PerlPrivateErrorHandler')) { } 0 0 0
702 {
703 0 $log_handler->( $o );
704 }
705 else
706 {
707 0 ▶ $r->warn( $o->as_string ) if( warnings::enabled( 'HTTP::Promise' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("HTTP::Promise") 0 0 0
708 }
709 }
710 0 ▶ elsif( $self->{fatal} || ( defined( ${"${class}\::FATAL_ERROR"} ) && ${"${class}\::FATAL_ERROR"} ) )
Condition33%2/6
$self->{"fatal"} or defined ${"${class}::FATAL_ERROR";} and ${"${class}::FATAL_ERROR";}
l!l&&r!l&&!r
001
defined ${"${class}::FATAL_ERROR";} and ${"${class}::FATAL_ERROR";}
!ll&&!rl&&r
100
MC/DC0%0/3
$self->{"fatal"} or defined ${"${class}::FATAL_ERROR";} and ${"${class}::FATAL_ERROR";}
$self->{"fatal"} defined ${"${class}::FATAL_ERROR";} ${"${class}::FATAL_ERROR";}
Truth table25%1/4
A or B and C
A= $self->{"fatal"}B= defined ${"${class}::FATAL_ERROR";}C= ${"${class}::FATAL_ERROR";}
ABCresult
1XX1
0111
00X0
0100
711 {
712 # my $enc_str = eval{ Encode::encode( 'UTF-8', "$o", Encode::FB_CROAK ) };
713 # die( $@ ? $o : $enc_str );
714 0 die( $o );
715 }
716 elsif( warnings::enabled( 'HTTP::Promise' ) )
717 {
718 0 ▶ if( $r )
Branch: 1 branch
BranchTrueFalseTotal
if ($r) { } 0 0 0
719 {
720 0 $r->warn( $o->as_string );
721 }
722 else
723 {
724 0 my $enc_str = eval{ Encode::encode( 'UTF-8', "$o", Encode::FB_CROAK ) };
725 # Display warnings if warnings for this class is registered and enabled or if not registered
726 0 ▶ warn( $@ ? $o : $enc_str );
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 0 0
727 }
728 }
729  
730 # https://metacpan.org/pod/Perl::Critic::Policy::Subroutines::ProhibitExplicitReturnUndef
731 # https://perlmonks.org/index.pl?node_id=741847
732 # Because in list context this would create a lit with one element undef()
733 # A bare return will return an empty list or an undef scalar
734 # return( undef() );
735 # return;
736 # As of 2019-10-13, Module::Generic version 0.6, we use this special package Module::Generic::Null to be returned in chain without perl causing the error that a method was called on an undefined value
737 # 2020-05-12: Added the no_return_null_object to instruct not to return a null object
738 # This is especially needed when an error is called from TIEHASH that returns a special object.
739 # A Null object would trigger a fatal perl segmentation fault
740 1 ▶ if( !$args->{no_return_null_object} &&
Branch: 1 branch
BranchTrueFalseTotal
if (not $args->{"no_return_null_object"} and $want_what && exists $want_return->{$want_what} && scalar grep(/^$want_what$/i, @$want_ok) || $args->{"object"}) 0 1 1
Condition36%4/11
not $args->{"no_return_null_object"} and $want_what && exists $want_return->{$want_what} && scalar grep(/^$want_what$/i, @$want_ok) || $args->{"object"}
!ll&&!rl&&r
010
$want_what and exists $want_return->{$want_what} and scalar grep(/^$want_what$/i, @$want_ok) or $args->{"object"}
l!l&&r!l&&!r
001
$want_what and exists $want_return->{$want_what} and scalar grep(/^$want_what$/i, @$want_ok)
!ll
10
$want_what and exists $want_return->{$want_what}
!ll&&!rl&&r
100
MC/DC0%0/4
not $args->{"no_return_null_object"} and $want_what && exists $want_return->{$want_what} && scalar grep(/^$want_what$/i, @$want_ok) || $args->{"object"}
not $args->{"no_return_null_object"} $want_what exists $want_return->{$want_what} $args->{"object"}
Truth table16%1/6
not(A) and B and C or D
A= not $args->{"no_return_null_object"}B= $want_whatC= exists $want_return->{$want_what}D= $args->{"object"}
ABCDresult
0XXX0
10X00
11000
111X1
10X11
11011
741 (
742 ( $want_what && CORE::exists( $want_return->{ $want_what } ) && scalar( grep( /^$want_what$/i, @$want_ok ) ) ) ||
743 $args->{object}
744 ) )
745 {
746 0 ▶ if( $args->{object} )
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'object'}) { } 0 0 0
747 {
748 0 rreturn( $want_return->{object}->() );
749 }
750 else
751 {
752 0 rreturn( $want_return->{ $want_what }->() );
753 }
754 }
755 1 return;
756 }
757 1 ▶ if( $i_am_blessed )
Branch: 1 branch
BranchTrueFalseTotal
if ($i_am_blessed) 1 0 1
758 {
759 # To avoid the perl error of 'called on undefined value' and so the user can do
760 # $o->error->_message for example without concerning himself/herself whether an exception object is actually set
761 1 ▶ if( !$self->{error} )
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'error'}) { } 0 1 1
762 {
763 0 ▶ if( $want_what &&
Branch: 1 branch
BranchTrueFalseTotal
if ($want_what and exists $want_return->{$want_what} and scalar grep(/^$want_what$/i, @$want_ok)) 0 0 0
Condition0%0/5
$want_what and exists $want_return->{$want_what} and scalar grep(/^$want_what$/i, @$want_ok)
!ll
00
$want_what and exists $want_return->{$want_what}
!ll&&!rl&&r
000
MC/DC0%0/2
$want_what and exists $want_return->{$want_what} and scalar grep(/^$want_what$/i, @$want_ok)
$want_what exists $want_return->{$want_what}
Truth table0%0/3
A and B
A= $want_whatB= exists $want_return->{$want_what}
ABresult
0X0
100
111
764 CORE::exists( $want_return->{ $want_what } ) &&
765 scalar( grep( /^$want_what$/i, @$want_ok ) ) )
766 {
767 0 rreturn( $want_return->{ $want_what }->() );
768 }
769 }
770 else
771 {
772 1 return( $self->{error} );
773 }
774 }
775  
776 0 $o = $repo->get;
777 0 ▶ if( CORE::defined( $o ) && CORE::length( $o ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $o and length $o) { } 0 0 0
elsif (not &CAN_THREADS() and defined ${$class . '::ERROR';} and length ${$class . '::ERROR';}) { } 0 0 0
Condition0%0/3
defined $o and length $o
!ll&&!rl&&r
000
MC/DC0%0/2
defined $o and length $o
defined $o length $o
Truth table0%0/3
A and B
A= defined $oB= length $o
ABresult
0X0
100
111
778 {
779 # Found an exception object using Module::Generic::Global
780 }
781 ▶ elsif( !CAN_THREADS &&
Condition0%0/6
not &CAN_THREADS() and defined ${$class . '::ERROR';} and length ${$class . '::ERROR';}
!ll&&!rl&&r
000
not &CAN_THREADS() and defined ${$class . '::ERROR';}
!ll&&!rl&&r
000
MC/DC0%0/3
not &CAN_THREADS() and defined ${$class . '::ERROR';} and length ${$class . '::ERROR';}
not &CAN_THREADS() defined ${$class . '::ERROR';} length ${$class . '::ERROR';}
Truth table0%0/4
not(A) and B and C
A= not &CAN_THREADS()B= defined ${$class . '::ERROR';}C= length ${$class . '::ERROR';}
ABCresult
0XX0
10X0
1100
1111
782 0 CORE::defined( ${ $class . '::ERROR' } ) &&
783 0 CORE::length( ${ $class . '::ERROR' } ) )
784 {
785 0 $o = ${ $class . '::ERROR' };
786 0 ▶ warn( "Accessing ${class}::ERROR is deprecated; use ${class}->error instead" ) if( warnings::enabled( 'HTTP::Promise' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("HTTP::Promise") 0 0 0
787 }
788 0 return( $o );
789 }
790  
791 0 ▶sub etag { return( shift->_set_get_one( 'Etag', @_ ) ); }
Subroutine etag: not called CC=1 SCAR=6.9
Pod documented
792  
793 sub exists
794 22 ▶{
Subroutine exists: called CC=3 SCAR=11.4
Pod documented
795 22 my $self = shift( @_ );
796 22 ▶ my $field = shift( @_ ) || return(0);
Condition50%1/2
shift @_ || (return 0)
l!l
220
MC/DC0%0/1
shift @_ || (return 0)
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
797 22 my $rv = $self->header( $field );
798 22 ▶ return( defined( $rv ) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
defined $rv ? : 0 22 22
799 }
800  
801 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expect>
802 0 ▶sub expect { return( shift->_set_get_one( 'Expect', @_ ) ); }
Subroutine expect: not called CC=1 SCAR=6.9
Pod documented
803  
804 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expect-CT>
805 0 ▶sub expect_ct { return( shift->_set_get_multi( 'Expect-CT', @_ ) ); }
Subroutine expect_ct: not called CC=1 SCAR=6.9
Pod documented
806  
807 # NOTE: expires() is inherited
808 3 ▶sub expires { return( shift->_date_header( 'Expires', @_ ) ); }
Subroutine expires: called CC=1 SCAR=0.0
Pod documented
809  
810 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers>
811 # e.g.: Access-Control-Expose-Headers: Content-Encoding, X-Kuma-Revision
812 0 ▶sub expose_headers { return( shift->_set_get_multi( 'Access-Control-Expose-Headers', @_ ) ); }
Subroutine expose_headers: not called CC=1 SCAR=6.9
Pod documented
813  
814 # NOTE: flatten() is inherited
815  
816 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded>
817 0 ▶sub forwarded { return( shift->_set_get_one( 'Forwarded', @_ ) ); }
Subroutine forwarded: not called CC=1 SCAR=6.9
Pod documented
818  
819 # NOTE: from() is inherited
820 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/From>
821 1 ▶sub from { return( shift->_set_get_one( 'From', @_ ) ); }
Subroutine from: called CC=1 SCAR=0.0
Pod documented
822  
823 0 ▶sub get { return( shift->header( shift( @_ ) ) ); }
Subroutine get: not called CC=1 SCAR=6.9
Pod documented
824  
825 # NOTE: header() is inherited
826  
827 # NOTE: header_field_names() is inherited
828  
829 0 ▶sub host { return( shift->_set_get_one( 'Host', @_ ) ); }
Subroutine host: not called CC=1 SCAR=6.9
Pod documented
830  
831 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match>
832 0 ▶sub if_match { return( shift->_set_get_one( 'If-Match', @_ ) ); }
Subroutine if_match: not called CC=1 SCAR=6.9
Pod documented
833  
834 # NOTE: if_modified_since() is inherited
835 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Modified-Since>
836 4 ▶sub if_modified_since { return( shift->_date_header( 'If-Modified-Since', @_ ) ); }
Subroutine if_modified_since: called CC=1 SCAR=0.0
Pod documented
837  
838 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-None-Match>
839 0 ▶sub if_none_match { return( shift->_set_get_one( 'If-None-Match', @_ ) ); }
Subroutine if_none_match: not called CC=1 SCAR=6.9
Pod documented
840  
841 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Range>
842 0 ▶sub if_range { return( shift->_set_get_one( 'If-Range', @_ ) ); }
Subroutine if_range: not called CC=1 SCAR=6.9
Pod documented
843  
844 # NOTE: if_unmodified_since() is inherited
845 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Unmodified-Since>
846 3 ▶sub if_unmodified_since { return( shift->_date_header( 'If-Unmodified-Since', @_ ) ); }
Subroutine if_unmodified_since: called CC=1 SCAR=0.0
Pod documented
847  
848 # NOTE: init_header() is inherited
849  
850 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive>
851 0 ▶sub keep_alive { return( shift->_set_get_one( 'Keep-Alive', @_ ) ); }
Subroutine keep_alive: not called CC=1 SCAR=6.9
Pod documented
852  
853 # NOTE: last_modified() is inherited
854 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Last-Modified>
855 3 ▶sub last_modified { return( shift->_date_header( 'Last-Modified', @_ ) ); }
Subroutine last_modified: called CC=1 SCAR=0.0
Pod documented
856  
857 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link>
858 0 ▶sub link { return( shift->_set_get_multi( 'Link', @_ ) ); }
Subroutine link: not called CC=1 SCAR=6.9
Pod documented
859  
860 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location>
861 0 ▶sub location { return( shift->_set_get_one( 'Location', @_ ) ); }
Subroutine location: not called CC=1 SCAR=6.9
Pod documented
862  
863 sub make_boundary
864 0 ▶{
Subroutine make_boundary: not called CC=2 SCAR=17.9
Pod documented
865 0 my $self = shift( @_ );
866 0 ▶ $self->_load_class( 'Data::UUID' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Data::UUID") or return $self->pass_error 0 0 0
867 0 return( Data::UUID->new->create_str );
868 }
869  
870 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age>
871 0 ▶sub max_age { return( shift->_set_get_number( 'Access-Control-Max-Age', @_ ) ); }
Subroutine max_age: not called CC=1 SCAR=6.9
Pod documented
872  
873 sub message
874 0 ▶{
Subroutine message: not called CC=51 SCAR=77.9
Pod undocumented
875 0 my $self = shift( @_ );
876 0 ▶ my $class = ref( $self ) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
877 12 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
878 0 ▶ if( $self->{verbose} || $self->{debug} || ${ $class . '::DEBUG' } )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"} or $self->{"debug"} or ${$class . '::DEBUG';}) 0 0 0
Condition0%0/6
$self->{"verbose"} or $self->{"debug"} or ${$class . '::DEBUG';}
l!l&&r!l&&!r
000
$self->{"verbose"} or $self->{"debug"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{"verbose"} or $self->{"debug"} or ${$class . '::DEBUG';}
$self->{"verbose"} $self->{"debug"} ${$class . '::DEBUG';}
Truth table0%0/4
A or B or C
A= $self->{"verbose"}B= $self->{"debug"}C= ${$class . '::DEBUG';}
ABCresult
1XX1
01X1
0011
0000
879 {
880 0 my $r;
881 0 ▶ if( $MOD_PERL )
Branch: 1 branch
BranchTrueFalseTotal
if ($HTTP::Promise::Headers::MOD_PERL) 0 0 0
882 {
883 # try-catch
884 0 local $@;
885 eval
886 0 {
887 0 $r = Apache2::RequestUtil->request;
888 };
889 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
890 {
891 0 $stderr_raw->print( "Error trying to get the global Apache2::ApacheRec: $@\n" );
892 }
893 }
894  
895 0 my $ref;
896 0 $ref = $self->message_check( @_ );
897 0 ▶ return(1) if( !$ref );
Branch: 1 branch
BranchTrueFalseTotal
unless $ref 0 0 0
898  
899 0 my $opts = {};
900 0 ▶ $opts = pop( @$ref ) if( ref( $ref->[-1] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $ref->[-1] eq "HASH" 0 0 0
901  
902 0 ▶ my $stackFrame = $self->message_frame( (caller(1))[3] ) || 1;
Condition0%0/2
$self->message_frame((caller 1)[3]) || 1
l!l
00
MC/DC0%0/1
$self->message_frame((caller 1)[3]) || 1
$self->message_frame((caller 1)[3])
Truth table0%0/2
A
A= $self->message_frame((caller 1)[3])
Aresult
11
00
903 0 ▶ $stackFrame = 1 unless( $stackFrame =~ /^\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $stackFrame =~ /^\d+$/ 0 0 0
904 0 ▶ $stackFrame-- if( $stackFrame );
Branch: 1 branch
BranchTrueFalseTotal
if $stackFrame 0 0 0
905 0 ▶ $stackFrame++ if( ( (caller(1))[3] // '' ) eq 'HTTP::Promise::Headers::messagef' );
Branch: 1 branch
BranchTrueFalseTotal
if ((caller 1)[3] // "") eq "HTTP::Promise::Headers::messagef" 0 0 0
Condition0%0/2
(caller 1)[3] // ""
l!l
00
MC/DC0%0/1
(caller 1)[3] // ""
(caller 1)[3]
Truth table0%0/2
A
A= (caller 1)[3]
Aresult
11
00
906 0 my( $pkg, $file, $line, @otherInfo ) = caller( $stackFrame );
907 0 ▶ my $sub = ( caller( $stackFrame + 1 ) )[3] // '';
Condition0%0/2
(caller $stackFrame + 1)[3] // ""
l!l
00
MC/DC0%0/1
(caller $stackFrame + 1)[3] // ""
(caller $stackFrame + 1)[3]
Truth table0%0/2
A
A= (caller $stackFrame + 1)[3]
Aresult
11
00
908 0 my $sub2 = substr( $sub, rindex( $sub, '::' ) + 2 );
909 0 ▶ if( ref( $self->{_message_frame} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"_message_frame"} eq "HASH") 0 0 0
910 {
911 0 ▶ if( exists( $self->{_message_frame}->{ $sub2 } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_message_frame"}{$sub2}) 0 0 0
912 {
913 0 my $frameNo = int( $self->{_message_frame}->{ $sub2 } );
914 0 ▶ if( $frameNo > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($frameNo > 0) 0 0 0
915 {
916 0 ( $pkg, $file, $line, $sub ) = caller( $frameNo );
917 0 $sub2 = substr( $sub, rindex( $sub, '::' ) + 2 );
918 }
919 }
920 }
921 0 ▶ if( $sub2 eq 'message' )
Branch: 1 branch
BranchTrueFalseTotal
if ($sub2 eq "message") 0 0 0
922 {
923 0 $stackFrame++;
924 0 ( $pkg, $file, $line, @otherInfo ) = caller( $stackFrame );
925 0 ▶ my $sub = ( caller( $stackFrame + 1 ) )[3] // '';
Condition0%0/2
(caller $stackFrame + 1)[3] // ""
l!l
00
MC/DC0%0/1
(caller $stackFrame + 1)[3] // ""
(caller $stackFrame + 1)[3]
Truth table0%0/2
A
A= (caller $stackFrame + 1)[3]
Aresult
11
00
926 0 $sub2 = substr( $sub, rindex( $sub, '::' ) + 2 );
927 }
928 0 my $txt;
929 0 ▶ if( $opts->{message} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'message'}) { } 0 0 0
930 {
931 0 ▶ if( ref( $opts->{message} ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opts->{'message'} eq 'ARRAY') { } 0 0 0
932 {
933 0 ▶ $txt = join( '', map( ( ref( $_ ) eq 'CODE' && !$self->{_msg_no_exec_sub} ) ? $_->() : ( $_ // '' ), @{$opts->{message}} ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' && !$self->{'_msg_no_exec_sub'} ? : 0 0 0
Condition0%0/5
ref $_ eq "CODE" and not $self->{"_msg_no_exec_sub"}
!ll&&!rl&&r
000
$_ // ""
l!l
00
MC/DC0%0/2
ref $_ eq "CODE" and not $self->{"_msg_no_exec_sub"}
ref $_ eq "CODE" not $self->{"_msg_no_exec_sub"}
MC/DC0%0/1
$_ // ""
$_
Truth table0%0/3
A and not(B)
A= ref $_ eq "CODE"B= not $self->{"_msg_no_exec_sub"}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $_
Aresult
11
00
934 }
935 else
936 {
937 0 $txt = $opts->{message};
938 }
939 }
940 else
941 {
942 0 ▶ $txt = join( '', map( ( ref( $_ ) eq 'CODE' && !$self->{_msg_no_exec_sub} ) ? $_->() : ( $_ // '' ), @$ref ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' && !$self->{'_msg_no_exec_sub'} ? : 0 0 0
Condition0%0/5
ref $_ eq "CODE" and not $self->{"_msg_no_exec_sub"}
!ll&&!rl&&r
000
$_ // ""
l!l
00
MC/DC0%0/2
ref $_ eq "CODE" and not $self->{"_msg_no_exec_sub"}
ref $_ eq "CODE" not $self->{"_msg_no_exec_sub"}
MC/DC0%0/1
$_ // ""
$_
Truth table0%0/3
A and not(B)
A= ref $_ eq "CODE"B= not $self->{"_msg_no_exec_sub"}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $_
Aresult
11
00
943 }
944 # Reset it
945 0 $self->{_msg_no_exec_sub} = 0;
946 0 ▶ my $prefix = CORE::length( $opts->{prefix} ) ? $opts->{prefix} : '##';
Branch: 1 branch
BranchTrueFalseTotal
length $opts->{'prefix'} ? : 0 0 0
947 12 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
948 0 ▶ $opts->{caller_info} = 1 if( !CORE::exists( $opts->{caller_info} ) || !CORE::length( $opts->{caller_info} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"caller_info"} and length $opts->{"caller_info"} 0 0 0
Condition0%0/3
exists $opts->{"caller_info"} and length $opts->{"caller_info"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"caller_info"} and length $opts->{"caller_info"}
exists $opts->{"caller_info"} length $opts->{"caller_info"}
Truth table0%0/3
A and B
A= exists $opts->{"caller_info"}B= length $opts->{"caller_info"}
ABresult
0X0
100
111
949 0 my $proc_info = " [PID: $$]";
950 0 ▶ if( HAS_THREADS )
Branch: 1 branch
BranchTrueFalseTotal
if (&HAS_THREADS()) 0 0 0
951 {
952 0 my $tid = threads->tid;
953 0 ▶ $proc_info .= ' -> [thread id ' . $tid . ']' if( $tid );
Branch: 1 branch
BranchTrueFalseTotal
if $tid 0 0 0
954 }
955 0 ▶ my $mesg_raw = $opts->{caller_info} ? ( "${pkg}::${sub2}( $self ) [$line]${proc_info}: " . $txt ) : $txt;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'caller_info'} ? : 0 0 0
956 0 $mesg_raw =~ s/\n$//gs;
957 0 my $mesg = "${prefix} " . join( "\n${prefix} ", split( /\n/, $mesg_raw ) );
958  
959 my $info =
960 {
961 'formatted' => $mesg,
962 'message' => $txt,
963 'file' => $file,
964 'line' => $line,
965 'package' => $class,
966 'sub' => $sub2,
967 0 ▶ 'level' => ( $_[0] =~ /^\d+$/ ? $_[0] : CORE::exists( $opts->{level} ) ? $opts->{level} : 0 ),
Branch: 2 branches
BranchTrueFalseTotal
$_[0] =~ /^\d+$/ ? : 0 0 0
exists $opts->{'level'} ? : 0 0 0
968 };
969 0 ▶ $info->{type} = $opts->{type} if( $opts->{type} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"type"} 0 0 0
970  
971 ## If Mod perl is activated AND we are not using a private log
972 0 ▶ if( $r && !${ "${class}::LOG_DEBUG" } )
Branch: 4 branches
BranchTrueFalseTotal
if ($r and not ${"${class}::LOG_DEBUG";}) { } 0 0 0
elsif ($HTTP::Promise::Headers::MOD_PERL and not ${"${class}::LOG_DEBUG";}) { } 0 0 0
elsif (not -t STDIN and $self->{'_log_handler'} and ref $self->{'_log_handler'} eq 'CODE') { } 0 0 0
elsif (not -t STDIN and ${$class . '::MESSAGE_HANDLER';} and ref ${$class . '::MESSAGE_HANDLER';} eq 'CODE') { } 0 0 0
Condition0%0/3
$r and not ${"${class}::LOG_DEBUG";}
!ll&&!rl&&r
000
MC/DC0%0/2
$r and not ${"${class}::LOG_DEBUG";}
$r not ${"${class}::LOG_DEBUG";}
Truth table0%0/3
A and not(B)
A= $rB= not ${"${class}::LOG_DEBUG";}
ABresult
0X0
100
111
973 {
974 0 ▶ if( my $log_handler = $r->get_handlers( 'PerlPrivateLogHandler' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (my $log_handler = $r->get_handlers('PerlPrivateLogHandler')) { } 0 0 0
elsif ($self->{'_log_handler'} and ref $self->{'_log_handler'} eq 'CODE') { } 0 0 0
975 {
976 0 $log_handler->( $mesg_raw );
977 }
978 ▶ elsif( $self->{_log_handler} && ref( $self->{_log_handler} ) eq 'CODE' )
Condition0%0/3
$self->{"_log_handler"} and ref $self->{"_log_handler"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_log_handler"} and ref $self->{"_log_handler"} eq "CODE"
$self->{"_log_handler"} ref $self->{"_log_handler"} eq "CODE"
Truth table0%0/3
A and B
A= $self->{"_log_handler"}B= ref $self->{"_log_handler"} eq "CODE"
ABresult
0X0
100
111
979 {
980 0 $self->{_log_handler}->( $info );
981 }
982 else
983 {
984 0 $r->log->debug( $mesg_raw );
985 }
986 }
987 # Using ModPerl Server to log
988 0 ▶ elsif( $MOD_PERL && !${ "${class}::LOG_DEBUG" } )
Condition0%0/3
$HTTP::Promise::Headers::MOD_PERL and not ${"${class}::LOG_DEBUG";}
!ll&&!rl&&r
000
MC/DC0%0/2
$HTTP::Promise::Headers::MOD_PERL and not ${"${class}::LOG_DEBUG";}
$HTTP::Promise::Headers::MOD_PERL not ${"${class}::LOG_DEBUG";}
Truth table0%0/3
A and not(B)
A= $HTTP::Promise::Headers::MOD_PERLB= not ${"${class}::LOG_DEBUG";}
ABresult
0X0
100
111
989 {
990 0 require Apache2::ServerUtil;
991 0 my $s = Apache2::ServerUtil->server;
992 0 $s->log->debug( $mesg );
993 }
994 # e.g. in our package, we could set the handler using the curry module like $self->{_log_handler} = $self->curry::log
995 ▶ elsif( !-t( STDIN ) && $self->{_log_handler} && ref( $self->{_log_handler} ) eq 'CODE' )
Condition0%0/6
not -t STDIN and $self->{"_log_handler"} and ref $self->{"_log_handler"} eq "CODE"
!ll&&!rl&&r
000
not -t STDIN and $self->{"_log_handler"}
!ll&&!rl&&r
000
MC/DC0%0/3
not -t STDIN and $self->{"_log_handler"} and ref $self->{"_log_handler"} eq "CODE"
not -t STDIN $self->{"_log_handler"} ref $self->{"_log_handler"} eq "CODE"
Truth table0%0/4
not(A) and B and C
A= not -t STDINB= $self->{"_log_handler"}C= ref $self->{"_log_handler"} eq "CODE"
ABCresult
0XX0
10X0
1100
1111
996 {
997 0 $self->{_log_handler}->( $info );
998 }
999 0 ▶ elsif( !-t( STDIN ) && ${ $class . '::MESSAGE_HANDLER' } && ref( ${ $class . '::MESSAGE_HANDLER' } ) eq 'CODE' )
Condition0%0/6
not -t STDIN and ${$class . '::MESSAGE_HANDLER';} and ref ${$class . '::MESSAGE_HANDLER';} eq "CODE"
!ll&&!rl&&r
000
not -t STDIN and ${$class . '::MESSAGE_HANDLER';}
!ll&&!rl&&r
000
MC/DC0%0/3
not -t STDIN and ${$class . '::MESSAGE_HANDLER';} and ref ${$class . '::MESSAGE_HANDLER';} eq "CODE"
not -t STDIN ${$class . '::MESSAGE_HANDLER';} ref ${$class . '::MESSAGE_HANDLER';} eq "CODE"
Truth table0%0/4
not(A) and B and C
A= not -t STDINB= ${$class . '::MESSAGE_HANDLER';}C= ref ${$class . '::MESSAGE_HANDLER';} eq "CODE"
ABCresult
0XX0
10X0
1100
1111
1000 {
1001 0 my $h = ${ $class . '::MESSAGE_HANDLER' };
1002 0 $h->( $info );
1003 }
1004 # Otherwise just on the stderr
1005 else
1006 {
1007 0 ▶ if( $opts->{no_encoding} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'no_encoding'}) { } 0 0 0
1008 {
1009 0 $stderr_raw->print( $mesg, "\n" );
1010 }
1011 else
1012 {
1013 0 $stderr->print( $mesg, "\n" );
1014 }
1015 }
1016 }
1017 0 return(1);
1018 }
1019  
1020 sub message_check
1021 0 ▶{
Subroutine message_check: not called CC=27 SCAR=64.5
Pod undocumented
1022 0 my $self = shift( @_ );
1023 0 ▶ my $class = ref( $self ) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
1024 12 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1025 12 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1026 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1027 {
1028 0 ▶ if( $_[0] !~ /^\d/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($_[0] =~ /^\d/) 0 0 0
1029 {
1030 # The last parameter is an options parameter which has the level property set
1031 0 ▶ if( ref( $_[-1] ) eq 'HASH' && CORE::exists( $_[-1]->{level} ) )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[-1] eq 'HASH' and exists $_[-1]{'level'}) { } 0 0 0
elsif ($self->{'_message_default_level'} =~ /^\d+$/ and $self->{'_message_default_level'} > 0) { } 0 0 0
Condition0%0/3
ref $_[-1] eq "HASH" and exists $_[-1]{"level"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[-1] eq "HASH" and exists $_[-1]{"level"}
ref $_[-1] eq "HASH" exists $_[-1]{"level"}
Truth table0%0/3
A and B
A= ref $_[-1] eq "HASH"B= exists $_[-1]{"level"}
ABresult
0X0
100
111
1032 {
1033 # Then let's use this
1034 }
1035 ▶ elsif( $self->{_message_default_level} =~ /^\d+$/ &&
Condition0%0/3
$self->{"_message_default_level"} =~ /^\d+$/ and $self->{"_message_default_level"} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_message_default_level"} =~ /^\d+$/ and $self->{"_message_default_level"} > 0
$self->{"_message_default_level"} =~ /^\d+$/ $self->{"_message_default_level"} > 0
Truth table0%0/3
A and B
A= $self->{"_message_default_level"} =~ /^\d+$/B= $self->{"_message_default_level"} > 0
ABresult
0X0
100
111
1036 $self->{_message_default_level} > 0 )
1037 {
1038 0 unshift( @_, $self->{_message_default_level} );
1039 }
1040 else
1041 {
1042 0 unshift( @_, 1 );
1043 }
1044 }
1045 # If the first argument looks line a number, and there is more than 1 argument
1046 # and it is greater than 1, and greater than our current debug level
1047 # well, we do not output anything then...
1048 0 ▶ if( ( $_[0] =~ /^\d+$/ ||
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^\d+$/ || ref $_[-1] eq "HASH" && exists $_[-1]{"level"} && $_[-1]{"level"} =~ /^\d+$/ and @_ > 1) 0 0 0
Condition0%0/12
$_[0] =~ /^\d+$/ || ref $_[-1] eq "HASH" && exists $_[-1]{"level"} && $_[-1]{"level"} =~ /^\d+$/ and @_ > 1
!ll&&!rl&&r
000
$_[0] =~ /^\d+$/ or ref $_[-1] eq "HASH" and exists $_[-1]{"level"} and $_[-1]{"level"} =~ /^\d+$/
l!l&&r!l&&!r
000
ref $_[-1] eq "HASH" and exists $_[-1]{"level"} and $_[-1]{"level"} =~ /^\d+$/
!ll&&!rl&&r
000
ref $_[-1] eq "HASH" and exists $_[-1]{"level"}
!ll&&!rl&&r
000
MC/DC0%0/5
$_[0] =~ /^\d+$/ || ref $_[-1] eq "HASH" && exists $_[-1]{"level"} && $_[-1]{"level"} =~ /^\d+$/ and @_ > 1
$_[0] =~ /^\d+$/ ref $_[-1] eq "HASH" exists $_[-1]{"level"} $_[-1]{"level"} =~ /^\d+$/ @_ > 1
Truth table0%0/7
A or B and C and D and E
A= $_[0] =~ /^\d+$/B= ref $_[-1] eq "HASH"C= exists $_[-1]{"level"}D= $_[-1]{"level"} =~ /^\d+$/E= @_ > 1
ABCDEresult
00XXX0
010XX0
0110X0
1XXX00
011100
1XXX11
011111
1049 ( ref( $_[-1] ) eq 'HASH' &&
1050 CORE::exists( $_[-1]->{level} ) &&
1051 $_[-1]->{level} =~ /^\d+$/
1052 )
1053 ) && @_ > 1 )
1054 {
1055 0 my $message_level = 0;
1056 0 ▶ if( $_[0] =~ /^\d+$/ )
Branch: 2 branches
BranchTrueFalseTotal
if ($_[0] =~ /^\d+$/) { } 0 0 0
elsif (ref $_[-1] eq 'HASH' and exists $_[-1]{'level'}) { } 0 0 0
1057 {
1058 0 $message_level = shift( @_ );
1059 }
1060 ▶ elsif( ref( $_[-1] ) eq 'HASH' && CORE::exists( $_[-1]->{level} ) )
Condition0%0/3
ref $_[-1] eq "HASH" and exists $_[-1]{"level"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[-1] eq "HASH" and exists $_[-1]{"level"}
ref $_[-1] eq "HASH" exists $_[-1]{"level"}
Truth table0%0/3
A and B
A= ref $_[-1] eq "HASH"B= exists $_[-1]{"level"}
ABresult
0X0
100
111
1061 {
1062 0 $message_level = $_[-1]->{level};
1063 }
1064 0 my $target_re = '';
1065 0 ▶ if( ref( ${ "${class}::DEBUG_TARGET" } ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref ${"${class}::DEBUG_TARGET";} eq "ARRAY") 0 0 0
1066 {
1067 0 ▶ $target_re = scalar( @${ "${class}::DEBUG_TARGET" } ) ? join( '|', @${ "${class}::DEBUG_TARGET" } ) : '';
Branch: 1 branch
BranchTrueFalseTotal
scalar @${"${class}::DEBUG_TARGET";} ? : 0 0 0
1068 }
1069 0 ▶ if( int( $self->{debug} ) >= $message_level ||
Branch: 1 branch
BranchTrueFalseTotal
if (int $self->{'debug'} >= $message_level or int $self->{'verbose'} >= $message_level or defined ${$class . '::DEBUG';} and ${$class . '::DEBUG';} >= $message_level or int $self->{'debug_level'} >= $message_level or int $self->{'debug'} >= 100 or length $target_re and $class =~ /^$target_re$/ and ${$class . '::GLOBAL_DEBUG';} >= $message_level) { } 0 0 0
Condition0%0/18
int $self->{"debug"} >= $message_level or int $self->{"verbose"} >= $message_level or defined ${$class . '::DEBUG';} and ${$class . '::DEBUG';} >= $message_level or int $self->{"debug_level"} >= $message_level or int $self->{"debug"} >= 100 or length $target_re and $class =~ /^$target_re$/ and ${$class . '::GLOBAL_DEBUG';} >= $message_level
l!l&&r!l&&!r
000
int $self->{"debug"} >= $message_level or int $self->{"verbose"} >= $message_level or defined ${$class . '::DEBUG';} and ${$class . '::DEBUG';} >= $message_level or int $self->{"debug_level"} >= $message_level or int $self->{"debug"} >= 100
l!l&&r!l&&!r
000
int $self->{"debug"} >= $message_level or int $self->{"verbose"} >= $message_level or defined ${$class . '::DEBUG';} and ${$class . '::DEBUG';} >= $message_level or int $self->{"debug_level"} >= $message_level
l!l&&r!l&&!r
000
int $self->{"debug"} >= $message_level or int $self->{"verbose"} >= $message_level or defined ${$class . '::DEBUG';} and ${$class . '::DEBUG';} >= $message_level
l!l&&r!l&&!r
000
int $self->{"debug"} >= $message_level or int $self->{"verbose"} >= $message_level
l!l&&r!l&&!r
000
defined ${$class . '::DEBUG';} and ${$class . '::DEBUG';} >= $message_level
!ll&&!rl&&r
000
MC/DC0%0/7
int $self->{"debug"} >= $message_level or int $self->{"verbose"} >= $message_level or defined ${$class . '::DEBUG';} and ${$class . '::DEBUG';} >= $message_level or int $self->{"debug_level"} >= $message_level or int $self->{"debug"} >= 100 or length $target_re and $class =~ /^$target_re$/ and ${$class . '::GLOBAL_DEBUG';} >= $message_level
int $self->{"debug"} >= $message_level int $self->{"verbose"} >= $message_level defined ${$class . '::DEBUG';} ${$class . '::DEBUG';} >= $message_level int $self->{"debug_level"} >= $message_level int $self->{"debug"} >= 100 length $target_re and $class =~ /^$target_re$/ and ${$class . '::GLOBAL_DEBUG';} >= $message_level
Truth table0%0/11
A or B or C and D or E or F or G
A= int $self->{"debug"} >= $message_levelB= int $self->{"verbose"} >= $message_levelC= defined ${$class . '::DEBUG';}D= ${$class . '::DEBUG';} >= $message_levelE= int $self->{"debug_level"} >= $message_levelF= int $self->{"debug"} >= 100G= length $target_re and $class =~ /^$target_re$/ and ${$class . '::GLOBAL_DEBUG';} >= $message_level
ABCDEFGresult
1XXXXXX1
01XXXXX1
0011XXX1
000X1XX1
00101XX1
000X01X1
001001X1
000X0011
00100011
000X0000
00100000
1070 int( $self->{verbose} ) >= $message_level ||
1071 0 ▶ ( defined( ${ $class . '::DEBUG' } ) && ${ $class . '::DEBUG' } >= $message_level ) ||
Condition0%0/6
length $target_re and $class =~ /^$target_re$/ and ${$class . '::GLOBAL_DEBUG';} >= $message_level
!ll&&!rl&&r
000
length $target_re and $class =~ /^$target_re$/
!ll&&!rl&&r
000
MC/DC0%0/3
length $target_re and $class =~ /^$target_re$/ and ${$class . '::GLOBAL_DEBUG';} >= $message_level
length $target_re $class =~ /^$target_re$/ ${$class . '::GLOBAL_DEBUG';} >= $message_level
Truth table0%0/4
A and B and C
A= length $target_reB= $class =~ /^$target_re$/C= ${$class . '::GLOBAL_DEBUG';} >= $message_level
ABCresult
0XX0
10X0
1100
1111
1072 int( $self->{debug_level} ) >= $message_level ||
1073 int( $self->{debug} ) >= 100 ||
1074 0 ( length( $target_re ) && $class =~ /^$target_re$/ && ${ $class . '::GLOBAL_DEBUG' } >= $message_level ) )
1075 {
1076 0 return( [ @_ ] );
1077 }
1078 else
1079 {
1080 0 return(0);
1081 }
1082 }
1083 }
1084 0 return(0);
1085 }
1086  
1087 sub message_frame
1088 0 ▶{
Subroutine message_frame: not called CC=7 SCAR=40.3
Pod undocumented
1089 0 my $self = shift( @_ );
1090 0 ▶ $self->{_message_frame } = {} if( !exists( $self->{_message_frame} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_message_frame"} 0 0 0
1091 0 my $mf = $self->{_message_frame};
1092 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1093 {
1094 0 my $args = {};
1095 0 ▶ if( ref( $_[0] ) eq 'HASH' )
Branch: 3 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 0 0
elsif (not @_ % 2) { } 0 0 0
elsif (scalar @_ == 1) { } 0 0 0
1096 {
1097 0 $args = shift( @_ );
1098 0 my @k = keys( %$args );
1099 0 @$mf{ @k } = @$args{ @k };
1100 }
1101 elsif( !( @_ % 2 ) )
1102 {
1103 0 $args = { @_ };
1104 0 my @k = keys( %$args );
1105 0 @$mf{ @k } = @$args{ @k };
1106 }
1107 elsif( scalar( @_ ) == 1 )
1108 {
1109 0 my $sub = shift( @_ );
1110 0 ▶ $sub = substr( $sub, rindex( $sub, '::' ) + 2 ) if( index( $sub, '::' ) != -1 );
Branch: 1 branch
BranchTrueFalseTotal
if (index($sub, "::") != -1) 0 0 0
1111 0 return( $mf->{ $sub } );
1112 }
1113 else
1114 {
1115 0 return( $self->error( "I was expecting a key => value pair such as routine => stack frame (integer)" ) );
1116 }
1117 }
1118 0 return( $mf );
1119 }
1120  
1121 # For compatibility for MIME::Decoder->head, itself used by HTTP::Promise::Entity
1122 # "some decoders need to know a little about the file they are encoding/decoding; e.g., x-uu likes to have the filename. The HEAD is any object which responds to messages like:
1123 # $head->mime_attr( 'content-disposition.filename' );
1124 sub mime_attr
1125 10 ▶{
Subroutine mime_attr: called CC=13 SCAR=36.5
Pod documented
1126 10 my $self = shift( @_ );
1127 10 my( $attr, $value ) = @_;
1128 10 ▶ return if( !defined( $attr ) || !length( $attr ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attr and length $attr 0 10 10
Condition33%1/3
defined $attr and length $attr
!ll&&!rl&&r
0010
MC/DC0%0/2
defined $attr and length $attr
defined $attr length $attr
Truth table33%1/3
A and B
A= defined $attrB= length $attr
ABresult
0X0
100
111
1129 # Break attribute name up
1130 10 my( $tag, $subtag ) = split( /\./, $attr, 2 );
1131 10 my $v = $self->header( $tag );
1132 10 require Module::Generic::HeaderValue;
1133 10 my $hv;
1134 10 ▶ if( defined( $v ) && length( $v ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v and length $v) 10 0 10
Condition33%1/3
defined $v and length $v
!ll&&!rl&&r
0010
MC/DC0%0/2
defined $v and length $v
defined $v length $v
Truth table33%1/3
A and B
A= defined $vB= length $v
ABresult
0X0
100
111
1135 {
1136 10 $hv = Module::Generic::HeaderValue->new_from_header( $v );
1137 10 ▶ return( $self->pass_error( Module::Generic::HeaderValue->error ) ) if( !defined( $hv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hv 0 10 10
1138 }
1139 10 ▶ if( scalar( @_ ) > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 1) { } 0 10 10
1140 {
1141 0 ▶ if( defined( $subtag ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $subtag) { } 0 0 0
1142 {
1143 0 ▶ return( $self->error( "There is no header field '$tag' currently set, so you cannot assign a value for '$subtag'." ) ) if( !defined( $hv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hv 0 0 0
1144 0 $hv->param( $subtag => $value );
1145 }
1146 else
1147 {
1148 0 ▶ if( defined( $hv ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hv) { } 0 0 0
1149 {
1150 0 $hv->value( $value );
1151 }
1152 else
1153 {
1154 0 ▶ $hv = Module::Generic::HeaderValue->new( $value ) ||
Condition0%0/2
'Module::Generic::HeaderValue'->new($value) || (return $self->pass_error('Module::Generic::HeaderValue'->error))
l!l
00
MC/DC0%0/1
'Module::Generic::HeaderValue'->new($value) || (return $self->pass_error('Module::Generic::HeaderValue'->error))
'Module::Generic::HeaderValue'->new($value)
Truth table0%0/2
A
A= 'Module::Generic::HeaderValue'->new($value)
Aresult
11
00
1155 return( $self->pass_error( Module::Generic::HeaderValue->error ) );
1156 }
1157 }
1158 0 $self->replace( $tag => "$hv" );
1159 0 return( $value );
1160 }
1161 else
1162 {
1163 10 ▶ return( '' ) if( !defined( $hv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hv 0 10 10
1164 10 ▶ return( defined( $subtag ) ? $hv->param( $subtag ) : $hv->value_data );
Branch: 1 branch
BranchTrueFalseTotal
defined $subtag ? : 8 2 10
1165 }
1166 }
1167  
1168 # In HTTP parlance, the request may contain a Content-Encoding in multipart/form-data,
1169 # and the server response may contain Transfer-Encoding to indicate in which encoding the
1170 # response is provided.
1171 sub mime_encoding
1172 0 ▶{
Subroutine mime_encoding: not called CC=4 SCAR=30.0
Pod documented
1173 0 my $self = shift( @_ );
1174 0 ▶ my $te = $self->header( 'Content-Encoding' ) || $self->header( 'Transfer-Encoding' );
Condition0%0/3
$self->header('Content-Encoding') || $self->header('Transfer-Encoding')
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->header('Content-Encoding') || $self->header('Transfer-Encoding')
$self->header('Content-Encoding') $self->header('Transfer-Encoding')
Truth table0%0/3
A || B
A= $self->header('Content-Encoding')B= $self->header('Transfer-Encoding')
ABresult
1X1
011
000
1175 0 ▶ return( '' ) if( !defined( $te ) || !length( $te ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $te and length $te 0 0 0
Condition0%0/3
defined $te and length $te
!ll&&!rl&&r
000
MC/DC0%0/2
defined $te and length $te
defined $te length $te
Truth table0%0/3
A and B
A= defined $teB= length $te
ABresult
0X0
100
111
1176 0 my $enc = lc( $te );
1177 # 7-bit, 7_bit -> 7bit. Same for 8-bit, 8_bit
1178 0 $enc =~ s{^([78])[ _-]bit\Z}{$1bit};
1179 0 return( $enc );
1180 }
1181  
1182 sub mime_type
1183 51 ▶{
Subroutine mime_type: called CC=5 SCAR=16.2
Pod documented
1184 51 my $self = shift( @_ );
1185 51 ▶ my $default = shift( @_ ) || $self->default_type;
Condition66%2/3
shift @_ || $self->default_type
l!l&&r!l&&!r
11040
MC/DC50%1/2
shift @_ || $self->default_type
shift @_ $self->default_type
Truth table66%2/3
A || B
A= shift @_B= $self->default_type
ABresult
1X1
011
000
1186 51 my $ct = $self->type;
1187 51 ▶ if( !defined( $ct ) || !length( $ct ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ct and length $ct) 16 35 51
Condition66%2/3
defined $ct and length $ct
!ll&&!rl&&r
16035
MC/DC50%1/2
defined $ct and length $ct
defined $ct length $ct
Truth table66%2/3
A and B
A= defined $ctB= length $ct
ABresult
0X0
100
111
1188 {
1189 16 ▶ return( $default ) if( defined( $default ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $default 3 13 16
1190 13 return( '' );
1191 }
1192 35 return( $ct );
1193 }
1194  
1195 sub multipart_boundary
1196 5 ▶{
Subroutine multipart_boundary: called CC=6 SCAR=20.2
Pod documented
1197 5 my $self = shift( @_ );
1198 5 my $ct = $self->content_type;
1199 5 ▶ return( '' ) unless( defined( $ct ) && length( "$ct" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ct and length "$ct" 0 5 5
Condition33%1/3
defined $ct and length "$ct"
!ll&&!rl&&r
005
MC/DC0%0/2
defined $ct and length "$ct"
defined $ct length "$ct"
Truth table33%1/3
A and B
A= defined $ctB= length "$ct"
ABresult
0X0
100
111
1200 # There is no attributes to this Content-Type, so no need to go further.
1201 5 ▶ return( '' ) if( index( $ct, ';' ) == -1 || index( $ct, 'boundary' ) == -1 );
Branch: 1 branch
BranchTrueFalseTotal
if index($ct, ";") == -1 or index($ct, "boundary") == -1 0 5 5
Condition33%1/3
index($ct, ";") == -1 or index($ct, "boundary") == -1
l!l&&r!l&&!r
005
MC/DC0%0/2
index($ct, ";") == -1 or index($ct, "boundary") == -1
index($ct, ";") == -1 index($ct, "boundary") == -1
Truth table33%1/3
A or B
A= index($ct, ";") == -1B= index($ct, "boundary") == -1
ABresult
1X1
011
000
1202 5 require Module::Generic::HeaderValue;
1203 5 ▶ my $hv = Module::Generic::HeaderValue->new_from_header( $ct ) ||
Condition50%1/2
'Module::Generic::HeaderValue'->new_from_header($ct) || (return $self->pass_error('Module::Generic::HeaderValue'->error))
l!l
50
MC/DC0%0/1
'Module::Generic::HeaderValue'->new_from_header($ct) || (return $self->pass_error('Module::Generic::HeaderValue'->error))
'Module::Generic::HeaderValue'->new_from_header($ct)
Truth table50%1/2
A
A= 'Module::Generic::HeaderValue'->new_from_header($ct)
Aresult
11
00
1204 return( $self->pass_error( Module::Generic::HeaderValue->error ) );
1205 5 my $boundary = $hv->param( 'boundary' );
1206 5 return( $boundary );
1207 }
1208  
1209 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/NEL>
1210 0 ▶sub nel { return( shift->_set_get_one( 'NEL', @_ ) ); }
Subroutine nel: not called CC=1 SCAR=6.9
Pod documented
1211  
1212 sub new_array
1213 22 ▶{
Subroutine new_array: called CC=1 SCAR=0.0
Pod undocumented
1214 22 my $self = shift( @_ );
1215 22 require Module::Generic::Array;
1216 22 return( Module::Generic::Array->new( @_ ) );
1217 }
1218  
1219 sub new_field
1220 76 ▶{
Subroutine new_field: called CC=12 SCAR=37.5
Pod undocumented
1221 76 my $self = shift( @_ );
1222 76 my $field = shift( @_ );
1223 76 ▶ return( $self->error( "No header field name was provided." ) ) if( !defined( $field ) || !length( "$field" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field and length "$field" 0 76 76
Condition33%1/3
defined $field and length "$field"
!ll&&!rl&&r
0076
MC/DC0%0/2
defined $field and length "$field"
defined $field length "$field"
Truth table33%1/3
A and B
A= defined $fieldB= length "$field"
ABresult
0X0
100
111
1224 76 ▶ unless( scalar( keys( %$SUPPORTED ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar keys %$HTTP::Promise::Headers::SUPPORTED) 0 76 76
1225 {
1226 0 ▶ $self->_load_class( 'Module::Generic::File' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::File") or return $self->pass_error 0 0 0
1227 0 ▶ my $dir = Module::Generic::File->new( ( $MOD_PATH || __FILE__ ) )->extension( undef );
Condition0%0/2
$HTTP::Promise::Headers::MOD_PATH || __FILE__
l!l
00
MC/DC0%0/1
$HTTP::Promise::Headers::MOD_PATH || __FILE__
$HTTP::Promise::Headers::MOD_PATH
Truth table0%0/2
A
A= $HTTP::Promise::Headers::MOD_PATH
Aresult
11
00
1228 0 ▶ $dir->open || return( $self->error( "Unable to open directory \"$dir\": ", $dir->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$dir->open or return $self->error(qq[Unable to open directory "$dir": ], $dir->error) 0 0 0
1229 0 my $f;
1230 0 ▶ while( defined( $f = $dir->read( exclude_invisible => 1, as_object => 1 ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($f = $dir->read("exclude_invisible", 1, "as_object", 1))) 0 0 0
1231 {
1232 0 ▶ next if( $f->extension ne 'pm' );
Branch: 1 branch
BranchTrueFalseTotal
if $f->extension ne "pm" 0 0 0
1233 0 my $base = $f->basename( '.pm' );
1234 0 $SUPPORTED->{ lc( $base ) } = "HTTP\::Promise\::Headers\::${base}";
1235 }
1236 }
1237 76 ( my $name = $field ) =~ s/[\-_]+//g;
1238 76 $name = lc( $name );
1239 76 ▶ return( $self->error( "Unsupported field \"$field\"." ) ) if( !exists( $SUPPORTED->{ $name } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $HTTP::Promise::Headers::SUPPORTED->{$name} 0 76 76
1240 76 my $class = $SUPPORTED->{ $name };
1241 76 ▶ $self->_load_class( $class ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($class) or return $self->pass_error 76 0 76
1242 76 ▶ my $o = $class->new( @_ ) ||
Condition50%1/2
$class->new(@_) || (return $self->pass_error($class->error))
l!l
760
MC/DC0%0/1
$class->new(@_) || (return $self->pass_error($class->error))
$class->new(@_)
Truth table50%1/2
A
A= $class->new(@_)
Aresult
11
00
1243 return( $self->pass_error( $class->error ) );
1244 76 return( $o );
1245 }
1246  
1247 sub new_number
1248 1 ▶{
Subroutine new_number: called CC=1 SCAR=0.0
Pod undocumented
1249 1 my $self = shift( @_ );
1250 1 require Module::Generic::Number;
1251 1 return( Module::Generic::Number->new( @_ ) );
1252 }
1253  
1254 sub new_scalar
1255 222 ▶{
Subroutine new_scalar: called CC=1 SCAR=0.0
Pod undocumented
1256 222 my $self = shift( @_ );
1257 222 require Module::Generic::Scalar;
1258 222 return( Module::Generic::Scalar->new( @_ ) );
1259 }
1260  
1261 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin>
1262 0 ▶sub origin { return( shift->_set_get_one_uri( 'Origin', @_ ) ); }
Subroutine origin: not called CC=1 SCAR=6.9
Pod documented
1263  
1264 # Purpose is to get an error object thrown from, possibly another package,
1265 # and make it ours and pass it along
1266 # e.g.:
1267 # $self->pass_error
1268 # $self->pass_error( 'Some error that will be passed to error()' );
1269 # $self->pass_error( $error_object );
1270 # $self->pass_error( $error_object, { class => 'Some::ExceptionClass', code => 400 } );
1271 # $self->pass_error({ class => 'Some::ExceptionClass' });
1272 sub pass_error
1273 0 ▶{
Subroutine pass_error: not called CC=41 SCAR=73.9
Pod undocumented
1274 0 my $self = shift( @_ );
1275 0 ▶ my $class = ref( $self ) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
1276 0 my $opts = {};
1277 0 my $err;
1278 my $ex_class;
1279 0 my $code;
1280 0 my $callback;
1281 12 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1282 0 ▶ my $err_key = HAS_THREADS() ? join( ';', $class, $$, threads->tid ) : join( ';', $class, $$ );
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 0 0 0
1283 0 my $repo = Module::Generic::Global->new( 'errors' => $class, key => $err_key );
1284  
1285 0 ▶ if( scalar( @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 0 0 0
1286 {
1287 # Either an hash defining a new error and this will be passed along to error(); or
1288 # an hash with a single property: { class => 'Some::ExceptionClass' }
1289 0 ▶ if( scalar( @_ ) == 1 && ref( $_[0] ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1 and ref $_[0] eq 'HASH') { } 0 0 0
Condition0%0/3
scalar @_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and ref $_[0] eq "HASH"
scalar @_ == 1 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= scalar @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
1290 {
1291 0 $opts = $_[0];
1292 }
1293 else
1294 {
1295 # $self->pass_error( $error_object, { class => 'Some::ExceptionClass' } );
1296 0 ▶ if( scalar( @_ ) > 1 && ref( $_[-1] ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 1 and ref $_[-1] eq "HASH") 0 0 0
Condition0%0/3
scalar @_ > 1 and ref $_[-1] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ > 1 and ref $_[-1] eq "HASH"
scalar @_ > 1 ref $_[-1] eq "HASH"
Truth table0%0/3
A and B
A= scalar @_ > 1B= ref $_[-1] eq "HASH"
ABresult
0X0
100
111
1297 {
1298 0 $opts = pop( @_ );
1299 }
1300 0 $err = $_[0];
1301 }
1302 }
1303 0 ▶ $err = $opts->{error} if( !defined( $err ) && CORE::exists( $opts->{error} ) && defined( $opts->{error} ) && CORE::length( $opts->{error} ) );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $err and exists $opts->{"error"} and defined $opts->{"error"} and length $opts->{"error"} 0 0 0
Condition0%0/9
not defined $err and exists $opts->{"error"} and defined $opts->{"error"} and length $opts->{"error"}
!ll&&!rl&&r
000
not defined $err and exists $opts->{"error"} and defined $opts->{"error"}
!ll&&!rl&&r
000
not defined $err and exists $opts->{"error"}
!ll&&!rl&&r
000
MC/DC0%0/4
not defined $err and exists $opts->{"error"} and defined $opts->{"error"} and length $opts->{"error"}
not defined $err exists $opts->{"error"} defined $opts->{"error"} length $opts->{"error"}
Truth table0%0/5
not(A) and B and C and D
A= not defined $errB= exists $opts->{"error"}C= defined $opts->{"error"}D= length $opts->{"error"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1304 # We set $ex_class only if the hash provided is a one-element hash and not an error-defining hash
1305 # $class = CORE::delete( $opts->{class} ) if( scalar( keys( %$opts ) ) == 1 && [keys( %$opts )]->[0] eq 'class' );
1306 0 ▶ $ex_class = $opts->{class} if( CORE::exists( $opts->{class} ) && defined( $opts->{class} ) && CORE::length( $opts->{class} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"class"} and defined $opts->{"class"} and length $opts->{"class"} 0 0 0
Condition0%0/6
exists $opts->{"class"} and defined $opts->{"class"} and length $opts->{"class"}
!ll&&!rl&&r
000
exists $opts->{"class"} and defined $opts->{"class"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $opts->{"class"} and defined $opts->{"class"} and length $opts->{"class"}
exists $opts->{"class"} defined $opts->{"class"} length $opts->{"class"}
Truth table0%0/4
A and B and C
A= exists $opts->{"class"}B= defined $opts->{"class"}C= length $opts->{"class"}
ABCresult
0XX0
10X0
1100
1111
1307 0 ▶ $code = $opts->{code} if( CORE::exists( $opts->{code} ) && defined( $opts->{code} ) && CORE::length( $opts->{code} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"code"} and defined $opts->{"code"} and length $opts->{"code"} 0 0 0
Condition0%0/6
exists $opts->{"code"} and defined $opts->{"code"} and length $opts->{"code"}
!ll&&!rl&&r
000
exists $opts->{"code"} and defined $opts->{"code"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $opts->{"code"} and defined $opts->{"code"} and length $opts->{"code"}
exists $opts->{"code"} defined $opts->{"code"} length $opts->{"code"}
Truth table0%0/4
A and B and C
A= exists $opts->{"code"}B= defined $opts->{"code"}C= length $opts->{"code"}
ABCresult
0XX0
10X0
1100
1111
1308 0 ▶ $callback = $opts->{callback} if( CORE::exists( $opts->{callback} ) && defined( $opts->{callback} ) && ref( $opts->{callback} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"callback"} and defined $opts->{"callback"} and ref $opts->{"callback"} 0 0 0
Condition0%0/6
exists $opts->{"callback"} and defined $opts->{"callback"} and ref $opts->{"callback"}
!ll&&!rl&&r
000
exists $opts->{"callback"} and defined $opts->{"callback"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $opts->{"callback"} and defined $opts->{"callback"} and ref $opts->{"callback"}
exists $opts->{"callback"} defined $opts->{"callback"} ref $opts->{"callback"}
Truth table0%0/4
A and B and C
A= exists $opts->{"callback"}B= defined $opts->{"callback"}C= ref $opts->{"callback"}
ABCresult
0XX0
10X0
1100
1111
1309  
1310 # called with no argument, most likely from the same class to pass on an error
1311 # set up earlier by another method; or
1312 # with an hash containing just one argument class => 'Some::ExceptionClass'
1313 0 ▶ if( !defined( $err ) && ( !scalar( @_ ) || defined( $ex_class ) ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $err and !scalar(@_) || defined $ex_class) { } 0 0 0
elsif (defined $err and builtin::blessed($err) and scalar @_ == 1 || scalar @_ == 2 && defined $ex_class) { } 0 0 0
Condition0%0/6
not defined $err and !scalar(@_) || defined $ex_class
!ll&&!rl&&r
000
not scalar @_ or defined $ex_class
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $err and !scalar(@_) || defined $ex_class
not defined $err not scalar @_ defined $ex_class
Truth table0%0/4
not(A) and not(B) or C
A= not defined $errB= not scalar @_C= defined $ex_class
ABCresult
0XX0
1000
11X1
1011
1314 {
1315 0 my $error;
1316 0 ▶ if( Scalar::Util::blessed( $self ) )
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($self)) { } 0 0 0
elsif ($repo->exists) { } 0 0 0
1317 {
1318 0 $error = $self->{error};
1319 }
1320 elsif( $repo->exists )
1321 {
1322 0 $error = $repo->get;
1323 }
1324  
1325 0 ▶ if( !defined( $error ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $error) { } 0 0 0
1326 {
1327 0 warn( "No error object provided and no previous error set either! It seems the previous method call returned a simple undef\n", $self->_get_stack_trace );
1328 }
1329 else
1330 {
1331 0 ▶ $err = ( defined( $ex_class ) ? bless( $error => $ex_class ) : $error );
Branch: 1 branch
BranchTrueFalseTotal
defined $ex_class ? : 0 0 0
1332 0 ▶ $err->code( $code ) if( defined( $code ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $code 0 0 0
1333 }
1334 }
1335 # An error object was provided
1336 ▶ elsif( defined( $err ) &&
Condition0%0/12
defined $err and builtin::blessed($err) and scalar @_ == 1 || scalar @_ == 2 && defined $ex_class
!ll&&!rl&&r
000
defined $err and builtin::blessed($err)
!ll&&!rl&&r
000
scalar @_ == 1 or scalar @_ == 2 and defined $ex_class
l!l&&r!l&&!r
000
scalar @_ == 2 and defined $ex_class
!ll&&!rl&&r
000
MC/DC0%0/5
defined $err and builtin::blessed($err) and scalar @_ == 1 || scalar @_ == 2 && defined $ex_class
defined $err builtin::blessed($err) scalar @_ == 1 scalar @_ == 2 defined $ex_class
Truth table0%0/6
A and B and C or D and E
A= defined $errB= builtin::blessed($err)C= scalar @_ == 1D= scalar @_ == 2E= defined $ex_class
ABCDEresult
0XXXX0
10XXX0
1100X0
110100
111XX1
110111
1337 Scalar::Util::blessed( $err ) &&
1338 ( scalar( @_ ) == 1 ||
1339 ( scalar( @_ ) == 2 && defined( $ex_class ) )
1340 ) )
1341 {
1342 # If necessary, we re-bless the error object to the designated class
1343 0 ▶ my $o = ( defined( $ex_class ) ? bless( $err => $ex_class ) : $err );
Branch: 1 branch
BranchTrueFalseTotal
defined $ex_class ? : 0 0 0
1344 0 $self->{error} = $o;
1345 # We ned to be backward compatible, and allow the user to access $My::Module::ERROR
1346 0 $repo->set( $o );
1347 0 ${ $class . '::ERROR' } = $o;
1348 0 ▶ $self->{error}->code( $code ) if( defined( $code ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $code 0 0 0
1349  
1350 0 ▶ if( $self->{fatal} || ( defined( ${"${class}\::FATAL_ERROR"} ) && ${"${class}\::FATAL_ERROR"} ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"fatal"} or defined ${"${class}::FATAL_ERROR";} and ${"${class}::FATAL_ERROR";}) 0 0 0
Condition0%0/6
$self->{"fatal"} or defined ${"${class}::FATAL_ERROR";} and ${"${class}::FATAL_ERROR";}
l!l&&r!l&&!r
000
defined ${"${class}::FATAL_ERROR";} and ${"${class}::FATAL_ERROR";}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"fatal"} or defined ${"${class}::FATAL_ERROR";} and ${"${class}::FATAL_ERROR";}
$self->{"fatal"} defined ${"${class}::FATAL_ERROR";} ${"${class}::FATAL_ERROR";}
Truth table0%0/4
A or B and C
A= $self->{"fatal"}B= defined ${"${class}::FATAL_ERROR";}C= ${"${class}::FATAL_ERROR";}
ABCresult
1XX1
0111
00X0
0100
1351 {
1352 0 die( $self->{error} );
1353 }
1354 }
1355 # If the error provided is not an object, we call error to create one
1356 else
1357 {
1358 0 return( $self->error( @_ ) );
1359 }
1360  
1361 0 ▶ if( want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (want("OBJECT")) 0 0 0
1362 {
1363 0 ▶ $self->_load_class( 'Module::Generic::Null' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Null") or die "Unable to load Module::Generic::Null" 0 0 0
1364 die( "Unable to load Module::Generic::Null" );
1365 0 my $null = Module::Generic::Null->new( $err, { debug => $self->{debug}, has_error => 1 });
1366 0 rreturn( $null );
1367 }
1368 0 return;
1369 }
1370  
1371 sub print
1372 22 ▶{
Subroutine print: called CC=5 SCAR=18.1
Pod documented
1373 22 my $self = shift( @_ );
1374 22 my $fh = shift( @_ );
1375 22 my $opts = $self->_get_args_as_hash( @_ );
1376 22 ▶ my $eol = $opts->{eol} || CRLF;
Condition50%1/2
$opts->{'eol'} || "\r\n"
l!l
220
MC/DC0%0/1
$opts->{'eol'} || "\r\n"
$opts->{'eol'}
Truth table50%1/2
A
A= $opts->{'eol'}
Aresult
11
00
1377 22 ▶ $fh ||= select;
Condition33%1/3
$fh ||= select
l!l&&r!l&&!r
2200
MC/DC0%0/2
$fh ||= select
$fh select
Truth table33%1/3
A ||= B
A= $fhB= select
ABresult
1X1
011
000
1378 22 ▶ return( $self->error( "Filehandle provided ($fh) is not a proper filehandle and its not a HTTP::Promise::IO object." ) ) if( !$self->_is_glob( $fh ) && !$self->_is_a( $fh => 'HTTP::Promise::IO' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_glob($fh) or $self->_is_a($fh, "HTTP::Promise::IO") 0 22 22
Condition33%1/3
$self->_is_glob($fh) or $self->_is_a($fh, "HTTP::Promise::IO")
l!l&&r!l&&!r
0220
MC/DC0%0/2
$self->_is_glob($fh) or $self->_is_a($fh, "HTTP::Promise::IO")
$self->_is_glob($fh) $self->_is_a($fh, "HTTP::Promise::IO")
Truth table33%1/3
A or B
A= $self->_is_glob($fh)B= $self->_is_a($fh, "HTTP::Promise::IO")
ABresult
1X1
011
000
1379 22 return( $fh->print( $self->as_string( $eol ) ) );
1380 }
1381  
1382 0 ▶sub proxy { return( shift->_set_get_uri( 'proxy', @_ ) ); }
Subroutine proxy: not called CC=1 SCAR=6.9
Pod documented
1383  
1384 # NOTE: proxy_authenticate() is inherited
1385 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Proxy-Authenticate>
1386 3 ▶sub proxy_authenticate { return( shift->_set_get_one( 'Proxy-Authenticate', @_ ) ); }
Subroutine proxy_authenticate: called CC=1 SCAR=0.0
Pod documented
1387  
1388 # NOTE: proxy_authorization() is inherited
1389 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Proxy-Authorization>
1390 1 ▶sub proxy_authorization { return( shift->_set_get_one( 'Proxy-Authorization', @_ ) ); }
Subroutine proxy_authorization: called CC=1 SCAR=0.0
Pod documented
1391  
1392 # NOTE: proxy_authorization_basic() is inherited
1393  
1394 # NOTE: push_header() is inherited
1395  
1396 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range>
1397 0 ▶sub range { return( shift->_set_get_multi( 'Range', @_ ) ); }
Subroutine range: not called CC=1 SCAR=6.9
Pod documented
1398  
1399 sub recommended_filename
1400 1 ▶{
Subroutine recommended_filename: called CC=5 SCAR=16.6
Pod documented
1401 1 my $self = shift( @_ );
1402 1 foreach my $attr_name ( qw( content-disposition.filename* content-disposition.filename content-type.name ) )
1403 {
1404 2 my $value = $self->mime_attr( $attr_name );
1405 2 ▶ if( defined( $value ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and $value ne "" and $value =~ /\S/) 1 1 2
Condition66%4/6
defined $value and $value ne "" and $value =~ /\S/
!ll&&!rl&&r
101
defined $value and $value ne ""
!ll&&!rl&&r
101
MC/DC33%1/3
defined $value and $value ne "" and $value =~ /\S/
defined $value $value ne "" $value =~ /\S/
Truth table50%2/4
A and B and C
A= defined $valueB= $value ne ""C= $value =~ /\S/
ABCresult
0XX0
10X0
1100
1111
1406 $value ne '' &&
1407 $value =~ /\S/ )
1408 {
1409 1 return( $self->decode_filename( $value ) );
1410 }
1411 }
1412 0 return;
1413 }
1414  
1415 # NOTE: referer() and referrer() are inherited
1416 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer>
1417 8 ▶sub referer { return( shift->_set_get_one_uri( 'Referer', @_ ) ); }
Subroutine referer: called CC=1 SCAR=0.0
Pod documented
1418  
1419 2 ▶sub referrer { return( shift->referer( @_ ) ); }
Subroutine referrer: called CC=1 SCAR=0.0
Pod documented
1420  
1421 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy>
1422 0 ▶sub referrer_policy { return( shift->_set_get_one( 'Referrer-Policy', @_ ) ); }
Subroutine referrer_policy: not called CC=1 SCAR=6.9
Pod documented
1423  
1424 8 ▶sub remove { return( shift->remove_header( @_ ) ); }
Subroutine remove: called CC=1 SCAR=0.0
Pod documented
1425  
1426 # NOTE: remove_header() is inherited
1427  
1428 # NOTE: remove_content_headers() is inherited
1429  
1430 sub replace
1431 30 ▶{
Subroutine replace: called CC=5 SCAR=18.3
Pod documented
1432 30 my $self = shift( @_ );
1433 30 my( $field, $value ) = @_;
1434 30 ▶ unless( defined( $field ) && length( $field // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $field and length($field // "")) 0 30 30
Condition40%2/5
defined $field and length($field // "")
!ll&&!rl&&r
0030
$field // ""
l!l
300
MC/DC0%0/2
defined $field and length($field // "")
defined $field $field
Truth table33%1/3
A and B
A= defined $fieldB= $field
ABresult
0X0
100
111
1435 {
1436 0 return( $self->error( "No header name was provided." ) );
1437 }
1438 30 ( my $meth = $field ) =~ tr/-/_/;
1439 30 $meth = lc( $meth );
1440 30 ▶ if( my $ref = $self->can( $meth ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $ref = $self->can($meth)) { } 30 0 30
1441 {
1442 30 $ref->( $self, $value );
1443 }
1444 else
1445 {
1446 0 $self->header( $field => $value );
1447 }
1448 30 return( $self );
1449 }
1450  
1451 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Request-Headers>
1452 0 ▶sub request_headers { return( shift->_set_get_one( 'Access-Control-Request-Headers', @_ ) ); }
Subroutine request_headers: not called CC=1 SCAR=6.9
Pod documented
1453  
1454 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Request-Method>
1455 0 ▶sub request_method { return( shift->_set_get_one( 'Access-Control-Request-Method', @_ ) ); }
Subroutine request_method: not called CC=1 SCAR=6.9
Pod documented
1456  
1457 0 ▶sub request_timeout { return( shift->_set_get_number( 'request_timeout', @_ ) ); }
Subroutine request_timeout: not called CC=1 SCAR=6.9
Pod documented
1458  
1459 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After>
1460 0 ▶sub retry_after { return( shift->_set_get_one( 'Retry-After', @_ ) ); }
Subroutine retry_after: not called CC=1 SCAR=6.9
Pod documented
1461  
1462 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Save-Data>
1463 0 ▶sub save_data { return( shift->_set_get_one( 'Save-Data', @_ ) ); }
Subroutine save_data: not called CC=1 SCAR=6.9
Pod documented
1464  
1465 # NOTE: scan() is inherited
1466  
1467 # NOTE: server() is inherited
1468 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server>
1469 3 ▶sub server { return( shift->_set_get_one( 'Server', @_ ) ); }
Subroutine server: called CC=1 SCAR=0.0
Pod documented
1470  
1471 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server-Timing>
1472 0 ▶sub server_timing { return( shift->_set_get_one( 'Server-Timing', @_ ) ); }
Subroutine server_timing: not called CC=1 SCAR=6.9
Pod documented
1473  
1474 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie>
1475 0 ▶sub set_cookie { return( shift->_set_get_one( 'Set-Cookie', @_ ) ); }
Subroutine set_cookie: not called CC=1 SCAR=6.9
Pod documented
1476  
1477 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/SourceMap>
1478 0 ▶sub sourcemap { return( shift->_set_get_one( 'SourceMap', @_ ) ); }
Subroutine sourcemap: not called CC=1 SCAR=6.9
Pod documented
1479  
1480 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security>
1481 0 ▶sub strict_transport_security { return( shift->_set_get_one( 'Strict-Transport-Security', @_ ) ); }
Subroutine strict_transport_security: not called CC=1 SCAR=6.9
Pod documented
1482  
1483 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/TE>
1484 0 ▶sub te { return( shift->_set_get_one( 'TE', @_ ) ); }
Subroutine te: not called CC=1 SCAR=6.9
Pod documented
1485  
1486 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Timing-Allow-Origin>
1487 0 ▶sub timing_allow_origin { return( shift->_set_get_multi( 'Timing-Allow-Origin', @_ ) ); }
Subroutine timing_allow_origin: not called CC=1 SCAR=6.9
Pod documented
1488  
1489 # NOTE: title() is inherited and sucks really
1490 3 ▶sub title { return( shift->_set_get_one( 'Title', @_ ) ); }
Subroutine title: called CC=1 SCAR=0.0
Pod documented
1491  
1492 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Tk>
1493 0 ▶sub tk { return( shift->_set_get_one( 'Tk', @_ ) ); }
Subroutine tk: not called CC=1 SCAR=6.9
Pod documented
1494  
1495 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Trailer>
1496 0 ▶sub trailer { return( shift->_set_get_one( 'Trailer', @_ ) ); }
Subroutine trailer: not called CC=1 SCAR=6.9
Pod documented
1497  
1498 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Transfer-Encoding>
1499 0 ▶sub transfer_encoding { return( shift->_set_get_one( 'Transfer-Encoding', @_ ) ); }
Subroutine transfer_encoding: not called CC=1 SCAR=6.9
Pod documented
1500  
1501 sub type
1502 139 ▶{
Subroutine type: called CC=11 SCAR=25.5
Pod documented
1503 139 my $self = shift( @_ );
1504 139 ▶ if( @_ )
Branch: 2 branches
BranchTrueFalseTotal
if (@_) { } 0 139 139
elsif (length $self->{'type'} and $self->{'_ctype_cached'} eq $self->content_type) { } 52 87 139
1505 {
1506 # mime-type like text/html, text/plain or application/json, etc...
1507 0 my $type = shift( @_ );
1508 0 $self->{type} = $type;
1509 # We are being provided with content type parameters, such as charset=utf8, or version=1
1510 0 my $ct = $self->new_field( 'Content-Type' => $type, @_ );
1511 0 $self->header( 'Content-Type' => "$ct" );
1512 0 $self->{_ctype_cached} = "$ct";
1513 0 ▶ $self->{boundary} = $ct->boundary if( $ct->boundary );
Branch: 1 branch
BranchTrueFalseTotal
if $ct->boundary 0 0 0
1514 }
1515 # Cached
1516 ▶ elsif( CORE::length( $self->{type} ) && $self->{_ctype_cached} eq $self->content_type )
Condition100%3/3
length $self->{"type"} and $self->{"_ctype_cached"} eq $self->content_type
!ll&&!rl&&r
771052
MC/DC100%2/2
length $self->{"type"} and $self->{"_ctype_cached"} eq $self->content_type
length $self->{"type"} $self->{"_ctype_cached"} eq $self->content_type
Truth table100%3/3
A and B
A= length $self->{"type"}B= $self->{"_ctype_cached"} eq $self->content_type
ABresult
0X0
100
111
1517 {
1518 52 return( $self->{type} );
1519 }
1520 else
1521 {
1522 87 my $ctype_raw = $self->content_type;
1523 87 ▶ return if( !defined( $ctype_raw ) || !length( "$ctype_raw" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ctype_raw and length "$ctype_raw" 53 34 87
Condition66%2/3
defined $ctype_raw and length "$ctype_raw"
!ll&&!rl&&r
53034
MC/DC50%1/2
defined $ctype_raw and length "$ctype_raw"
defined $ctype_raw length "$ctype_raw"
Truth table66%2/3
A and B
A= defined $ctype_rawB= length "$ctype_raw"
ABresult
0X0
100
111
1524 34 $self->{_ctype_cached} = $ctype_raw;
1525 # There is nothing, but the mime-type itself, so no need to bother
1526 34 ▶ if( index( $ctype_raw, ';' ) == -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($ctype_raw, ';') == -1) { } 20 14 34
1527 {
1528 20 $self->{type} = $ctype_raw;
1529 20 $self->{boundary} = '';
1530 }
1531 else
1532 {
1533 # Content-Type: application/json; encoding=utf-8
1534 14 my $ct = $self->new_field( 'Content-Type' => $ctype_raw );
1535 14 ▶ return( $self->pass_error ) if( !defined( $ct ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ct 0 14 14
1536 # Accept: application/json; version=1.0; charset=utf-8
1537 14 $self->{type} = lc( $ct->type );
1538 14 my $charset = $ct->charset;
1539 14 ▶ $charset = lc( $charset ) if( defined( $charset ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $charset 3 11 14
1540 14 $self->{charset} = $charset;
1541 14 ▶ $self->{boundary} = $ct->boundary if( $ct->boundary );
Branch: 1 branch
BranchTrueFalseTotal
if $ct->boundary 5 9 14
1542 }
1543 }
1544 34 return( $self->{type} );
1545 }
1546  
1547 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Upgrade>
1548 0 ▶sub upgrade { return( shift->_set_get_multi( 'Upgrade', @_ ) ); }
Subroutine upgrade: not called CC=1 SCAR=6.9
Pod documented
1549  
1550 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Upgrade-Insecure-Requests>
1551 0 ▶sub upgrade_insecure_requests { return( shift->_set_get_one( 'Upgrade-Insecure-Requests', @_ ) ); }
Subroutine upgrade_insecure_requests: not called CC=1 SCAR=6.9
Pod documented
1552  
1553 3 ▶sub uri_escape_utf8 { return( URI::Escape::XS::uri_escape( Encode::encode( 'UTF-8', $_[1] ) ) ); }
Subroutine uri_escape_utf8: called CC=1 SCAR=0.0
Pod documented
1554  
1555 # NOTE: user_agent() is inherited
1556 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent>
1557 3 ▶sub user_agent { return( shift->_set_get_one( 'user_agent', @_ ) ); }
Subroutine user_agent: called CC=1 SCAR=0.0
Pod documented
1558  
1559 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Vary>
1560 0 ▶sub vary { return( shift->_set_get_multi( 'Vary', @_ ) ); }
Subroutine vary: not called CC=1 SCAR=6.9
Pod documented
1561  
1562 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Via>
1563 0 ▶sub via { return( shift->_set_get_multi( 'Via', @_ ) ); }
Subroutine via: not called CC=1 SCAR=6.9
Pod documented
1564  
1565 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Want-Digest>
1566 0 ▶sub want_digest { return( shift->_set_get_multi( 'Want-Digest', @_ ) ); }
Subroutine want_digest: not called CC=1 SCAR=6.9
Pod documented
1567  
1568 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Warning>
1569 0 ▶sub warning { return( shift->_set_get_one( 'Warning', @_ ) ); }
Subroutine warning: not called CC=1 SCAR=6.9
Pod documented
1570  
1571 # NOTE: www_authenticate() is superseded
1572 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/WWW-Authenticate>
1573 3 ▶sub www_authenticate { return( shift->_set_get_one( 'WWW-Authenticate', @_ ) ); }
Subroutine www_authenticate: called CC=1 SCAR=0.0
Pod documented
1574  
1575 0 ▶sub x { return( shift->_set_get_one( 'X-' . $_[0], @_ ) ); }
Subroutine x: not called CC=1 SCAR=6.9
Pod documented
1576  
1577 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options>
1578 0 ▶sub x_content_type_options { return( shift->_set_get_one( 'X-Content-Type-Options', @_ ) ); }
Subroutine x_content_type_options: not called CC=1 SCAR=6.9
Pod documented
1579  
1580 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-DNS-Prefetch-Control>
1581 0 ▶sub x_dns_prefetch_control { return( shift->_set_get_one( 'X-DNS-Prefetch-Control', @_ ) ); }
Subroutine x_dns_prefetch_control: not called CC=1 SCAR=6.9
Pod documented
1582  
1583 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For>
1584 0 ▶sub x_forwarded_for { return( shift->_set_get_one( 'X-Forwarded-For', @_ ) ); }
Subroutine x_forwarded_for: not called CC=1 SCAR=6.9
Pod documented
1585  
1586 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host>
1587 0 ▶sub x_forwarded_host { return( shift->_set_get_one( 'X-Forwarded-Host', @_ ) ); }
Subroutine x_forwarded_host: not called CC=1 SCAR=6.9
Pod documented
1588  
1589 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto>
1590 0 ▶sub x_forwarded_proto { return( shift->_set_get_one( 'X-Forwarded-Proto', @_ ) ); }
Subroutine x_forwarded_proto: not called CC=1 SCAR=6.9
Pod documented
1591  
1592 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options>
1593 0 ▶sub x_frame_options { return( shift->_set_get_one( 'X-Frame-Options', @_ ) ); }
Subroutine x_frame_options: not called CC=1 SCAR=6.9
Pod documented
1594  
1595 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection>
1596 0 ▶sub x_xss_protection { return( shift->_set_get_one( 'X-XSS-Protection', @_ ) ); }
Subroutine x_xss_protection: not called CC=1 SCAR=6.9
Pod documented
1597  
1598 sub _basic_auth
1599 9 ▶{
Subroutine _basic_auth: called CC=12 SCAR=25.8
1600 9 my $self = shift( @_ );
1601 9 my $field = shift( @_ );
1602 9 ▶ return( $self->error( "No field provided to get its basic authentication value." ) ) if( !defined( $field ) || !length( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field and length $field 0 9 9
Condition33%1/3
defined $field and length $field
!ll&&!rl&&r
009
MC/DC0%0/2
defined $field and length $field
defined $field length $field
Truth table33%1/3
A and B
A= defined $fieldB= length $field
ABresult
0X0
100
111
1603 9 ▶ $self->_load_class( 'Crypt::Misc' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Crypt::Misc") or return $self->pass_error 9 0 9
1604 9 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 4 5 9
1605 {
1606 4 my( $user, $pwd ) = @_;
1607 4 ▶ return( $self->error( "Basic authorisation user name cannot contain ':'." ) ) if( index( $user, ':' ) != -1 );
Branch: 1 branch
BranchTrueFalseTotal
if (index($user, ":") != -1) 1 3 4
1608 3 ▶ $pwd = '' if( !defined( $pwd ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pwd 1 2 3
1609 3 $self->header( $field => sprintf( 'Basic %s', Crypt::Misc::encode_b64( "${user}:${pwd}" ) ) );
1610 3 return( "${user}:${pwd}" );
1611 }
1612 else
1613 {
1614 5 my $v = $self->header( $field );
1615 5 ▶ return( $v ) if( !defined( $v ) && !want( 'OBJECT' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v or want("OBJECT") 1 4 5
Condition66%2/3
defined $v or want("OBJECT")
l!l&&r!l&&!r
401
MC/DC50%1/2
defined $v or want("OBJECT")
defined $v want("OBJECT")
Truth table66%2/3
A or B
A= defined $vB= want("OBJECT")
ABresult
1X1
011
000
1616 4 ▶ if( defined( $v ) && $v =~ /^[[:blank:]\h]*Basic[[:blank:]\h]+(.+?)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v and $v =~ /^[[:blank:]\h]*Basic[[:blank:]\h]+(.+?)$/) 4 0 4
Condition33%1/3
defined $v and $v =~ /^[[:blank:]\h]*Basic[[:blank:]\h]+(.+?)$/
!ll&&!rl&&r
004
MC/DC0%0/2
defined $v and $v =~ /^[[:blank:]\h]*Basic[[:blank:]\h]+(.+?)$/
defined $v $v =~ /^[[:blank:]\h]*Basic[[:blank:]\h]+(.+?)$/
Truth table33%1/3
A and B
A= defined $vB= $v =~ /^[[:blank:]\h]*Basic[[:blank:]\h]+(.+?)$/
ABresult
0X0
100
111
1617 {
1618 4 $v = Crypt::Misc::decode_b64( $1 );
1619 }
1620 4 ▶ return( wantarray() ? split( /:/, "$v" ) : $self->new_scalar( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 1 4
1621 }
1622 }
1623  
1624 sub _date_header
1625 18 ▶{
Subroutine _date_header: called CC=29 SCAR=42.8
1626 18 my $self = shift( @_ );
1627 18 my $f = shift( @_ );
1628 18 ▶ return( $self->error( "No field was provided to get or set its value." ) ) if( !defined( $f ) || !length( "$f" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f and length "$f" 0 18 18
Condition33%1/3
defined $f and length "$f"
!ll&&!rl&&r
0018
MC/DC0%0/2
defined $f and length "$f"
defined $f length "$f"
Truth table33%1/3
A and B
A= defined $fB= length "$f"
ABresult
0X0
100
111
1629 18 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 5 13 18
1630 {
1631 5 my $this = shift( @_ );
1632 5 ▶ return( $self->remove_header( "$f" ) ) if( !defined( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this 0 5 5
1633 5 my $opts = $self->_get_args_as_hash( @_ );
1634 5 ▶ $opts->{time_zone} = 'GMT' if( !defined( $opts->{time_zone} ) || !length( $opts->{time_zone} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"time_zone"} and length $opts->{"time_zone"} 5 0 5
Condition33%1/3
defined $opts->{"time_zone"} and length $opts->{"time_zone"}
!ll&&!rl&&r
500
MC/DC0%0/2
defined $opts->{"time_zone"} and length $opts->{"time_zone"}
defined $opts->{"time_zone"} length $opts->{"time_zone"}
Truth table33%1/3
A and B
A= defined $opts->{"time_zone"}B= length $opts->{"time_zone"}
ABresult
0X0
100
111
1635 5 require Module::Generic::DateTime;
1636 5 require DateTime::Format::Lite;
1637 5 ▶ if( ref( $this ) && Scalar::Util::blessed( $this ) && $this->isa( 'Module::Generic::DateTime' ) )
Branch: 3 branches
BranchTrueFalseTotal
if (ref $this and builtin::blessed($this) and $this->isa('Module::Generic::DateTime')) { } 0 5 5
elsif (ref $this and builtin::blessed($this) and $this->isa('DateTime::Lite') || $this->isa('DateTime')) { } 0 5 5
elsif ($this =~ /^\d+$/) { } 5 0 5
Condition33%2/6
ref $this and builtin::blessed($this) and $this->isa("Module::Generic::DateTime")
!ll&&!rl&&r
500
ref $this and builtin::blessed($this)
!ll&&!rl&&r
500
MC/DC0%0/3
ref $this and builtin::blessed($this) and $this->isa("Module::Generic::DateTime")
ref $this builtin::blessed($this) $this->isa("Module::Generic::DateTime")
Truth table25%1/4
A and B and C
A= ref $thisB= builtin::blessed($this)C= $this->isa("Module::Generic::DateTime")
ABCresult
0XX0
10X0
1100
1111
1638 {
1639 # Ok, pass through
1640 }
1641 ▶ elsif( ref( $this ) && Scalar::Util::blessed( $this ) && ( $this->isa( 'DateTime::Lite' ) || $this->isa( 'DateTime' ) ) )
Condition22%2/9
ref $this and builtin::blessed($this) and $this->isa("DateTime::Lite") || $this->isa("DateTime")
!ll&&!rl&&r
500
ref $this and builtin::blessed($this)
!ll&&!rl&&r
500
$this->isa("DateTime::Lite") or $this->isa("DateTime")
l!l&&r!l&&!r
000
MC/DC0%0/4
ref $this and builtin::blessed($this) and $this->isa("DateTime::Lite") || $this->isa("DateTime")
ref $this builtin::blessed($this) $this->isa("DateTime::Lite") $this->isa("DateTime")
Truth table20%1/5
A and B and C or D
A= ref $thisB= builtin::blessed($this)C= $this->isa("DateTime::Lite")D= $this->isa("DateTime")
ABCDresult
0XXX0
10XX0
11000
111X1
11011
1642 {
1643 0 $this = Module::Generic::DateTime->new( $this );
1644 }
1645 elsif( $this =~ /^\d+$/ )
1646 {
1647 # try-catch
1648 5 local $@;
1649 eval
1650 5 {
1651 5 $this = Module::Generic::DateTime->from_epoch( epoch => "$this", time_zone => $opts->{time_zone} );
1652 };
1653 5 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 5 5
1654 {
1655 0 return( $self->error( "An error occurred while trying to get the DateTime object for epoch value '$this': $@" ) );
1656 }
1657 }
1658 else
1659 {
1660 0 return( $self->error( "I was expecting an integer representing a unix time or a DateTime object, but instead got '$this'." ) );
1661 }
1662  
1663 # try-catch
1664 5 local $@;
1665 eval
1666 5 {
1667 5 $this->set_time_zone( 'GMT' );
1668 };
1669 5 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 5 5
1670 {
1671 0 return( $self->error( "An error occurred while trying to set the timezone GMT on the datetime object '$this': $@" ) );
1672 }
1673 5 ▶ my $fmt = DateTime::Format::Lite->new(
Condition50%1/2
'DateTime::Format::Lite'->new('pattern', '%a, %d %b %Y %H:%M:%S GMT', 'locale', 'en_GB', 'time_zone', 'GMT') || (return $self->error("An error occurred while trying to format the datetime '${this}': ", 'DateTime::Format::Lite'->error))
l!l
50
MC/DC0%0/1
'DateTime::Format::Lite'->new('pattern', '%a, %d %b %Y %H:%M:%S GMT', 'locale', 'en_GB', 'time_zone', 'GMT') || (return $self->error("An error occurred while trying to format the datetime '${this}': ", 'DateTime::Format::Lite'->error))
'DateTime::Format::Lite'->new('pattern', '%a, %d %b %Y %H:%M:%S GMT', 'locale', 'en_GB', 'time_zone', 'GMT')
Truth table50%1/2
A
A= 'DateTime::Format::Lite'->new('pattern', '%a, %d %b %Y %H:%M:%S GMT', 'locale', 'en_GB', 'time_zone', 'GMT')
Aresult
11
00
1674 pattern => '%a, %d %b %Y %H:%M:%S GMT',
1675 locale => 'en_GB',
1676 time_zone => 'GMT',
1677 ) || return( $self->error( "An error occurred while trying to format the datetime '$this': ", DateTime::Format::Lite->error ) );
1678 5 $this->set_formatter( $fmt );
1679 5 $self->header( $f => $this );
1680 5 return( $this );
1681 }
1682 else
1683 {
1684 13 my $v = $self->header( "$f" );
1685 13 ▶ return( $v ) if( !defined( $v ) || !length( "${v}" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v and length "$v" 5 8 13
Condition66%2/3
defined $v and length "$v"
!ll&&!rl&&r
508
MC/DC50%1/2
defined $v and length "$v"
defined $v length "$v"
Truth table66%2/3
A and B
A= defined $vB= length "$v"
ABresult
0X0
100
111
1686 8 ▶ if( !length( "$v" ) || ( ref( $v ) && !overload::Method( $v, '""' ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not length "$v" or ref $v and not overload::Method($v, "\"\"")) 0 8 8
Condition50%3/6
not length "$v" or ref $v and not overload::Method($v, "\"\"")
l!l&&r!l&&!r
008
ref $v and not overload::Method($v, "\"\"")
!ll&&!rl&&r
170
MC/DC0%0/3
not length "$v" or ref $v and not overload::Method($v, "\"\"")
not length "$v" ref $v not overload::Method($v, "\"\"")
Truth table50%2/4
not(A) or B and not(C)
A= not length "$v"B= ref $vC= not overload::Method($v, "\"\"")
ABCresult
1XX1
0111
00X0
0100
1687 {
1688 0 ▶ warn( "I do not know what to do with this supposedly datetime header $f with value '$v'\n" ) if( length( "$v" ) );
Branch: 1 branch
BranchTrueFalseTotal
if length "$v" 0 0 0
1689 0 return( '' );
1690 }
1691  
1692 # try-catch
1693 8 local $@;
1694 eval
1695 8 {
1696 8 ▶ unless( Scalar::Util::blessed( $v ) && $v->isa( 'Module::Generic::DateTime' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($v) and $v->isa("Module::Generic::DateTime")) 1 7 8
Condition66%2/3
builtin::blessed($v) and $v->isa("Module::Generic::DateTime")
!ll&&!rl&&r
107
MC/DC50%1/2
builtin::blessed($v) and $v->isa("Module::Generic::DateTime")
builtin::blessed($v) $v->isa("Module::Generic::DateTime")
Truth table66%2/3
A and B
A= builtin::blessed($v)B= $v->isa("Module::Generic::DateTime")
ABresult
0X0
100
111
1697 {
1698 # IE6 appends "; length = NNNN" on If-Modified-Since (can we handle it)
1699 # e.g.: Sat, 29 Oct 1994 19:43:31 GMT; length=34343
1700 1 ▶ if( index( $v, ';' ) != -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($v, ";") != -1) 1 0 1
1701 {
1702 1 $v = [split( /[[:blank:]\h]*;[[:blank:]\h]*/, "${v}", 2 )]->[0];
1703 }
1704 1 require Module::Generic;
1705 1 my $dt = Module::Generic->_parse_timestamp( "$v" );
1706 1 ▶ return( $self->pass_error( Module::Generic->error ) ) if( !defined( $dt ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dt 0 1 1
1707 1 my $fmt = DateTime::Format::Lite->new( pattern => '%s' );
1708 1 $dt->set_formatter( $fmt );
1709 1 $v = Module::Generic::DateTime->new( $dt );
1710 }
1711 };
1712 8 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 8 8
1713 {
1714 0 return( $self->error( "An error occurred while parsing datetime '$v': $@" ) );
1715 }
1716 8 return( $v );
1717 }
1718 }
1719  
1720 sub _get_args_as_array
1721 85 ▶{
Subroutine _get_args_as_array: called CC=6 SCAR=33.4
1722 85 my $self = shift( @_ );
1723 85 ▶ return( [] ) if( !scalar( @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ 85 0 85
1724 0 my $ref = [];
1725 0 ▶ if( scalar( @_ ) == 1 &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1 and defined $_[0] and ref $_[0] and builtin::reftype($_[0]) eq 'ARRAY') { } 0 0 0
Condition0%0/9
scalar @_ == 1 and defined $_[0] and ref $_[0] and builtin::reftype($_[0]) eq "ARRAY"
!ll&&!rl&&r
000
scalar @_ == 1 and defined $_[0] and ref $_[0]
!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] and builtin::reftype($_[0]) eq "ARRAY"
scalar @_ == 1 defined $_[0] ref $_[0] builtin::reftype($_[0]) eq "ARRAY"
Truth table0%0/5
A and B and C and D
A= scalar @_ == 1B= defined $_[0]C= ref $_[0]D= builtin::reftype($_[0]) eq "ARRAY"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1726 defined( $_[0] ) &&
1727 # Scalar::Util::reftype returns undef if the value is not a reference, which
1728 # causes a warning to pop up since we then compare an undefined value.
1729 ref( $_[0] ) &&
1730 Scalar::Util::reftype( $_[0] ) eq 'ARRAY' )
1731 {
1732 0 $ref = shift( @_ );
1733 }
1734 else
1735 {
1736 0 $ref = [ @_ ];
1737 }
1738 0 return( $ref );
1739 }
1740  
1741 sub _get_args_as_hash
1742 27 ▶{
Subroutine _get_args_as_hash: called CC=10 SCAR=29.7
1743 27 my $self = shift( @_ );
1744 27 ▶ return( {} ) if( !scalar( @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ 5 22 27
1745 12 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1746 22 my $ref = {};
1747 22 my $order = $self->new_array;
1748 22 ▶ my $need_list = want( 'LIST' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
want('LIST') ? : 0 22 22
1749 22 ▶ if( scalar( @_ ) == 1 && Scalar::Util::reftype( $_[0] ) eq 'HASH' )
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_ == 1 and builtin::reftype($_[0]) eq 'HASH') { } 22 0 22
elsif (not scalar(@_) % 2) { } 0 0 0
Condition33%1/3
scalar @_ == 1 and builtin::reftype($_[0]) eq "HASH"
!ll&&!rl&&r
0022
MC/DC0%0/2
scalar @_ == 1 and builtin::reftype($_[0]) eq "HASH"
scalar @_ == 1 builtin::reftype($_[0]) eq "HASH"
Truth table33%1/3
A and B
A= scalar @_ == 1B= builtin::reftype($_[0]) eq "HASH"
ABresult
0X0
100
111
1750 {
1751 22 $ref = shift( @_ );
1752 22 ▶ $order = $self->new_array( [sort( keys( %$ref ) )] ) if( $need_list );
Branch: 1 branch
BranchTrueFalseTotal
if $need_list 0 22 22
1753 }
1754 elsif( !( scalar( @_ ) % 2 ) )
1755 {
1756 0 $ref = { @_ };
1757 0 ▶ if( $need_list )
Branch: 1 branch
BranchTrueFalseTotal
if ($need_list) 0 0 0
1758 {
1759 0 ▶ for( my $i = 0; $i < scalar( @_ ); $i += 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @_) 0 0 0
1760 {
1761 0 $order->push( $_[$i] );
1762 }
1763 }
1764 }
1765 22 ▶ return( $need_list ? ( $ref, $order ) : $ref );
Branch: 1 branch
BranchTrueFalseTotal
$need_list ? : 0 22 22
1766 }
1767  
1768 sub _header_get
1769 0 ▶{
Subroutine _header_get: not called CC=5 SCAR=34.0
1770 0 my $self = shift( @_ );
1771 0 my $f = shift( @_ );
1772 0 ▶ return( $self->error( "No header field was provided." ) ) if( !defined( $f ) || !length( "$f" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f and length "$f" 0 0 0
Condition0%0/3
defined $f and length "$f"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $f and length "$f"
defined $f length "$f"
Truth table0%0/3
A and B
A= defined $fB= length "$f"
ABresult
0X0
100
111
1773 0 my @values = ();
1774 0 ▶ if( wantarray() )
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
1775 {
1776 0 @values = $self->header( "$f" );
1777 0 ▶ return if( !@values );
Branch: 1 branch
BranchTrueFalseTotal
unless @values 0 0 0
1778 0 return( @values );
1779 }
1780 else
1781 {
1782 0 return( $self->header( "$f" ) );
1783 }
1784 }
1785  
1786 sub _header_set
1787 0 ▶{
Subroutine _header_set: not called CC=7 SCAR=40.3
1788 0 my $self = shift( @_ );
1789 0 ▶ return( $self->SUPER::error( "Uneven number of parameters provided. I was expecting field-value pairs." ) ) if( @_ % 2 );
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 0 0
1790 0 my @args = ();
1791 0 ▶ for( my $i = 0; $i < scalar( @_ ); $i += 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @_) 0 0 0
1792 {
1793 0 my( $f, $v ) = @_[$i..$i+1];
1794 0 ▶ next if( !defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
1795 0 ▶ if( $self->_is_array( $v ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_array($v)) { } 0 0 0
1796 {
1797 0 ▶ my $ref = $self->_is_object( $v ) ? [@$v] : $v;
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_object($v) ? : 0 0 0
1798 0 push( @args, "$f" => $ref );
1799 }
1800 else
1801 {
1802 0 push( @args, "$f" => $v );
1803 }
1804 }
1805  
1806 # try-catch
1807 0 local $@;
1808 eval
1809 0 {
1810 0 $self->header( @args );
1811 };
1812 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1813 {
1814 0 return( $self->error( "Error trying to set headers with values: $@" ) );
1815 }
1816 0 return( $self );
1817 }
1818  
1819 sub _is_a
1820 22 ▶{
Subroutine _is_a: called CC=4 SCAR=14.5
1821 22 my $self = shift( @_ );
1822 22 my $obj = shift( @_ );
1823 22 my $pkg = shift( @_ );
1824 12 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
1825 22 ▶ return if( !$obj || !$pkg );
Branch: 1 branch
BranchTrueFalseTotal
unless $obj and $pkg 0 22 22
Condition33%1/3
$obj and $pkg
!ll&&!rl&&r
0022
MC/DC0%0/2
$obj and $pkg
$obj $pkg
Truth table33%1/3
A and B
A= $objB= $pkg
ABresult
0X0
100
111
1826 22 ▶ return if( !Scalar::Util::blessed( $obj ) );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($obj) 0 22 22
1827 22 return( $obj->isa( $pkg ) );
1828 }
1829  
1830 sub _is_class_loaded
1831 98 ▶{
Subroutine _is_class_loaded: called CC=12 SCAR=30.9
1832 98 my $self = shift( @_ );
1833 98 my $class = shift( @_ );
1834 98 ▶ my $key = HAS_THREADS ? join( ';', $class, threads->tid() ) : $class;
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 0 98 98
1835 98 ▶ my $repo = Module::Generic::Global->new( 'loaded_classes' => ( ref( $self ) || $self ), key => $key );
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
9800
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
1836 98 ▶ if( $MOD_PERL )
Branch: 2 branches
BranchTrueFalseTotal
if ($HTTP::Promise::Headers::MOD_PERL) { } 0 98 98
elsif ($repo->exists) { } 65 33 98
1837 {
1838 # https://perl.apache.org/docs/2.0/api/Apache2/Module.html#C_loaded_
1839 0 my $rv = Apache2::Module::loaded( $class );
1840 0 ▶ return(1) if( $rv );
Branch: 1 branch
BranchTrueFalseTotal
if $rv 0 0 0
1841 }
1842 # elsif( HAS_THREADS && $repo->exists )
1843 elsif( $repo->exists )
1844 {
1845 65 return(1);
1846 }
1847 else
1848 {
1849 33 ( my $pm = $class ) =~ s{::}{/}gs;
1850 33 $pm .= '.pm';
1851 33 ▶ if( CORE::exists( $INC{ $pm } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $INC{$pm}) 21 12 33
1852 {
1853 21 $repo->set(1);
1854 21 return(1);
1855 }
1856 }
1857 12 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1858 12 my $ns = \%{ $class . '::' };
1859 12 ▶ if( exists( $ns->{ISA} ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ns->{"ISA"} or exists $ns->{"BEGIN"} or exists $ns->{"VERSION"} and builtin::reftype(\$ns->{"VERSION"}) eq "GLOB" and defined ${*{\$ns->{"VERSION"};}{"SCALAR"};}) 0 12 12
Condition33%4/12
exists $ns->{"ISA"} or exists $ns->{"BEGIN"} or exists $ns->{"VERSION"} and builtin::reftype(\$ns->{"VERSION"}) eq "GLOB" and defined ${*{\$ns->{"VERSION"};}{"SCALAR"};}
l!l&&r!l&&!r
0012
exists $ns->{"ISA"} or exists $ns->{"BEGIN"}
l!l&&r!l&&!r
0012
exists $ns->{"VERSION"} and builtin::reftype(\$ns->{"VERSION"}) eq "GLOB" and defined ${*{\$ns->{"VERSION"};}{"SCALAR"};}
!ll&&!rl&&r
1200
exists $ns->{"VERSION"} and builtin::reftype(\$ns->{"VERSION"}) eq "GLOB"
!ll&&!rl&&r
1200
MC/DC0%0/5
exists $ns->{"ISA"} or exists $ns->{"BEGIN"} or exists $ns->{"VERSION"} and builtin::reftype(\$ns->{"VERSION"}) eq "GLOB" and defined ${*{\$ns->{"VERSION"};}{"SCALAR"};}
exists $ns->{"ISA"} exists $ns->{"BEGIN"} exists $ns->{"VERSION"} builtin::reftype(\$ns->{"VERSION"}) eq "GLOB" defined ${*{\$ns->{"VERSION"};}{"SCALAR"};}
Truth table16%1/6
A or B or C and D and E
A= exists $ns->{"ISA"}B= exists $ns->{"BEGIN"}C= exists $ns->{"VERSION"}D= builtin::reftype(\$ns->{"VERSION"}) eq "GLOB"E= defined ${*{\$ns->{"VERSION"};}{"SCALAR"};}
ABCDEresult
1XXXX1
01XXX1
001111
000XX0
0010X0
001100
1860 exists( $ns->{BEGIN} ) ||
1861 (
1862 exists( $ns->{VERSION} ) &&
1863 Scalar::Util::reftype( \$ns->{VERSION} ) eq 'GLOB' &&
1864 0 defined( ${*{\$ns->{VERSION}}{SCALAR}} )
1865 ) )
1866 {
1867 0 $repo->set(1);
1868 0 return(1);
1869 }
1870 12 return(0);
1871 }
1872  
1873 sub _is_glob
1874 22 ▶{
Subroutine _is_glob: called CC=4 SCAR=14.6
1875 22 ▶ return(0) if( scalar( @_ < 2 ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar(@_ < 2) 0 22 22
1876 22 ▶ return(0) if( !defined( $_[1] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] 0 22 22
1877 22 my $type = Scalar::Util::reftype( $_[1] );
1878 22 ▶ return(0) if( !defined( $type ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 22 22
1879 22 return( $type eq 'GLOB' );
1880 }
1881  
1882 sub _load_class
1883 85 ▶{
Subroutine _load_class: called CC=25 SCAR=44.8
1884 85 my $self = shift( @_ );
1885 85 ▶ my $class = shift( @_ ) || return( $self->error( "No package name was provided to load." ) );
Condition50%1/2
shift @_ || (return $self->error('No package name was provided to load.'))
l!l
850
MC/DC0%0/1
shift @_ || (return $self->error('No package name was provided to load.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
1886  
1887 # Rigorous validation
1888 85 ▶ return( $self->error( "Class name is empty." ) ) unless( length( $class ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $class 0 85 85
1889  
1890 85 my $opts = {};
1891 85 ▶ $opts = pop( @_ ) if ( ref( $_[-1] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 0 85 85
1892  
1893 # Validate options
1894 85 my %valid_opts = map { $_ => 1 } qw( caller version no_import );
1895 85 foreach my $key ( keys( %$opts ) )
1896 {
1897 0 ▶ return( $self->error( "Invalid option: $key" ) ) unless ( exists( $valid_opts{ $key } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $valid_opts{$key} 0 0 0
1898 }
1899 85 ▶ if( exists( $opts->{version} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"version"}) 0 85 85
1900 {
1901 0 ▶ return( $self->error( "Version must be defined and non-empty." ) ) unless( defined( $opts->{version} ) && length( $opts->{version} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"version"} and length $opts->{"version"} 0 0 0
Condition0%0/3
defined $opts->{"version"} and length $opts->{"version"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opts->{"version"} and length $opts->{"version"}
defined $opts->{"version"} length $opts->{"version"}
Truth table0%0/3
A and B
A= defined $opts->{"version"}B= length $opts->{"version"}
ABresult
0X0
100
111
1902 }
1903  
1904 85 my $args = $self->_get_args_as_array( @_ );
1905  
1906 # Get the caller's package so we load the module in context
1907 85 ▶ my $caller_class = $opts->{caller} || CORE::caller;
Condition33%1/3
$opts->{'caller'} || caller
l!l&&r!l&&!r
0850
MC/DC0%0/2
$opts->{'caller'} || caller
$opts->{'caller'} caller
Truth table33%1/3
A || B
A= $opts->{'caller'}B= caller
ABresult
1X1
011
000
1908  
1909 # Return if already loaded (threads aware)
1910 85 my $is_loaded = $self->_is_class_loaded( $class );
1911 85 ▶ if( $is_loaded )
Branch: 1 branch
BranchTrueFalseTotal
if ($is_loaded) 73 12 85
1912 {
1913 73 ▶ if( scalar( @$args ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args) 0 73 73
1914 {
1915 0 ▶ my $pl = "package ${caller_class}; $class->import(" . ( scalar( @$args ) ? "'" . join( "', '", @$args ) . "'" : '' ) . ");";
Branch: 1 branch
BranchTrueFalseTotal
scalar @$args ? : 0 0 0
1916 0 eval( $pl );
1917 0 ▶ return( $self->error( "Error importing class $class into caller's namespace ${caller_class}: $@" ) ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1918 }
1919 73 return( $class );
1920 }
1921 # Use a shared variable for locking in threaded environments
1922 # What we retrieved from _is_class_loaded is not a threaded shared value, so we have to do this instead:
1923 12 ▶ my $key = HAS_THREADS ? join( ';', $class, threads->tid() ) : $class;
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 0 12 12
1924 12 ▶ my $repo = Module::Generic::Global->new( 'loaded_classes' => ( ref( $self ) || $self ), key => $key );
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
1200
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
1925  
1926 # Load the module with thread safety
1927 {
1928 12 ▶ my $has_version = ( CORE::exists( $opts->{version} ) && CORE::length( $opts->{version} // '' ) ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'version'} && length($opts->{'version'} // '') ? : 0 12 12
Condition20%1/5
exists $opts->{"version"} and length($opts->{"version"} // "")
!ll&&!rl&&r
1200
$opts->{"version"} // ""
l!l
00
MC/DC0%0/2
exists $opts->{"version"} and length($opts->{"version"} // "")
exists $opts->{"version"} $opts->{"version"}
Truth table33%1/3
A and B
A= exists $opts->{"version"}B= $opts->{"version"}
ABresult
0X0
100
111
1929 12 ▶ local $SIG{__DIE__} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=0.0
1930 12 local $@;
1931 12 my $pl = "package ${caller_class}; require $class;";
1932 12 eval( $pl );
1933 12 ▶ return( $self->error( "Unable to load package ${class}: $@\nCode executed was:\n${pl}" ) ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 12 12
1934 12 ▶ if( $has_version )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_version) 0 12 12
1935 {
1936 0 eval{ $class->VERSION( $opts->{version} ) };
1937 0 ▶ return( $self->error( "Insufficient version ", $class->VERSION(), ", for class $class. $opts->{version} minimum is required." ) ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1938 }
1939  
1940 12 ▶ $pl = "package ${caller_class}; $class->import(" . ( scalar( @$args ) ? "'" . join( "', '", @$args ) . "'" : '' ) . ");";
Branch: 1 branch
BranchTrueFalseTotal
scalar @$args ? : 0 12 12
1941 12 eval( $pl );
1942 12 ▶ return( $self->error( "Error importing class $class into caller's namespace ${caller_class}: $@" ) ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 12 12
1943 12 $repo->set(1);
1944 }
1945  
1946 12 ▶ return( $self->_is_class_loaded( $class ) ? $class : '' );
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_class_loaded($class) ? : 12 0 12
1947 }
1948  
1949 sub _set_get
1950 40 ▶{
Subroutine _set_get: called CC=2 SCAR=7.0
1951 40 my $self = shift( @_ );
1952 40 my $prop = shift( @_ );
1953 40 ▶ $self->{ $prop } = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 40 40
1954 40 return( $self->{ $prop } );
1955 }
1956  
1957 # If there can be multiple instance of the given header
1958 sub _set_get_multi
1959 3 ▶{
Subroutine _set_get_multi: called CC=9 SCAR=23.4
1960 3 my $self = shift( @_ );
1961 3 my $f = shift( @_ );
1962 3 ▶ return( $self->error( "No field was provided to get or set its value." ) ) if( !defined( $f ) || !length( "$f" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f and length "$f" 0 3 3
Condition33%1/3
defined $f and length "$f"
!ll&&!rl&&r
003
MC/DC0%0/2
defined $f and length "$f"
defined $f length "$f"
Truth table33%1/3
A and B
A= defined $fB= length "$f"
ABresult
0X0
100
111
1963 3 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 1 2 3
1964 {
1965 1 my $v = shift( @_ );
1966 1 ▶ return( $self->remove_header( "$f" ) ) if( !defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 1 1
1967 # Too dangerous and unnecessary. The value type the user provides us defines how it will be set in the HTTP headers
1968 # An array reference means there will be possibly multiple instance of the header
1969 # A string, means there will be only one instance.
1970 # my $ref = Scalar::Util::reftype( $v ) eq 'ARRAY' ? $v : [split( /\,[[:blank:]\h]*/, $v)];
1971 # $self->header( "$f" => $ref );
1972 1 $self->header( "$f" => $v );
1973 1 return( $v );
1974 }
1975 else
1976 {
1977 2 my @vals = $self->header( "$f" );
1978 2 my $ref;
1979 2 ▶ if( @vals > 1 )
Branch: 2 branches
BranchTrueFalseTotal
if (@vals > 1) { } 0 2 2
elsif (not defined $vals[0]) { } 1 1 2
1980 {
1981 0 $ref = \@vals;
1982 }
1983 elsif( !defined( $vals[0] ) )
1984 {
1985 1 ▶ if( want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (want('OBJECT')) { } 0 1 1
1986 {
1987 0 return( Module::Generic::Null->new );
1988 }
1989 else
1990 {
1991 1 return;
1992 }
1993 }
1994 else
1995 {
1996 1 $vals[0] =~ s/^[[:blank:]\h]+|[[:blank:]\h]+$//g;
1997 1 $ref = [split( /\,[[:blank:]\h]*/, $vals[0] )];
1998 }
1999 # Thi is not such a good idea after all. It is better to return a list in list
2000 # context or a scalar object otherwise
2001 # return( $self->new_array( $ref ) );
2002 1 ▶ return( wantarray() ? @$ref : $self->new_scalar( join( ', ', @$ref ) ) );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
2003 }
2004 }
2005  
2006 # If there can be only one instance of the given header
2007 sub _set_get_one
2008 144 ▶{
Subroutine _set_get_one: called CC=8 SCAR=21.4
2009 144 my $self = shift( @_ );
2010 144 my $f = shift( @_ );
2011 144 ▶ return( $self->error( "No field was provided to get or set its value." ) ) if( !defined( $f ) || !length( "$f" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f and length "$f" 0 144 144
Condition33%1/3
defined $f and length "$f"
!ll&&!rl&&r
00144
MC/DC0%0/2
defined $f and length "$f"
defined $f length "$f"
Truth table33%1/3
A and B
A= defined $fB= length "$f"
ABresult
0X0
100
111
2012 144 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 29 115 144
2013 {
2014 29 my $v = shift( @_ );
2015 29 ▶ return( $self->remove_header( "$f" ) ) if( !defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 29 29
2016 29 $self->header( "$f" => $v );
2017 29 return( $v );
2018 }
2019 else
2020 {
2021 115 my @vals = $self->header( "$f" );
2022 115 ▶ if( @vals > 1 )
Branch: 2 branches
BranchTrueFalseTotal
if (@vals > 1) { } 0 115 115
elsif (not defined $vals[0]) { } 52 63 115
2023 {
2024 # return( $self->new_array( \@vals ) );
2025 0 return( $self->new_scalar( join( ', ', @vals ) ) );
2026 }
2027 elsif( !defined( $vals[0] ) )
2028 {
2029 52 ▶ if( want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (want('OBJECT')) { } 8 44 52
2030 {
2031 8 return( Module::Generic::Null->new );
2032 }
2033 else
2034 {
2035 44 return;
2036 }
2037 }
2038 else
2039 {
2040 63 $vals[0] =~ s/^[[:blank:]\h]+|[[:blank:]\h]+$//g;
2041 63 return( $self->new_scalar( $vals[0] ) );
2042 }
2043 }
2044 }
2045  
2046 sub _set_get_one_number
2047 17 ▶{
Subroutine _set_get_one_number: called CC=11 SCAR=31.4
2048 17 my $self = shift( @_ );
2049 17 my $f = shift( @_ );
2050 17 ▶ return( $self->error( "No field was provided to get or set its value." ) ) if( !defined( $f ) || !length( "$f" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f and length "$f" 0 17 17
Condition33%1/3
defined $f and length "$f"
!ll&&!rl&&r
0017
MC/DC0%0/2
defined $f and length "$f"
defined $f length "$f"
Truth table33%1/3
A and B
A= defined $fB= length "$f"
ABresult
0X0
100
111
2051 17 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 17 17
2052 {
2053 0 my $v = shift( @_ );
2054 0 ▶ return( $self->remove_header( "$f" ) ) if( !defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
2055 0 $self->header( "$f" => $v );
2056 0 return( $v );
2057 }
2058 else
2059 {
2060 17 my $v = $self->header( "$f" );
2061 17 ▶ if( !defined( $v ) || !length( $v ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $v and length $v) 16 1 17
Condition66%2/3
defined $v and length $v
!ll&&!rl&&r
1601
MC/DC50%1/2
defined $v and length $v
defined $v length $v
Truth table66%2/3
A and B
A= defined $vB= length $v
ABresult
0X0
100
111
2062 {
2063 16 ▶ if( want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (want('OBJECT')) { } 0 16 16
2064 {
2065 0 require Module::Generic::Null;
2066 0 my $null = Module::Generic::Null->new( '', { debug => $self->debug });
2067 0 rreturn( $null );
2068 }
2069 else
2070 {
2071 16 return( $v );
2072 }
2073 }
2074 # Ignore overflow values
2075 # 16 digits corresponding to 2^53-1 or 9007199254740991
2076 1 ▶ if( $v =~ /^[[:blank:]\h]*(\d{1,16})[[:blank:]\h]*$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /^[[:blank:]\h]*(\d{1,16})[[:blank:]\h]*$/) { } 1 0 1
2077 {
2078 1 $v = $1;
2079 }
2080 else
2081 {
2082 0 return( '' );
2083 }
2084 1 ▶ return( $v ) if( ref( $v ) && !overload::Method( $v, '""' ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $v and not overload::Method($v, "\"\"") 0 1 1
Condition33%1/3
ref $v and not overload::Method($v, "\"\"")
!ll&&!rl&&r
100
MC/DC0%0/2
ref $v and not overload::Method($v, "\"\"")
ref $v not overload::Method($v, "\"\"")
Truth table33%1/3
A and not(B)
A= ref $vB= not overload::Method($v, "\"\"")
ABresult
0X0
100
111
2085 1 return( $self->new_number( "$v" ) );
2086 }
2087 }
2088  
2089 sub _set_get_one_uri
2090 8 ▶{
Subroutine _set_get_one_uri: called CC=6 SCAR=18.5
2091 8 my $self = shift( @_ );
2092 8 my $f = shift( @_ );
2093 8 ▶ return( $self->error( "No field was provided to get or set its value." ) ) if( !defined( $f ) || !length( "$f" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f and length "$f" 0 8 8
Condition33%1/3
defined $f and length "$f"
!ll&&!rl&&r
008
MC/DC0%0/2
defined $f and length "$f"
defined $f length "$f"
Truth table33%1/3
A and B
A= defined $fB= length "$f"
ABresult
0X0
100
111
2094 8 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 3 5 8
2095 {
2096 3 my $v = shift( @_ );
2097 3 ▶ return( $self->remove_header( "$f" ) ) if( !defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 3 3
2098 3 $self->header( "$f" => $v );
2099 3 return( $v );
2100 }
2101 else
2102 {
2103 5 my $v = $self->header( "$f" );
2104 5 my $uri;
2105 # try-catch
2106 5 local $@;
2107 eval
2108 5 {
2109 5 require URI;
2110 5 $uri = URI->new( $v );
2111 };
2112 5 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 5 5
2113 {
2114 0 return( $self->error( "Unable to create an URI object from the header value for \"$f\": $@" ) );
2115 }
2116 5 return( $uri );
2117 }
2118 }
2119  
2120 # $obj->_str_val( $some_object );
2121 # $obj->_str_val( undef );
2122 sub _str_val
2123 0 ▶{
Subroutine _str_val: not called CC=3 SCAR=18.1
2124 12 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
2125 0 ▶ return( '' ) unless( scalar( @_ ) > 1 && defined( $_[1] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ > 1 and defined $_[1] 0 0 0
Condition0%0/3
scalar @_ > 1 and defined $_[1]
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ > 1 and defined $_[1]
scalar @_ > 1 defined $_[1]
Truth table0%0/3
A and B
A= scalar @_ > 1B= defined $_[1]
ABresult
0X0
100
111
2126 0 return( "$_[1]" );
2127 }
2128  
2129 # NOTE: For CBOR and Sereal
2130 sub FREEZE
2131 10 ▶{
Subroutine FREEZE: called CC=5 SCAR=17.2
Pod undocumented
2132 10 my $self = CORE::shift( @_ );
2133 10 ▶ my $serialiser = CORE::shift( @_ ) // '';
Condition50%1/2
shift @_ // ""
l!l
100
MC/DC0%0/1
shift @_ // ""
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
2134 10 my $class = CORE::ref( $self );
2135 10 my $h = {};
2136 10 my $headers = [];
2137 10 my $order = [];
2138 $self->scan(sub
2139 20 ▶ {
Subroutine __ANON__: called CC=3 SCAR=15.0
2140 20 my( $f, $val ) = @_;
2141 20 ▶ if( CORE::exists( $h->{ $f } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $h->{$f}) { } 0 20 20
2142 {
2143 0 ▶ $h->{ $f } = [ $h->{ $f } ] unless( CORE::ref( $h->{ $f } ) eq 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $h->{$f} eq "ARRAY" 0 0 0
2144 0 CORE::push( @{$h->{ $f }}, $val );
2145 }
2146 else
2147 {
2148 20 $h->{ $f } = $val;
2149 20 CORE::push( @$order, $f );
2150 }
2151 10 });
2152 10 foreach my $f ( @$order )
2153 {
2154 20 CORE::push( @$headers, $f, $h->{ $f } );
2155 }
2156 10 my %hash = %$self;
2157 10 $hash{_headers_to_restore} = $headers;
2158 # Return an array reference rather than a list so this works with Sereal and CBOR
2159 10 ▶ CORE::return( [$class, \%hash] ) if( $serialiser eq 'Sereal' && Sereal::Encoder->VERSION <= version->parse( '4.023' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $serialiser eq "Sereal" and "Sereal::Encoder"->VERSION <= "version"->parse("4.023") 0 10 10
Condition66%2/3
$serialiser eq "Sereal" and "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
!ll&&!rl&&r
550
MC/DC0%0/2
$serialiser eq "Sereal" and "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
$serialiser eq "Sereal" "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
Truth table66%2/3
A and B
A= $serialiser eq "Sereal"B= "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
ABresult
0X0
100
111
2160 # But Storable want a list with the first element being the serialised element
2161 10 CORE::return( $class, \%hash );
2162 }
2163  
2164 5 ▶sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: called CC=1 SCAR=0.0
Pod undocumented
2165  
2166 # NOTE: Storable creates an instance of HTTP:::Promise::Headers. The only problem is that it does not work with XS module and that Storable discard whatever value is returned by STORABLE_thaw. See issue #19984 <https://github.com/Perl/perl5/issues/19984>
2167 # So instead, we use this hook to store some data into the object created by Storable, and we call STORABLE_thaw_post_processing() with it and take what it returns.
2168 sub STORABLE_thaw
2169 5 ▶{
Subroutine STORABLE_thaw: called CC=4 SCAR=16.6
Pod undocumented
2170 5 my( $self, undef, $class, $hash ) = @_;
2171 5 ▶ $class //= CORE::ref( $self ) || $self;
Condition16%1/6
$class //= ref $self || $self
l!l&&r!l&&!r
500
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/3
$class //= ref $self || $self
$class ref $self $self
Truth table0%0/4
A //= B || C
A= $classB= ref $selfC= $self
ABCresult
1XX1
01X1
0011
0000
2172 5 ▶ $hash //= {};
Condition50%1/2
$hash //= {}
l!l
50
MC/DC0%0/1
$hash //= {}
$hash
Truth table50%1/2
A
A= $hash
Aresult
11
00
2173 5 $hash->{_class} = $class;
2174 5 $self->{_deserialisation_params} = $hash;
2175 # Useles to do more in STORABLE_thaw, because Storable anyway ignores the value returned
2176 # so we just store our hash of parameters for STORABLE_thaw_post_processing to do its actual job
2177 5 CORE::return( $self );
2178 }
2179  
2180 sub STORABLE_thaw_post_processing
2181 4 ▶{
Subroutine STORABLE_thaw_post_processing: called CC=7 SCAR=22.7
Pod undocumented
2182 4 my $obj = CORE::shift( @_ );
2183 my $hash = ( CORE::exists( $obj->{_deserialisation_params} ) && CORE::ref( $obj->{_deserialisation_params} ) eq 'HASH' )
2184 ? CORE::delete( $obj->{_deserialisation_params} )
2185 4 ▶ : {};
Branch: 1 branch
BranchTrueFalseTotal
exists $obj->{'_deserialisation_params'} && ref $obj->{'_deserialisation_params'} eq 'HASH' ? : 4 0 4
Condition33%1/3
exists $obj->{"_deserialisation_params"} and ref $obj->{"_deserialisation_params"} eq "HASH"
!ll&&!rl&&r
004
MC/DC0%0/2
exists $obj->{"_deserialisation_params"} and ref $obj->{"_deserialisation_params"} eq "HASH"
exists $obj->{"_deserialisation_params"} ref $obj->{"_deserialisation_params"} eq "HASH"
Truth table33%1/3
A and B
A= exists $obj->{"_deserialisation_params"}B= ref $obj->{"_deserialisation_params"} eq "HASH"
ABresult
0X0
100
111
2186 4 ▶ my $class = CORE::delete( $hash->{_class} ) || CORE::ref( $obj ) || $obj;
Condition33%2/6
delete $hash->{'_class'} || ref $obj || $obj
l!l&&r!l&&!r
400
delete $hash->{"_class"} or ref $obj
l!l&&r!l&&!r
400
MC/DC0%0/3
delete $hash->{'_class'} || ref $obj || $obj
delete $hash->{"_class"} ref $obj $obj
Truth table25%1/4
A or B || C
A= delete $hash->{"_class"}B= ref $objC= $obj
ABCresult
1XX1
01X1
0011
0000
2187 my $headers = CORE::ref( $hash->{_headers_to_restore} ) eq 'ARRAY'
2188 ? CORE::delete( $hash->{_headers_to_restore} )
2189 4 ▶ : [];
Branch: 1 branch
BranchTrueFalseTotal
ref $hash->{'_headers_to_restore'} eq 'ARRAY' ? : 4 0 4
2190 4 my $new = $class->new( @$headers );
2191 4 foreach( CORE::keys( %$hash ) )
2192 {
2193 19 $new->{ $_ } = CORE::delete( $hash->{ $_ } );
2194 }
2195 4 CORE::return( $new );
2196 }
2197  
2198 # NOTE: CBOR will call the THAW method with the stored classname as first argument, the constant string CBOR as second argument, and all values returned by FREEZE as remaining arguments.
2199 # NOTE: Storable calls STORABLE_thaw with a blessed object it created followed with $cloning and any other arguments initially provided by STORABLE_freeze. Then, after receiving $self from STORABLE_thaw, we call THAW which return a useable object. The one generated by Storable triggers the exception: "hl is not an instance of HTTP::XSHeader"
2200 sub THAW
2201 5 ▶{
Subroutine THAW: called CC=12 SCAR=33.5
Pod undocumented
2202 # STORABLE_thaw would issue $cloning as the 2nd argument, while CBOR would issue
2203 # 'CBOR' as the second value.
2204 5 my( $self, undef, @args ) = @_;
2205 5 ▶ 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 5 5
Condition33%1/3
scalar @args == 1 and ref $args[0] eq "ARRAY"
!ll&&!rl&&r
500
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
2206 5 ▶ 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 ? : 5 0 5
Condition22%2/9
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
!ll&&!rl&&r
005
defined $ref and ref $ref eq "ARRAY"
!ll&&!rl&&r
005
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
2207 5 ▶ my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 5 0 5
2208 my $headers = ( CORE::exists( $hash->{_headers_to_restore} ) && CORE::ref( $hash->{_headers_to_restore} ) eq 'ARRAY' )
2209 ? CORE::delete( $hash->{_headers_to_restore} )
2210 5 ▶ : [];
Branch: 1 branch
BranchTrueFalseTotal
exists $hash->{'_headers_to_restore'} && ref $hash->{'_headers_to_restore'} eq 'ARRAY' ? : 5 0 5
Condition33%1/3
exists $hash->{"_headers_to_restore"} and ref $hash->{"_headers_to_restore"} eq "ARRAY"
!ll&&!rl&&r
005
MC/DC0%0/2
exists $hash->{"_headers_to_restore"} and ref $hash->{"_headers_to_restore"} eq "ARRAY"
exists $hash->{"_headers_to_restore"} ref $hash->{"_headers_to_restore"} eq "ARRAY"
Truth table33%1/3
A and B
A= exists $hash->{"_headers_to_restore"}B= ref $hash->{"_headers_to_restore"} eq "ARRAY"
ABresult
0X0
100
111
2211  
2212 5 my $new = $class->new( @$headers );
2213 5 foreach( CORE::keys( %$hash ) )
2214 {
2215 23 ▶ next if( CORE::scalar( CORE::grep( $_, @$headers ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar grep($_, @$headers) 23 0 23
2216 0 $new->{ $_ } = CORE::delete( $hash->{ $_ } );
2217 }
2218 5 CORE::return( $new );
2219 }
2220  
2221 sub TO_JSON
2222 0 ▶{
Subroutine TO_JSON: not called CC=1 SCAR=6.9
Pod undocumented
2223 0 my $self = shift( @_ );
2224 0 my $ref = [];
2225 $self->scan(sub
2226 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2227 0 my( $header, $val ) = @_;
2228 0 CORE::push( @$ref, [ $header, $val ] );
2229 0 });
2230 0 return( $ref );
2231 }
2232  
2233 12 1;
2234 # NOTE: POD
2235 __END__
« Promise/Stream.pm ↑ Summary Promise/Entity.pm »