Promise/Headers.pm

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