lib/HTTP/Promise/Headers.pm

filter: Statementstmt 41.5% 441 / 1062 Branchbran 24.0% 143 / 594 Conditioncond 15.1% 74 / 488 MC/DCmcdc 3.3% 9 / 273 Subroutinesub 39.2% 78 / 199 Podpod 89.4% 127 / 142 totaltotal 31.6% 872 / 2758 CC 475 SCAR 63.0
CC
475
Cov
31%
error
2626.6
message
2415.7
pass_error
1620.5
CRAP 546.2
« blib/lib/HTTP/Promise/Stream.pm ↑ Summary blib/lib/HTTP/Promise/Entity.pm »
1 ##----------------------------------------------------------------------------
2 ## Asynchronous HTTP Request and Promise - ~/lib/HTTP/Promise/Headers.pm
3 ## Version v0.3.2
4 ## Copyright(c) 2025 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2022/03/21
7 ## Modified 2025/10/25
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 {
17 13 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 13 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 13 ▶ warnings::register_categories( 'HTTP::Promise' );
Subroutine BEGIN: called CC=3 SCAR=11.3
20 13 ▶ use parent qw( HTTP::XSHeaders );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 13 ▶ use vars qw( $VERSION $EXCEPTION_CLASS $MOD_PERL $SUPPORTED $MOD_PATH );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 13 ▶ use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 13 ▶ use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 13 ▶ use HTTP::Promise::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 13 ▶ use HTTP::XSHeaders 0.400004;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 13 ▶ use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 13 ▶ use Module::Generic::Global qw( :const );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 13 ▶ use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 13 ▶ use URI::Escape::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
30 13 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 13 ▶ 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 13 13
Condition33%1/3
exists $ENV{"MOD_PERL"} and $HTTP::Promise::Headers::MOD_PERL = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]
!ll&&!rl&&r
1300
MC/DC0%0/2
exists $ENV{"MOD_PERL"} and $HTTP::Promise::Headers::MOD_PERL = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]
exists $ENV{"MOD_PERL"} $HTTP::Promise::Headers::MOD_PERL = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]
Truth table33%1/3
A and B
A= exists $ENV{"MOD_PERL"}B= $HTTP::Promise::Headers::MOD_PERL = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]
ABresult
0X0
100
111
32 &&
33 ( $MOD_PERL = $ENV{MOD_PERL} =~ /^mod_perl\/(\d+\.[\d\.]+)/ ) )
34 {
35 0 select( ( select( STDOUT ), $| = 1 )[ 0 ] );
36 0 require Apache2::Log;
37 # For _is_class_loaded method
38 0 require Apache2::Module;
39 0 require Apache2::ServerUtil;
40 0 require Apache2::RequestUtil;
41 0 require Apache2::ServerRec;
42 0 require ModPerl::Util;
43 0 require Apache2::Const;
44 0 Apache2::Const->import( compile => qw( :log OK ) );
45 }
46 13 ▶ use constant CRLF => "\015\012";
Subroutine BEGIN: called CC=1 SCAR=0.0
47 13 our $EXCEPTION_CLASS = 'HTTP::Promise::Exception';
48 13 our $SUPPORTED = {};
49 13 our $VERSION = 'v0.3.2';
50 };
51  
52 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 13 my $stderr = IO::File->new;
56 13 $stderr->fdopen( fileno( STDERR ), 'w' );
57 13 $stderr->binmode( ':utf8' );
58 13 $stderr->autoflush( 1 );
59 13 my $stderr_raw = IO::File->new;
60 13 $stderr_raw->fdopen( fileno( STDERR ), 'w' );
61 13 $stderr_raw->binmode( ':raw' );
62 13 $stderr_raw->autoflush( 1 );
63  
64 13 our $MOD_PATH = Cwd::abs_path( $INC{ ( __PACKAGE__ =~ s{::}{/}gr ) . '.pm' } );
65  
66 # for mod in `ls -1 ./lib/HTTP/Promise/Headers`; do printf "%-32s => 'HTTP::Promise::Headers::%s',\n" $(echo $(basename $mod ".pm")|tr "[:upper:]" "[:lower:]") $(basename $mod ".pm"); done
67 # or
68 # perl -MModule::Generic::File=file -lE 'my $d=file("./lib/HTTP/Promise/Headers"); my $files=$d->content; $files->for(sub{ my$f=file($_); printf("%-32s => ''HTTP::Promise::Headers::%s'',\n", $f->basename(".pm")->lc, $f->basename(".pm")) })'
69 13 our $SUPPORTED =
70 {
71 accept => 'HTTP::Promise::Headers::Accept',
72 acceptencoding => 'HTTP::Promise::Headers::AcceptEncoding',
73 acceptlanguage => 'HTTP::Promise::Headers::AcceptLanguage',
74 altsvc => 'HTTP::Promise::Headers::AltSvc',
75 cachecontrol => 'HTTP::Promise::Headers::CacheControl',
76 clearsitedata => 'HTTP::Promise::Headers::ClearSiteData',
77 contentdisposition => 'HTTP::Promise::Headers::ContentDisposition',
78 contentrange => 'HTTP::Promise::Headers::ContentRange',
79 contentsecuritypolicy => 'HTTP::Promise::Headers::ContentSecurityPolicy',
80 contentsecuritypolicyreportonly => 'HTTP::Promise::Headers::ContentSecurityPolicyReportOnly',
81 contenttype => 'HTTP::Promise::Headers::ContentType',
82 cookie => 'HTTP::Promise::Headers::Cookie',
83 expectct => 'HTTP::Promise::Headers::ExpectCT',
84 forwarded => 'HTTP::Promise::Headers::Forwarded',
85 generic => 'HTTP::Promise::Headers::Generic',
86 keepalive => 'HTTP::Promise::Headers::KeepAlive',
87 link => 'HTTP::Promise::Headers::Link',
88 range => 'HTTP::Promise::Headers::Range',
89 servertiming => 'HTTP::Promise::Headers::ServerTiming',
90 stricttransportsecurity => 'HTTP::Promise::Headers::StrictTransportSecurity',
91 te => 'HTTP::Promise::Headers::TE',
92 wantdigest => 'HTTP::Promise::Headers::WantDigest',
93 };
94  
95 sub new
96 {
97 135 ▶ my $this = shift( @_ );
Subroutine new: called CC=4 SCAR=13.9
Pod documented
98 135 my $opts = {};
99 135 ▶ $opts = pop( @_ ) if( ref( $_[-1] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 18 117 135
100 135 my $self;
101 # try-catch
102 135 local $@;
103 eval
104 135 {
105 135 $self = $this->SUPER::new( @_ );
106 };
107 135 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 135 135
108 {
109 0 return( $this->error( "Error instantiating an HTTP::Promise::Headers object: $@" ) );
110 }
111 135 $self->{default_type} = undef;
112 135 $self->{_init_strict_use_sub} = 1;
113 135 $self->{_exception_class} = $EXCEPTION_CLASS;
114 135 ▶ $self->debug( $opts->{debug} ) if( CORE::exists( $opts->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"debug"} 18 117 135
115 135 $self->{_ctype_cached} = '';
116 135 return( $self );
117 }
118  
119 # e.g. text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
120 sub accept
121 {
122 0 ▶ my $self = shift( @_ );
Subroutine accept: not called CC=2 SCAR=17.9
Pod documented
123 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
124 {
125 0 my $types = $self->_get_args_as_array( @_ );
126 0 $self->header( accept => $types );
127 0 CORE::delete( $self->{acceptables} );
128 }
129 0 return( $self->_set_get_one( 'Accept' ) );
130 }
131  
132 # Obsolete header that should not be used
133 0 ▶sub accept_charset { return( shift->_set_get_one( 'Accept-Charset', @_ ) ); }
Subroutine accept_charset: not called CC=1 SCAR=6.9
Pod documented
134  
135 # e.g. gzip, deflate, br
136 0 ▶sub accept_encoding { return( shift->_set_get_multi( 'Accept-Encoding', @_ ) ); }
Subroutine accept_encoding: not called CC=1 SCAR=6.9
Pod documented
137  
138 # e.g.: en-GB,fr-FR;q=0.8,fr;q=0.6,ja;q=0.4,en;q=0.2
139 0 ▶sub accept_language { return( shift->_set_get_multi( 'Accept-Language', @_ ) ); }
Subroutine accept_language: not called CC=1 SCAR=6.9
Pod documented
140  
141 # NOTE: Accept-Patch is a response header
142 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Patch>
143 0 ▶sub accept_patch { return( shift->_set_get_one( 'Accept-Patch', @_ ) ); }
Subroutine accept_patch: not called CC=1 SCAR=6.9
Pod documented
144  
145 # NOTE: Accept-Post is a response header
146 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Post>
147 0 ▶sub accept_post { return( shift->_set_get_multi( 'Accept-Post', @_ ) ); }
Subroutine accept_post: not called CC=1 SCAR=6.9
Pod documented
148  
149 # NOTE: Accept-Tanges is a response header
150 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Ranges>
151 0 ▶sub accept_ranges { return( shift->_set_get_multi( 'Accept-Ranges', @_ ) ); }
Subroutine accept_ranges: not called CC=1 SCAR=6.9
Pod documented
152  
153 sub acceptables
154 {
155 0 ▶ my $self = shift( @_ );
Subroutine acceptables: not called CC=4 SCAR=30.0
Pod documented
156 0 ▶ return( $self->{acceptables} ) if( $self->{acceptables} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"acceptables"} 0 0 0
157 0 my $accept_raw = $self->accept;
158 0 ▶ if( $accept_raw )
Branch: 1 branch
BranchTrueFalseTotal
if ($accept_raw) 0 0 0
159 {
160 0 ▶ my $f = $self->new_field( accept => $accept_raw ) ||
Condition0%0/2
$self->new_field('accept', $accept_raw) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_field('accept', $accept_raw) || (return $self->pass_error)
$self->new_field('accept', $accept_raw)
Truth table0%0/2
A
A= $self->new_field('accept', $accept_raw)
Aresult
11
00
161 return( $self->pass_error );
162 0 $self->{acceptables} = $f;
163 }
164 0 return( $self->{acceptables} );
165 }
166  
167 1 ▶sub add { return( shift->push_header( @_ ) ); }
Subroutine add: called CC=1 SCAR=0.0
Pod documented
168  
169 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Age>
170 0 ▶sub age { return( shift->_set_get_one( 'Age', @_ ) ); }
Subroutine age: not called CC=1 SCAR=6.9
Pod documented
171  
172 # NOTE: Allow is a response header
173 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Allow>
174 0 ▶sub allow { return( shift->_set_get_multi( 'Allow', @_ ) ); }
Subroutine allow: not called CC=1 SCAR=6.9
Pod documented
175  
176 # Response header: <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials>
177 0 ▶sub allow_credentials { return( shift->_set_get_one( 'Access-Control-Allow-Credentials', @_ ) ); }
Subroutine allow_credentials: not called CC=1 SCAR=6.9
Pod documented
178  
179 # Response header <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers>
180 0 ▶sub allow_headers { return( shift->_set_get_multi( 'Access-Control-Allow-Headers', @_ ) ); }
Subroutine allow_headers: not called CC=1 SCAR=6.9
Pod documented
181  
182 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods>
183 0 ▶sub allow_methods { return( shift->_set_get_one( 'Access-Control-Allow-Methods', @_ ) ); }
Subroutine allow_methods: not called CC=1 SCAR=6.9
Pod documented
184  
185 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin>
186 0 ▶sub allow_origin { return( shift->_set_get_one( 'Access-Control-Allow-Origin', @_ ) ); }
Subroutine allow_origin: not called CC=1 SCAR=6.9
Pod documented
187  
188 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Alt-Svc>
189 0 ▶sub alt_svc { return( shift->_set_get_multi( 'Alt-Svc', @_ ) ); }
Subroutine alt_svc: not called CC=1 SCAR=6.9
Pod documented
190  
191 sub alternate_server
192 {
193 0 ▶ my $self = shift( @_ );
Subroutine alternate_server: not called CC=4 SCAR=30.0
Pod documented
194 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
195 {
196 # { name => 'h2', value => 'alt.example.com:443', ma => 2592000, persist => 1
197 0 my $def = $self->_get_args_as_hash( @_ );
198 0 my $name = CORE::delete( $def->{name} );
199 0 my $value = CORE::delete( $def->{value} );
200 0 ▶ my $f = $self->new_field( alt_svc => [$name => $value], $def ) ||
Condition0%0/2
$self->new_field('alt_svc', [$name, $value], $def) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_field('alt_svc', [$name, $value], $def) || (return $self->pass_error)
$self->new_field('alt_svc', [$name, $value], $def)
Truth table0%0/2
A
A= $self->new_field('alt_svc', [$name, $value], $def)
Aresult
11
00
201 return( $self->pass_error );
202 0 $self->push_header( 'Alt-Svc' => "$f" );
203 }
204 else
205 {
206 0 my $all = $self->alt_svc;
207 0 ▶ return( $all ) if( !$all->length );
Branch: 1 branch
BranchTrueFalseTotal
unless $all->length 0 0 0
208 0 my $a = $self->new_array;
209 $all->foreach(sub
210 {
211 0 ▶ my $f = $self->new_field( alt_svc => $_ ) ||
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$self->new_field('alt_svc', $_) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_field('alt_svc', $_) || (return $self->pass_error)
$self->new_field('alt_svc', $_)
Truth table0%0/2
A
A= $self->new_field('alt_svc', $_)
Aresult
11
00
212 return( $self->pass_error );
213 0 $a->push( $f );
214 0 });
215 0 return( $a );
216 }
217 }
218  
219 # NOTE: as_string() is inherited
220 # NOTE: unfortunately, HTTP::XSHeaders is not dealing with as_string properly
221 # It takes the given eol and replace simply any instance in-between line of \n with it,
222 # thus if you have something like: foo\r\nbar\r\n, it will end up with
223 # foo\r\r\nbar\r\n instead of foot\r\nbar\r\n
224 # Bug report #10 <https://github.com/p5pclub/http-xsheaders/issues/10>
225 # sub as_string { return( shift->SUPER::as_string( @_ ? @_ : ( CRLF ) ) ); }
226 sub as_string
227 {
228 42 ▶ my $self = shift( @_ );
Subroutine as_string: called CC=6 SCAR=19.3
Pod documented
229 42 my $type = $self->type;
230 # If the type is multipart, ensure we have a boundary set.
231 # This is a convenience for the user, who only needs to set the mime-type
232 # without having to worry about generating a boundary.
233 42 ▶ 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 40 42
Condition100%3/3
defined $type and lc [split(m[/], $type, 2)]->[0] eq "multipart"
!ll&&!rl&&r
23172
MC/DC100%2/2
defined $type and lc [split(m[/], $type, 2)]->[0] eq "multipart"
defined $type lc [split(m[/], $type, 2)]->[0] eq "multipart"
Truth table100%3/3
A and B
A= defined $typeB= lc [split(m[/], $type, 2)]->[0] eq "multipart"
ABresult
0X0
100
111
234 {
235 2 my $boundary = $self->multipart_boundary;
236 2 ▶ unless( $boundary )
Branch: 1 branch
BranchTrueFalseTotal
unless ($boundary) 0 2 2
237 {
238 0 $boundary = $self->make_boundary;
239 0 my $ct = $self->new_field( 'Content-Type' => $type );
240 0 $ct->boundary( $boundary );
241 0 $self->content_type( "$ct" );
242 }
243 }
244 42 ▶ my $str = $self->SUPER::as_string( @_ ? @_ : ( CRLF ) );
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 23 19 42
245 42 ▶ if( index( $str, "\r\r\n" ) != -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($str, "\r\r\n") != -1) 0 42 42
246 {
247 0 $str =~ s/\r\r\n/\r\n/g;
248 }
249 42 return( $str );
250 }
251  
252 # NOTE: authorization() is inherited
253 0 ▶sub authorization { return( shift->_set_get_one( 'Authorization', @_ ) ); }
Subroutine authorization: not called CC=1 SCAR=6.9
Pod documented
254  
255 # NOTE: authorization_basic() is inherited
256 0 ▶sub authorization_basic { return( shift->_basic_auth( 'Authorization', @_ ) ); }
Subroutine authorization_basic: not called CC=1 SCAR=6.9
Pod documented
257  
258 sub boundary
259 {
260 1 ▶ my $self = shift( @_ );
Subroutine boundary: called CC=7 SCAR=33.9
Pod documented
261 1 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
262 {
263 0 my $boundary = shift( @_ );
264 0 my $ct = $self->content_type;
265 0 $self->{boundary} = $boundary;
266 # If there is a content type set, add the charset to it; otherwise, just return
267 # User should set the content type before setting the charset
268 0 ▶ return( '' ) if( !length( $ct ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $ct 0 0 0
269 0 ▶ my $f = $self->new_field( content_type => $ct ) ||
Condition0%0/2
$self->new_field('content_type', $ct) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_field('content_type', $ct) || (return $self->pass_error)
$self->new_field('content_type', $ct)
Truth table0%0/2
A
A= $self->new_field('content_type', $ct)
Aresult
11
00
270 return( $self->pass_error );
271 0 $f->param( boundary => $boundary );
272 0 $self->{type} = $f->type;
273 0 $self->content_type( $f );
274 0 $self->{_ctype_cached} = "$f";
275 }
276 1 ▶ unless( length( $self->{boundary} ) && $self->{_ctype_cached} eq $self->content_type )
Branch: 1 branch
BranchTrueFalseTotal
unless (length $self->{"boundary"} and $self->{"_ctype_cached"} eq $self->content_type) 0 1 1
Condition33%1/3
length $self->{"boundary"} and $self->{"_ctype_cached"} eq $self->content_type
!ll&&!rl&&r
001
MC/DC0%0/2
length $self->{"boundary"} and $self->{"_ctype_cached"} eq $self->content_type
length $self->{"boundary"} $self->{"_ctype_cached"} eq $self->content_type
Truth table33%1/3
A and B
A= length $self->{"boundary"}B= $self->{"_ctype_cached"} eq $self->content_type
ABresult
0X0
100
111
277 {
278 0 my $ct = $self->content_type;
279 0 ▶ my $f = $self->new_field( content_type => ( defined( $ct ) ? "$ct" : () ) );
Branch: 1 branch
BranchTrueFalseTotal
defined $ct ? : 0 0 0
280 0 $self->{boundary} = $f->boundary;
281 0 $self->{type} = $f->type;
282 0 $self->{_ctype_cached} = $ct;
283 }
284 1 return( $self->{boundary} );
285 }
286  
287 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control>
288 2 ▶sub cache_control { return( shift->_set_get_one( 'Cache-Control', @_ ) ); }
Subroutine cache_control: called CC=1 SCAR=0.0
Pod documented
289  
290 sub charset
291 {
292 0 ▶ my $self = shift( @_ );
Subroutine charset: not called CC=5 SCAR=34.0
Pod documented
293 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
294 {
295 0 my $charset = shift( @_ );
296 0 my $ct = $self->content_type;
297 0 $self->{charset} = $charset;
298 # If there is a content type set, add the charset to it; otherwise, just return
299 # User should set the content type before setting the charset
300 0 ▶ return( '' ) if( !length( $ct ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $ct 0 0 0
301 0 ▶ my $f = $self->new_field( content_type => $ct ) || return( $self->pass_error );
Condition0%0/2
$self->new_field('content_type', $ct) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_field('content_type', $ct) || (return $self->pass_error)
$self->new_field('content_type', $ct)
Truth table0%0/2
A
A= $self->new_field('content_type', $ct)
Aresult
11
00
302 0 $f->param( charset => $charset );
303 0 $self->content_type( $f );
304 }
305 0 ▶ unless( length( $self->{charset} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (length $self->{"charset"}) 0 0 0
306 {
307 0 my $ct = $self->content_type;
308 0 my $f = $self->new_field( content_type => $ct );
309 0 $self->{charset} = $f->charset;
310 }
311 0 return( $self->{charset} );
312 }
313  
314 # NOTE: clear() is inherited
315  
316 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Clear-Site-Data>
317 0 ▶sub clear_site_data { return( shift->_set_get_multi( 'Clear-Site-Data', @_ ) ); }
Subroutine clear_site_data: not called CC=1 SCAR=6.9
Pod documented
318  
319 2 ▶sub client_date { return( shift->_date_header( 'Client-Date', @_ ) ); }
Subroutine client_date: called CC=1 SCAR=0.0
Pod undocumented
320  
321 # NOTE: clone() is inherited
322  
323 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Connection>
324 0 ▶sub connection { return( shift->_set_get_one( 'Connection', @_ ) ); }
Subroutine connection: not called CC=1 SCAR=6.9
Pod documented
325  
326 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition>
327 63 ▶sub content_disposition { return( shift->_set_get_one( 'Content-Disposition', @_ ) ); }
Subroutine content_disposition: called CC=1 SCAR=0.0
Pod documented
328  
329 # NOTE: content_encoding() is implemented in our parent class, but our implementation differs
330 58 ▶sub content_encoding { return( shift->_set_get_one( 'Content-Encoding', @_ ) ); }
Subroutine content_encoding: called CC=1 SCAR=0.0
Pod documented
331  
332 # NOTE: content_is_html() is already implemented by our parent class, but our implementation of content_type() differs
333 sub content_is_html
334 {
335 0 ▶ my $self = shift( @_ );
Subroutine content_is_html: not called CC=4 SCAR=30.0
Pod documented
336 0 my $type = $self->type;
337 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
338 0 $type = lc( $type );
339 0 ▶ return( $type eq 'text/html' || $self->content_is_xhtml );
Condition0%0/3
$type eq 'text/html' || $self->content_is_xhtml
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq 'text/html' || $self->content_is_xhtml
$type eq 'text/html' $self->content_is_xhtml
Truth table0%0/3
A || B
A= $type eq 'text/html'B= $self->content_is_xhtml
ABresult
1X1
011
000
340 }
341  
342 sub content_is_json
343 {
344 0 ▶ my $self = shift( @_ );
Subroutine content_is_json: not called CC=4 SCAR=30.0
Pod documented
345 0 my $type = $self->type;
346 0 ▶ return(0) if( !defined( $type ) || !length( "$type" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and length "$type" 0 0 0
Condition0%0/3
defined $type and length "$type"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $type and length "$type"
defined $type length "$type"
Truth table0%0/3
A and B
A= defined $typeB= length "$type"
ABresult
0X0
100
111
347 0 $type = lc( $type );
348 # Standard API error payload as per RFC9457: application/problem+json
349 0 ▶ return( $type eq 'application/json' || $type =~ m,^application/\w+\+json, );
Condition0%0/3
$type eq 'application/json' || $type =~ m[^application/\w+\+json]
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq 'application/json' || $type =~ m[^application/\w+\+json]
$type eq 'application/json' $type =~ m[^application/\w+\+json]
Truth table0%0/3
A || B
A= $type eq 'application/json'B= $type =~ m[^application/\w+\+json]
ABresult
1X1
011
000
350 }
351  
352 sub content_is_text
353 {
354 8 ▶ my $self = shift( @_ );
Subroutine content_is_text: called CC=3 SCAR=12.0
Pod documented
355 8 my $type = $self->content_type;
356 8 ▶ return(0) if( !defined( $type ) || !length( "$type" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and length "$type" 0 8 8
Condition33%1/3
defined $type and length "$type"
!ll&&!rl&&r
008
MC/DC0%0/2
defined $type and length "$type"
defined $type length "$type"
Truth table33%1/3
A and B
A= defined $typeB= length "$type"
ABresult
0X0
100
111
357 8 return( $$type =~ m,^text/,i );
358 }
359  
360 # NOTE: content_is_xhtml() is already implemented by our parent class, but our implementation of content_type() differs
361 sub content_is_xhtml
362 {
363 0 ▶ my $self = shift( @_ );
Subroutine content_is_xhtml: not called CC=4 SCAR=30.0
Pod documented
364 0 my $type = $self->type;
365 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
366 0 $type = lc( $type );
367 0 ▶ return( $type eq 'application/xhtml+xml' || $type eq 'application/vnd.wap.xhtml+xml' );
Condition0%0/3
$type eq 'application/xhtml+xml' || $type eq 'application/vnd.wap.xhtml+xml'
l!l&&r!l&&!r
000
MC/DC0%0/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 table0%0/3
A || B
A= $type eq 'application/xhtml+xml'B= $type eq 'application/vnd.wap.xhtml+xml'
ABresult
1X1
011
000
368 }
369  
370 # NOTE: content_is_xml() is already implemented by our parent class, but our implementation of content_type() differs
371 sub content_is_xml
372 {
373 8 ▶ my $self = shift( @_ );
Subroutine content_is_xml: called CC=6 SCAR=19.6
Pod documented
374 8 my $type = $self->type;
375 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
376 8 $type = lc( $type );
377 8 ▶ return(1) if( $type eq 'text/xml' );
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "text/xml" 0 8 8
378 8 ▶ return(1) if( $type eq 'application/xml' );
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "application/xml" 0 8 8
379 8 ▶ return(1) if( $type =~ /\+xml$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $type =~ /\+xml$/ 0 8 8
380 8 return(0);
381 }
382  
383 # NOTE: content_language() is implemented in our parent class, but our implementation differs
384 0 ▶sub content_language { return( shift->_set_get_multi( 'Content-Language', @_ ) ); }
Subroutine content_language: not called CC=1 SCAR=6.9
Pod documented
385  
386 # NOTE: content_length() is implemented in our parent class, but our implementation differs
387 17 ▶sub content_length { return( shift->_set_get_one_number( 'Content-Length', @_ ) ); }
Subroutine content_length: called CC=1 SCAR=0.0
Pod documented
388  
389 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Location>
390 0 ▶sub content_location { return( shift->_set_get_one( 'Content-Location', @_ ) ); }
Subroutine content_location: not called CC=1 SCAR=6.9
Pod documented
391  
392 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range>
393 0 ▶sub content_range { return( shift->_set_get_one( 'Content-Range', @_ ) ); }
Subroutine content_range: not called CC=1 SCAR=6.9
Pod documented
394  
395 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy>
396 0 ▶sub content_security_policy { return( shift->_set_get_one( 'Content-Security-Policy', @_ ) ); }
Subroutine content_security_policy: not called CC=1 SCAR=6.9
Pod documented
397  
398 0 ▶sub content_security_policy_report_only { return( shift->_set_get_one( 'Content-Security-Policy-Report-Only', @_ ) ); }
Subroutine content_security_policy_report_only: not called CC=1 SCAR=6.9
Pod documented
399  
400 # NOTE: content_type() is already implemented by our parent class, but we our implementation is more straightforward in line with the idea of setting and getting exactly the header field value.
401 # Arguably, it is wrong to expect the return value of content_type to be only the mime_type, thus there is the type() method for that
402 sub content_type
403 {
404 189 ▶ my $self = shift( @_ );
Subroutine content_type: called CC=7 SCAR=19.7
Pod documented
405 189 my $v;
406 189 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 20 169 189
407 {
408 20 $v = shift( @_ );
409 20 $self->header( content_type => $v );
410 # Simple value, set the type() cache
411 20 ▶ if( index( $v, ';' ) == -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($v, ';') == -1) { } 7 13 20
412 {
413 7 $self->{type} = $v;
414 }
415 # Force type() to find the mime-type
416 else
417 {
418 13 $self->{type} = '';
419 }
420  
421 20 ▶ return( $self->new_scalar( ref( $v ) ? "$v" : \$v ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $v ? : 0 20 20
422 }
423 else
424 {
425 169 $v = $self->header( 'Content-Type' );
426 }
427  
428 169 ▶ if( defined( $v ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $v) { } 113 56 169
elsif (want('OBJECT')) { } 0 56 56
429 {
430 113 ▶ return( $self->new_scalar( ref( $v ) ? "$v" : \$v ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $v ? : 0 113 113
431 }
432 elsif( want( 'OBJECT' ) )
433 {
434 0 return( Module::Generic::Null->new );
435 }
436 else
437 {
438 56 return;
439 }
440 }
441  
442 # NOTE: content_type_charset() is inherited
443  
444 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Embedder-Policy>
445 0 ▶sub cross_origin_embedder_policy { return( shift->_set_get_one( 'Cross-Origin-Embedder-Policy', @_ ) ); }
Subroutine cross_origin_embedder_policy: not called CC=1 SCAR=6.9
Pod documented
446  
447 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy>
448 0 ▶sub cross_origin_opener_policy { return( shift->_set_get_one( 'Cross-Origin-Opener-Policy', @_ ) ); }
Subroutine cross_origin_opener_policy: not called CC=1 SCAR=6.9
Pod documented
449  
450 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy>
451 0 ▶sub cross_origin_resource_policy { return( shift->_set_get_one( 'Cross-Origin-Resource-Policy', @_ ) ); }
Subroutine cross_origin_resource_policy: not called CC=1 SCAR=6.9
Pod documented
452  
453 0 ▶sub cspro { return( shift->content_security_policy_report_only( @_ ) ); }
Subroutine cspro: not called CC=1 SCAR=6.9
Pod documented
454  
455 # NOTE: date() is already implemented by our parent class, but our implementation is more versatile and better
456 5 ▶sub date { return( shift->_date_header( 'Date', @_ ) ); }
Subroutine date: called CC=1 SCAR=0.0
Pod documented
457  
458 # rfc2231 <https://datatracker.ietf.org/doc/html/rfc2231>
459 sub decode_filename
460 {
461 8 ▶ my $self = shift( @_ );
Subroutine decode_filename: called CC=21 SCAR=53.8
Pod documented
462 8 my $fname = shift( @_ );
463 8 ▶ return( $fname ) if( !defined( $fname ) || !length( $fname ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fname and length $fname 0 8 8
Condition33%1/3
defined $fname and length $fname
!ll&&!rl&&r
008
MC/DC0%0/2
defined $fname and length $fname
defined $fname length $fname
Truth table33%1/3
A and B
A= defined $fnameB= length $fname
ABresult
0X0
100
111
464 8 my( $charset, $lang );
465 8 ▶ if( $fname =~ /^(.*?)\'([^\']*)\'(.*?)$/ )
Branch: 2 branches
BranchTrueFalseTotal
if ($fname =~ /^(.*?)\'([^\']*)\'(.*?)$/) { } 1 7 8
elsif ($fname =~ /^=\?(.+?)\?(.+?)\?(.+)\?=$/) { } 0 7 7
466 {
467 1 ( $charset, $lang, my $encoded_fname ) = ( $1, $2, $3 );
468 1 ▶ unless( lc( $charset ) eq 'utf8' || lc( $charset ) eq 'utf-8' )
Branch: 1 branch
BranchTrueFalseTotal
unless (lc $charset eq "utf8" or lc $charset eq "utf-8") 0 1 1
Condition33%1/3
lc $charset eq "utf8" or lc $charset eq "utf-8"
l!l&&r!l&&!r
010
MC/DC0%0/2
lc $charset eq "utf8" or lc $charset eq "utf-8"
lc $charset eq "utf8" lc $charset eq "utf-8"
Truth table33%1/3
A or B
A= lc $charset eq "utf8"B= lc $charset eq "utf-8"
ABresult
1X1
011
000
469 {
470 0 return( $self->error( "Character set '$charset' is not supported for file name '$encoded_fname'" ) );
471 }
472 # The language parameter, if any, is discarded
473 1 $fname = Encode::decode_utf8( URI::Escape::XS::uri_unescape( $encoded_fname ) );
474 }
475 # rfc2047 encoded?
476 elsif( $fname =~ /^=\?(.+?)\?(.+?)\?(.+)\?=$/ )
477 {
478 0 $charset = $1;
479 0 my $encoding = uc( $2 );
480 0 my $encfile = $3;
481  
482 0 ▶ if( $encoding eq 'Q' || $encoding eq 'B' )
Branch: 1 branch
BranchTrueFalseTotal
if ($encoding eq "Q" or $encoding eq "B") 0 0 0
Condition0%0/3
$encoding eq "Q" or $encoding eq "B"
l!l&&r!l&&!r
000
MC/DC0%0/2
$encoding eq "Q" or $encoding eq "B"
$encoding eq "Q" $encoding eq "B"
Truth table0%0/3
A or B
A= $encoding eq "Q"B= $encoding eq "B"
ABresult
1X1
011
000
483 {
484 eval
485 0 {
486 0 ▶ if( $encoding eq 'Q' )
Branch: 1 branch
BranchTrueFalseTotal
if ($encoding eq 'Q') { } 0 0 0
487 {
488 0 $encfile =~ s/_/ /g;
489 0 ▶ $self->_load_class( 'HTTP::Promise::Stream' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Stream") or return $self->pass_error 0 0 0
490 0 ▶ my $s = HTTP::Promise::Stream->new( \$encfile, { decoding => 'quoted-printable' } ) ||
Condition0%0/2
'HTTP::Promise::Stream'->new(\$encfile, {'decoding', 'quoted-printable'}) || (return $self->pass_error('HTTP::Promise::Stream'->error))
l!l
00
MC/DC0%0/1
'HTTP::Promise::Stream'->new(\$encfile, {'decoding', 'quoted-printable'}) || (return $self->pass_error('HTTP::Promise::Stream'->error))
'HTTP::Promise::Stream'->new(\$encfile, {'decoding', 'quoted-printable'})
Truth table0%0/2
A
A= 'HTTP::Promise::Stream'->new(\$encfile, {'decoding', 'quoted-printable'})
Aresult
11
00
491 return( $self->pass_error( HTTP::Promise::Stream->error ) );
492 0 my $decoded = $s->decode;
493 0 ▶ return( $self->pass_error( $s->error ) ) if( !defined( $decoded ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $decoded 0 0 0
494 0 $encfile = $decoded;
495 }
496 # $encoding eq 'B'
497 else
498 {
499 0 ▶ $self->_load_class( 'Crypt::Misc' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Crypt::Misc") or return $self->pass_error 0 0 0
500 0 $encfile = Crypt::Misc::decode_b64( $encfile );
501 }
502 };
503  
504 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
505 {
506 # return( $self->error( "Error decoding content disposition file name: $e" ) );
507 0 ▶ warn( "Error decoding content disposition file name: $@" ) if( warnings::enabled( 'HTTP::Promise' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("HTTP::Promise") 0 0 0
508 }
509  
510 eval
511 0 {
512 0 ▶ $self->_load_class( 'Encode' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Encode") or return $self->pass_error 0 0 0
513 0 ▶ $self->_load_class( 'Encode::Locale' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Encode::Locale") or return $self->pass_error 0 0 0
514 0 Encode::from_to( $encfile, $charset, 'locale_fs' );
515 0 $fname = $encfile;
516 };
517  
518 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
519 {
520 # return( $self->error( "Error encoding content disposition file name: $e" ) );
521 0 ▶ warn( "Error encoding content disposition file name from '$charset' to 'locale_fs': $@" ) if( warnings::enabled( 'HTTP::Promise' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("HTTP::Promise") 0 0 0
522 }
523 }
524 }
525 8 ▶ return( wantarray() ? ( $fname, $charset, $lang ) : $fname );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 7 1 8
526 }
527  
528 sub debug
529 {
530 49 ▶ my $self = shift( @_ );
Subroutine debug: called CC=6 SCAR=20.4
Pod documented
531 49 ▶ my $class = ( ref( $self ) || $self );
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
4900
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
532 13 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
533 49 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 49 0 49
534 {
535 49 my $flag = shift( @_ );
536 49 $self->{debug} = $flag;
537 49 ▶ if( $self->{debug} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"} and not $self->{"debug_level"}) 0 49 49
Condition33%1/3
$self->{"debug"} and not $self->{"debug_level"}
!ll&&!rl&&r
4900
MC/DC0%0/2
$self->{"debug"} and not $self->{"debug_level"}
$self->{"debug"} not $self->{"debug_level"}
Truth table33%1/3
A and not(B)
A= $self->{"debug"}B= not $self->{"debug_level"}
ABresult
0X0
100
111
538 !$self->{debug_level} )
539 {
540 0 $self->{debug_level} = $self->{debug};
541 }
542 }
543 49 ▶ return( $self->{debug} || ${"$class\:\:DEBUG"} );
Condition33%1/3
$self->{'debug'} || ${"${class}::DEBUG";}
l!l&&r!l&&!r
0490
MC/DC0%0/2
$self->{'debug'} || ${"${class}::DEBUG";}
$self->{'debug'} ${"${class}::DEBUG";}
Truth table33%1/3
A || B
A= $self->{'debug'}B= ${"${class}::DEBUG";}
ABresult
1X1
011
000
544 }
545  
546 40 ▶sub default_type { return( shift->_set_get( 'default_type', @_ ) ); }
Subroutine default_type: called CC=1 SCAR=0.0
Pod documented
547  
548 0 ▶sub delete { return( shift->remove_header( @_ ) ); }
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
549  
550 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Device-Memory>
551 0 ▶sub device_memory { return( shift->_set_get_one( 'Device-Memory', @_ ) ); }
Subroutine device_memory: not called CC=1 SCAR=6.9
Pod documented
552  
553 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Digest>
554 0 ▶sub digest { return( shift->_set_get_multi( 'Digest', @_ ) ); }
Subroutine digest: not called CC=1 SCAR=6.9
Pod documented
555  
556 # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/DNT
557 0 ▶sub dnt { return( shift->_set_get_one( dnt => @_ ) ); }
Subroutine dnt: not called CC=1 SCAR=6.9
Pod documented
558  
559 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Early-Data>
560 0 ▶sub early_data { return( shift->_set_get_one( 'Early-Data', @_ ) ); }
Subroutine early_data: not called CC=1 SCAR=6.9
Pod documented
561  
562 # rfc2231 <https://datatracker.ietf.org/doc/html/rfc2231>
563 sub encode_filename
564 {
565 3 ▶ my $self = shift( @_ );
Subroutine encode_filename: called CC=3 SCAR=11.6
Pod documented
566 3 my $fname = shift( @_ );
567 3 my $lang = shift( @_ );
568 3 ▶ if( $fname =~ /[^\w\.]+/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($fname =~ /[^\w\.]+/) 3 0 3
569 {
570 3 ▶ $lang = '' if( !defined( $lang ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lang 3 0 3
571 3 return( sprintf( "UTF-8'${lang}'%s", $self->uri_escape_utf8( $fname ) ) );
572 }
573 # Nothing to be done. We return undef on purpose to indicate nothing was done
574 0 return;
575 }
576  
577 # Copied here from Module::Generic
578 sub error
579 {
580 0 ▶ my $self = shift( @_ );
Subroutine error: not called CC=54 SCAR=78.7
Pod documented
581 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
582 0 ▶ my $i_am_blessed = Scalar::Util::blessed( $self ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($self) ? : 0 0 0
583 13 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
584 0 our $MOD_PERL;
585 0 my $o;
586 13 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
587 13 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
588 my $want_return =
589 {
590 array => sub
591 {
592 0 ▶ return( [] );
Subroutine __ANON__: not called CC=1 SCAR=6.9
593 },
594 code => sub
595 {
596 0 ▶ return( sub{} );
Subroutine __ANON__: not called CC=1 SCAR=6.9
597 },
598 'glob' => sub
599 {
600 0 ▶ my $dummy = '';
Subroutine __ANON__: not called CC=1 SCAR=6.9
601 0 open( my $tmp, '>', \$dummy );
602 0 return( $tmp );
603 },
604 hash => sub
605 {
606 0 ▶ return( {} );
Subroutine __ANON__: not called CC=1 SCAR=6.9
607 },
608 object => sub
609 {
610 0 ▶ $self->_load_class( 'Module::Generic::Null' ) ||
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Null") or die "Unable to load Module::Generic::Null" 0 0 0
611 die( "Unable to load Module::Generic::Null" );
612 0 my $null = Module::Generic::Null->new( $o, { debug => $self->{debug}, has_error => 1, wants => 'object' });
613 0 return( $null );
614 },
615 'scalar' => sub
616 {
617 0 ▶ my $dummy = undef;
Subroutine __ANON__: not called CC=1 SCAR=6.9
618 0 return( \$dummy );
619 },
620 0 };
621  
622 0 my $want_what = Wanted::wantref();
623  
624 # Ensure this is lowercase and at the same time that this is defined
625 0 ▶ $want_what = lc( $want_what // '' );
Condition0%0/2
$want_what // ""
l!l
00
MC/DC0%0/1
$want_what // ""
$want_what
Truth table0%0/2
A
A= $want_what
Aresult
11
00
626 # What type of expected value we support to prevent perl error upon undef.
627 # By default: object
628 0 my $want_ok = [qw( object )];
629  
630 0 ▶ my $err_key = HAS_THREADS ? join( ';', $class, $$, threads->tid ) : join( ';', $class, $$ );
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 0 0 0
631 0 my $repo = Module::Generic::Global->new( 'errors' => $class, key => $err_key );
632 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
633 {
634 0 my $args = {};
635 # We got an object as first argument. It could be a child from our exception package or from another package
636 # Either way, we use it as it is
637 0 ▶ 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 0 0
elsif (ref $_[0] eq 'HASH') { } 0 0 0
Condition0%0/6
builtin::blessed($_[0]) and $_[0]->isa("Module::Generic::Exception") or builtin::blessed($_[0])
l!l&&r!l&&!r
000
builtin::blessed($_[0]) and $_[0]->isa("Module::Generic::Exception")
!ll&&!rl&&r
000
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 table0%0/5
A and B or C
A= builtin::blessed($_[0])B= $_[0]->isa("Module::Generic::Exception")C= builtin::blessed($_[0])
ABCresult
11X1
0X11
1011
0X00
1000
638 Scalar::Util::blessed( $_[0] ) )
639 {
640 0 $o = shift( @_ );
641 }
642 elsif( ref( $_[0] ) eq 'HASH' )
643 {
644 0 $args = shift( @_ );
645 }
646 else
647 {
648 0 ▶ $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 0 0
Condition0%0/3
ref $_ eq "CODE" and not $self->{"_msg_no_exec_sub"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_ eq "CODE" and not $self->{"_msg_no_exec_sub"}
ref $_ eq "CODE" not $self->{"_msg_no_exec_sub"}
Truth table0%0/3
A and not(B)
A= ref $_ eq "CODE"B= not $self->{"_msg_no_exec_sub"}
ABresult
0X0
100
111
649 }
650 0 ▶ $args->{class} //= '';
Condition0%0/2
$args->{"class"} //= ""
l!l
00
MC/DC0%0/1
$args->{"class"} //= ""
$args->{"class"}
Truth table0%0/2
A
A= $args->{"class"}
Aresult
11
00
651 my $max_len = ( CORE::exists( $self->{error_max_length} ) && $self->{error_max_length} =~ /^[-+]?\d+$/ )
652 ? $self->{error_max_length}
653 0 ▶ : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'error_max_length'} && $self->{'error_max_length'} =~ /^[-+]?\d+$/ ? : 0 0 0
Condition0%0/3
exists $self->{"error_max_length"} and $self->{"error_max_length"} =~ /^[-+]?\d+$/
!ll&&!rl&&r
000
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 table0%0/3
A and B
A= exists $self->{"error_max_length"}B= $self->{"error_max_length"} =~ /^[-+]?\d+$/
ABresult
0X0
100
111
654 0 ▶ $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 0 0
Condition0%0/3
$max_len > 0 and length $args->{"message"} > $max_len
!ll&&!rl&&r
000
MC/DC0%0/2
$max_len > 0 and length $args->{"message"} > $max_len
$max_len > 0 length $args->{"message"} > $max_len
Truth table0%0/3
A and B
A= $max_len > 0B= length $args->{"message"} > $max_len
ABresult
0X0
100
111
655 # Reset it
656 0 $self->{_msg_no_exec_sub} = 0;
657 # Note Taken from Carp to find the right point in the stack to start from
658 0 my $caller_func;
659 0 ▶ $caller_func = \&{"CORE::GLOBAL::caller"} if( defined( &{"CORE::GLOBAL::caller"} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined &{"CORE::GLOBAL::caller";} 0 0 0
660 0 ▶ if( !defined( $o ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $o) 0 0 0
661 {
662 my $ex_class = CORE::length( $args->{class} )
663 ? $args->{class}
664 : ( CORE::exists( $self->{_exception_class} ) && CORE::length( $self->{_exception_class} ) )
665 ? $self->{_exception_class}
666 0 ▶ : 'Module::Generic::Exception';
Branch: 2 branches
BranchTrueFalseTotal
length $args->{'class'} ? : 0 0 0
exists $self->{'_exception_class'} && length $self->{'_exception_class'} ? : 0 0 0
Condition0%0/3
exists $self->{"_exception_class"} and length $self->{"_exception_class"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"_exception_class"} and length $self->{"_exception_class"}
exists $self->{"_exception_class"} length $self->{"_exception_class"}
Truth table0%0/3
A and B
A= exists $self->{"_exception_class"}B= length $self->{"_exception_class"}
ABresult
0X0
100
111
667 0 ▶ unless( $self->_is_class_loaded( $ex_class ) || scalar( keys( %{"${ex_class}\::"} ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_class_loaded($ex_class) or scalar keys %{"${ex_class}::";}) 0 0 0
Condition0%0/2
$self->_is_class_loaded($ex_class) or scalar keys %{"${ex_class}::";}
l!l
00
MC/DC0%0/1
$self->_is_class_loaded($ex_class) or scalar keys %{"${ex_class}::";}
$self->_is_class_loaded($ex_class)
Truth table0%0/2
A
A= $self->_is_class_loaded($ex_class)
Aresult
11
00
668 {
669 0 my $pl = "use $ex_class;";
670 0 ▶ local $SIG{__DIE__} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
671 0 eval( $pl );
672 # We have to die, because we have an error within another error
673 0 ▶ die( __PACKAGE__ . "::error() is unable to load exception class \"$ex_class\": $@" ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
674 }
675 # $o = $self->{error} = ${ $class . '::ERROR' } = $ex_class->new( $args );
676 0 $o = $ex_class->new( $args );
677 }
678 0 $self->{error} = $o;
679 0 $repo->set( $o );
680 # For backward compatibility, so the user can access $My::Module::ERROR
681 0 ${ $class . '::ERROR' } = $o;
682  
683 0 my $r;
684 0 ▶ if( $MOD_PERL )
Branch: 1 branch
BranchTrueFalseTotal
if ($HTTP::Promise::Headers::MOD_PERL) 0 0 0
685 {
686 # try-catch
687 0 local $@;
688 eval
689 0 {
690 0 $r = Apache2::RequestUtil->request;
691 0 ▶ $r->warn( $o->as_string ) if( $r );
Branch: 1 branch
BranchTrueFalseTotal
if $r 0 0 0
692 };
693 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
694 {
695 0 print( STDERR "Error trying to get the global Apache2::ApacheRec: $@\n" );
696 }
697 }
698  
699 0 ▶ if( $r )
Branch: 3 branches
BranchTrueFalseTotal
if ($r) { } 0 0 0
elsif ($self->{'fatal'} or defined ${"${class}::FATAL_ERROR";} and ${"${class}::FATAL_ERROR";}) { } 0 0 0
elsif (warnings::enabled('HTTP::Promise')) { } 0 0 0
700 {
701 0 ▶ if( my $log_handler = $r->get_handlers( 'PerlPrivateErrorHandler' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $log_handler = $r->get_handlers('PerlPrivateErrorHandler')) { } 0 0 0
702 {
703 0 $log_handler->( $o );
704 }
705 else
706 {
707 0 ▶ $r->warn( $o->as_string ) if( warnings::enabled( 'HTTP::Promise' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("HTTP::Promise") 0 0 0
708 }
709 }
710 0 ▶ elsif( $self->{fatal} || ( defined( ${"${class}\::FATAL_ERROR"} ) && ${"${class}\::FATAL_ERROR"} ) )
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
711 {
712 # my $enc_str = eval{ Encode::encode( 'UTF-8', "$o", Encode::FB_CROAK ) };
713 # die( $@ ? $o : $enc_str );
714 0 die( $o );
715 }
716 elsif( warnings::enabled( 'HTTP::Promise' ) )
717 {
718 0 ▶ if( $r )
Branch: 1 branch
BranchTrueFalseTotal
if ($r) { } 0 0 0
719 {
720 0 $r->warn( $o->as_string );
721 }
722 else
723 {
724 0 my $enc_str = eval{ Encode::encode( 'UTF-8', "$o", Encode::FB_CROAK ) };
725 # Display warnings if warnings for this class is registered and enabled or if not registered
726 0 ▶ warn( $@ ? $o : $enc_str );
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 0 0
727 }
728 }
729  
730 # https://metacpan.org/pod/Perl::Critic::Policy::Subroutines::ProhibitExplicitReturnUndef
731 # https://perlmonks.org/index.pl?node_id=741847
732 # Because in list context this would create a lit with one element undef()
733 # A bare return will return an empty list or an undef scalar
734 # return( undef() );
735 # return;
736 # As of 2019-10-13, Module::Generic version 0.6, we use this special package Module::Generic::Null to be returned in chain without perl causing the error that a method was called on an undefined value
737 # 2020-05-12: Added the no_return_null_object to instruct not to return a null object
738 # This is especially needed when an error is called from TIEHASH that returns a special object.
739 # A Null object would trigger a fatal perl segmentation fault
740 0 ▶ 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 0 0
Condition0%0/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
000
$want_what and exists $want_return->{$want_what} and scalar grep(/^$want_what$/i, @$want_ok) or $args->{"object"}
l!l&&r!l&&!r
000
$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/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 table0%0/6
not(A) and B and C or D
A= not $args->{"no_return_null_object"}B= $want_whatC= exists $want_return->{$want_what}D= $args->{"object"}
ABCDresult
0XXX0
10X00
11000
111X1
10X11
11011
741 (
742 ( $want_what && CORE::exists( $want_return->{ $want_what } ) && scalar( grep( /^$want_what$/i, @$want_ok ) ) ) ||
743 $args->{object}
744 ) )
745 {
746 0 ▶ if( $args->{object} )
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'object'}) { } 0 0 0
747 {
748 0 rreturn( $want_return->{object}->() );
749 }
750 else
751 {
752 0 rreturn( $want_return->{ $want_what }->() );
753 }
754 }
755 0 return;
756 }
757 0 ▶ if( $i_am_blessed )
Branch: 1 branch
BranchTrueFalseTotal
if ($i_am_blessed) 0 0 0
758 {
759 # To avoid the perl error of 'called on undefined value' and so the user can do
760 # $o->error->_message for example without concerning himself/herself whether an exception object is actually set
761 0 ▶ if( !$self->{error} )
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'error'}) { } 0 0 0
762 {
763 0 ▶ if( $want_what &&
Branch: 1 branch
BranchTrueFalseTotal
if ($want_what and exists $want_return->{$want_what} and scalar grep(/^$want_what$/i, @$want_ok)) 0 0 0
Condition0%0/5
$want_what and exists $want_return->{$want_what} and scalar grep(/^$want_what$/i, @$want_ok)
!ll
00
$want_what and exists $want_return->{$want_what}
!ll&&!rl&&r
000
MC/DC0%0/2
$want_what and exists $want_return->{$want_what} and scalar grep(/^$want_what$/i, @$want_ok)
$want_what exists $want_return->{$want_what}
Truth table0%0/3
A and B
A= $want_whatB= exists $want_return->{$want_what}
ABresult
0X0
100
111
764 CORE::exists( $want_return->{ $want_what } ) &&
765 scalar( grep( /^$want_what$/i, @$want_ok ) ) )
766 {
767 0 rreturn( $want_return->{ $want_what }->() );
768 }
769 }
770 else
771 {
772 0 return( $self->{error} );
773 }
774 }
775  
776 0 $o = $repo->get;
777 0 ▶ if( CORE::defined( $o ) && CORE::length( $o ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $o and length $o) { } 0 0 0
elsif (not &CAN_THREADS() and defined ${$class . '::ERROR';} and length ${$class . '::ERROR';}) { } 0 0 0
Condition0%0/3
defined $o and length $o
!ll&&!rl&&r
000
MC/DC0%0/2
defined $o and length $o
defined $o length $o
Truth table0%0/3
A and B
A= defined $oB= length $o
ABresult
0X0
100
111
778 {
779 # Found an exception object using Module::Generic::Global
780 }
781 ▶ elsif( !CAN_THREADS &&
Condition0%0/6
not &CAN_THREADS() and defined ${$class . '::ERROR';} and length ${$class . '::ERROR';}
!ll&&!rl&&r
000
not &CAN_THREADS() and defined ${$class . '::ERROR';}
!ll&&!rl&&r
000
MC/DC0%0/3
not &CAN_THREADS() and defined ${$class . '::ERROR';} and length ${$class . '::ERROR';}
not &CAN_THREADS() defined ${$class . '::ERROR';} length ${$class . '::ERROR';}
Truth table0%0/4
not(A) and B and C
A= not &CAN_THREADS()B= defined ${$class . '::ERROR';}C= length ${$class . '::ERROR';}
ABCresult
0XX0
10X0
1100
1111
782 0 CORE::defined( ${ $class . '::ERROR' } ) &&
783 0 CORE::length( ${ $class . '::ERROR' } ) )
784 {
785 0 $o = ${ $class . '::ERROR' };
786 0 ▶ warn( "Accessing ${class}::ERROR is deprecated; use ${class}->error instead" ) if( warnings::enabled( 'HTTP::Promise' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("HTTP::Promise") 0 0 0
787 }
788 0 return( $o );
789 }
790  
791 0 ▶sub etag { return( shift->_set_get_one( 'Etag', @_ ) ); }
Subroutine etag: not called CC=1 SCAR=6.9
Pod documented
792  
793 sub exists
794 {
795 25 ▶ my $self = shift( @_ );
Subroutine exists: called CC=3 SCAR=11.4
Pod documented
796 25 ▶ my $field = shift( @_ ) || return(0);
Condition50%1/2
shift @_ || (return 0)
l!l
250
MC/DC0%0/1
shift @_ || (return 0)
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
797 25 my $rv = $self->header( $field );
798 25 ▶ return( defined( $rv ) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
defined $rv ? : 0 25 25
799 }
800  
801 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expect>
802 0 ▶sub expect { return( shift->_set_get_one( 'Expect', @_ ) ); }
Subroutine expect: not called CC=1 SCAR=6.9
Pod documented
803  
804 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expect-CT>
805 0 ▶sub expect_ct { return( shift->_set_get_multi( 'Expect-CT', @_ ) ); }
Subroutine expect_ct: not called CC=1 SCAR=6.9
Pod documented
806  
807 # NOTE: expires() is inherited
808 0 ▶sub expires { return( shift->_date_header( 'Expires', @_ ) ); }
Subroutine expires: not called CC=1 SCAR=6.9
Pod documented
809  
810 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers>
811 # e.g.: Access-Control-Expose-Headers: Content-Encoding, X-Kuma-Revision
812 0 ▶sub expose_headers { return( shift->_set_get_multi( 'Access-Control-Expose-Headers', @_ ) ); }
Subroutine expose_headers: not called CC=1 SCAR=6.9
Pod documented
813  
814 # NOTE: flatten() is inherited
815  
816 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded>
817 0 ▶sub forwarded { return( shift->_set_get_one( 'Forwarded', @_ ) ); }
Subroutine forwarded: not called CC=1 SCAR=6.9
Pod documented
818  
819 # NOTE: from() is inherited
820 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/From>
821 0 ▶sub from { return( shift->_set_get_one( 'From', @_ ) ); }
Subroutine from: not called CC=1 SCAR=6.9
Pod documented
822  
823 0 ▶sub get { return( shift->header( shift( @_ ) ) ); }
Subroutine get: not called CC=1 SCAR=6.9
Pod documented
824  
825 # NOTE: header() is inherited
826  
827 # NOTE: header_field_names() is inherited
828  
829 0 ▶sub host { return( shift->_set_get_one( 'Host', @_ ) ); }
Subroutine host: not called CC=1 SCAR=6.9
Pod documented
830  
831 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match>
832 0 ▶sub if_match { return( shift->_set_get_one( 'If-Match', @_ ) ); }
Subroutine if_match: not called CC=1 SCAR=6.9
Pod documented
833  
834 # NOTE: if_modified_since() is inherited
835 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Modified-Since>
836 0 ▶sub if_modified_since { return( shift->_date_header( 'If-Modified-Since', @_ ) ); }
Subroutine if_modified_since: not called CC=1 SCAR=6.9
Pod documented
837  
838 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-None-Match>
839 0 ▶sub if_none_match { return( shift->_set_get_one( 'If-None-Match', @_ ) ); }
Subroutine if_none_match: not called CC=1 SCAR=6.9
Pod documented
840  
841 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Range>
842 0 ▶sub if_range { return( shift->_set_get_one( 'If-Range', @_ ) ); }
Subroutine if_range: not called CC=1 SCAR=6.9
Pod documented
843  
844 # NOTE: if_unmodified_since() is inherited
845 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Unmodified-Since>
846 0 ▶sub if_unmodified_since { return( shift->_date_header( 'If-Unmodified-Since', @_ ) ); }
Subroutine if_unmodified_since: not called CC=1 SCAR=6.9
Pod documented
847  
848 # NOTE: init_header() is inherited
849  
850 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive>
851 0 ▶sub keep_alive { return( shift->_set_get_one( 'Keep-Alive', @_ ) ); }
Subroutine keep_alive: not called CC=1 SCAR=6.9
Pod documented
852  
853 # NOTE: last_modified() is inherited
854 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Last-Modified>
855 1 ▶sub last_modified { return( shift->_date_header( 'Last-Modified', @_ ) ); }
Subroutine last_modified: called CC=1 SCAR=0.0
Pod documented
856  
857 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link>
858 0 ▶sub link { return( shift->_set_get_multi( 'Link', @_ ) ); }
Subroutine link: not called CC=1 SCAR=6.9
Pod documented
859  
860 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location>
861 0 ▶sub location { return( shift->_set_get_one( 'Location', @_ ) ); }
Subroutine location: not called CC=1 SCAR=6.9
Pod documented
862  
863 sub make_boundary
864 {
865 0 ▶ my $self = shift( @_ );
Subroutine make_boundary: not called CC=2 SCAR=17.9
Pod documented
866 0 ▶ $self->_load_class( 'Data::UUID' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Data::UUID") or return $self->pass_error 0 0 0
867 0 return( Data::UUID->new->create_str );
868 }
869  
870 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age>
871 0 ▶sub max_age { return( shift->_set_get_number( 'Access-Control-Max-Age', @_ ) ); }
Subroutine max_age: not called CC=1 SCAR=6.9
Pod documented
872  
873 sub message
874 {
875 0 ▶ my $self = shift( @_ );
Subroutine message: not called CC=51 SCAR=77.9
Pod undocumented
876 0 ▶ my $class = ref( $self ) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
877 13 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
878 0 ▶ if( $self->{verbose} || $self->{debug} || ${ $class . '::DEBUG' } )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"} or $self->{"debug"} or ${$class . '::DEBUG';}) 0 0 0
Condition0%0/6
$self->{"verbose"} or $self->{"debug"} or ${$class . '::DEBUG';}
l!l&&r!l&&!r
000
$self->{"verbose"} or $self->{"debug"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{"verbose"} or $self->{"debug"} or ${$class . '::DEBUG';}
$self->{"verbose"} $self->{"debug"} ${$class . '::DEBUG';}
Truth table0%0/4
A or B or C
A= $self->{"verbose"}B= $self->{"debug"}C= ${$class . '::DEBUG';}
ABCresult
1XX1
01X1
0011
0000
879 {
880 0 my $r;
881 0 ▶ if( $MOD_PERL )
Branch: 1 branch
BranchTrueFalseTotal
if ($HTTP::Promise::Headers::MOD_PERL) 0 0 0
882 {
883 # try-catch
884 0 local $@;
885 eval
886 0 {
887 0 $r = Apache2::RequestUtil->request;
888 };
889 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
890 {
891 0 $stderr_raw->print( "Error trying to get the global Apache2::ApacheRec: $@\n" );
892 }
893 }
894  
895 0 my $ref;
896 0 $ref = $self->message_check( @_ );
897 0 ▶ return(1) if( !$ref );
Branch: 1 branch
BranchTrueFalseTotal
unless $ref 0 0 0
898  
899 0 my $opts = {};
900 0 ▶ $opts = pop( @$ref ) if( ref( $ref->[-1] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $ref->[-1] eq "HASH" 0 0 0
901  
902 0 ▶ my $stackFrame = $self->message_frame( (caller(1))[3] ) || 1;
Condition0%0/2
$self->message_frame((caller 1)[3]) || 1
l!l
00
MC/DC0%0/1
$self->message_frame((caller 1)[3]) || 1
$self->message_frame((caller 1)[3])
Truth table0%0/2
A
A= $self->message_frame((caller 1)[3])
Aresult
11
00
903 0 ▶ $stackFrame = 1 unless( $stackFrame =~ /^\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $stackFrame =~ /^\d+$/ 0 0 0
904 0 ▶ $stackFrame-- if( $stackFrame );
Branch: 1 branch
BranchTrueFalseTotal
if $stackFrame 0 0 0
905 0 ▶ $stackFrame++ if( ( (caller(1))[3] // '' ) eq 'HTTP::Promise::Headers::messagef' );
Branch: 1 branch
BranchTrueFalseTotal
if ((caller 1)[3] // "") eq "HTTP::Promise::Headers::messagef" 0 0 0
Condition0%0/2
(caller 1)[3] // ""
l!l
00
MC/DC0%0/1
(caller 1)[3] // ""
(caller 1)[3]
Truth table0%0/2
A
A= (caller 1)[3]
Aresult
11
00
906 0 my( $pkg, $file, $line, @otherInfo ) = caller( $stackFrame );
907 0 ▶ my $sub = ( caller( $stackFrame + 1 ) )[3] // '';
Condition0%0/2
(caller $stackFrame + 1)[3] // ""
l!l
00
MC/DC0%0/1
(caller $stackFrame + 1)[3] // ""
(caller $stackFrame + 1)[3]
Truth table0%0/2
A
A= (caller $stackFrame + 1)[3]
Aresult
11
00
908 0 my $sub2 = substr( $sub, rindex( $sub, '::' ) + 2 );
909 0 ▶ if( ref( $self->{_message_frame} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"_message_frame"} eq "HASH") 0 0 0
910 {
911 0 ▶ if( exists( $self->{_message_frame}->{ $sub2 } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_message_frame"}{$sub2}) 0 0 0
912 {
913 0 my $frameNo = int( $self->{_message_frame}->{ $sub2 } );
914 0 ▶ if( $frameNo > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($frameNo > 0) 0 0 0
915 {
916 0 ( $pkg, $file, $line, $sub ) = caller( $frameNo );
917 0 $sub2 = substr( $sub, rindex( $sub, '::' ) + 2 );
918 }
919 }
920 }
921 0 ▶ if( $sub2 eq 'message' )
Branch: 1 branch
BranchTrueFalseTotal
if ($sub2 eq "message") 0 0 0
922 {
923 0 $stackFrame++;
924 0 ( $pkg, $file, $line, @otherInfo ) = caller( $stackFrame );
925 0 ▶ my $sub = ( caller( $stackFrame + 1 ) )[3] // '';
Condition0%0/2
(caller $stackFrame + 1)[3] // ""
l!l
00
MC/DC0%0/1
(caller $stackFrame + 1)[3] // ""
(caller $stackFrame + 1)[3]
Truth table0%0/2
A
A= (caller $stackFrame + 1)[3]
Aresult
11
00
926 0 $sub2 = substr( $sub, rindex( $sub, '::' ) + 2 );
927 }
928 0 my $txt;
929 0 ▶ if( $opts->{message} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'message'}) { } 0 0 0
930 {
931 0 ▶ if( ref( $opts->{message} ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opts->{'message'} eq 'ARRAY') { } 0 0 0
932 {
933 0 ▶ $txt = join( '', map( ( ref( $_ ) eq 'CODE' && !$self->{_msg_no_exec_sub} ) ? $_->() : ( $_ // '' ), @{$opts->{message}} ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' && !$self->{'_msg_no_exec_sub'} ? : 0 0 0
Condition0%0/5
ref $_ eq "CODE" and not $self->{"_msg_no_exec_sub"}
!ll&&!rl&&r
000
$_ // ""
l!l
00
MC/DC0%0/2
ref $_ eq "CODE" and not $self->{"_msg_no_exec_sub"}
ref $_ eq "CODE" not $self->{"_msg_no_exec_sub"}
MC/DC0%0/1
$_ // ""
$_
Truth table0%0/3
A and not(B)
A= ref $_ eq "CODE"B= not $self->{"_msg_no_exec_sub"}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $_
Aresult
11
00
934 }
935 else
936 {
937 0 $txt = $opts->{message};
938 }
939 }
940 else
941 {
942 0 ▶ $txt = join( '', map( ( ref( $_ ) eq 'CODE' && !$self->{_msg_no_exec_sub} ) ? $_->() : ( $_ // '' ), @$ref ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' && !$self->{'_msg_no_exec_sub'} ? : 0 0 0
Condition0%0/5
ref $_ eq "CODE" and not $self->{"_msg_no_exec_sub"}
!ll&&!rl&&r
000
$_ // ""
l!l
00
MC/DC0%0/2
ref $_ eq "CODE" and not $self->{"_msg_no_exec_sub"}
ref $_ eq "CODE" not $self->{"_msg_no_exec_sub"}
MC/DC0%0/1
$_ // ""
$_
Truth table0%0/3
A and not(B)
A= ref $_ eq "CODE"B= not $self->{"_msg_no_exec_sub"}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $_
Aresult
11
00
943 }
944 # Reset it
945 0 $self->{_msg_no_exec_sub} = 0;
946 0 ▶ my $prefix = CORE::length( $opts->{prefix} ) ? $opts->{prefix} : '##';
Branch: 1 branch
BranchTrueFalseTotal
length $opts->{'prefix'} ? : 0 0 0
947 13 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
948 0 ▶ $opts->{caller_info} = 1 if( !CORE::exists( $opts->{caller_info} ) || !CORE::length( $opts->{caller_info} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"caller_info"} and length $opts->{"caller_info"} 0 0 0
Condition0%0/3
exists $opts->{"caller_info"} and length $opts->{"caller_info"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"caller_info"} and length $opts->{"caller_info"}
exists $opts->{"caller_info"} length $opts->{"caller_info"}
Truth table0%0/3
A and B
A= exists $opts->{"caller_info"}B= length $opts->{"caller_info"}
ABresult
0X0
100
111
949 0 my $proc_info = " [PID: $$]";
950 0 ▶ if( HAS_THREADS )
Branch: 1 branch
BranchTrueFalseTotal
if (&HAS_THREADS()) 0 0 0
951 {
952 0 my $tid = threads->tid;
953 0 ▶ $proc_info .= ' -> [thread id ' . $tid . ']' if( $tid );
Branch: 1 branch
BranchTrueFalseTotal
if $tid 0 0 0
954 }
955 0 ▶ my $mesg_raw = $opts->{caller_info} ? ( "${pkg}::${sub2}( $self ) [$line]${proc_info}: " . $txt ) : $txt;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'caller_info'} ? : 0 0 0
956 0 $mesg_raw =~ s/\n$//gs;
957 0 my $mesg = "${prefix} " . join( "\n${prefix} ", split( /\n/, $mesg_raw ) );
958  
959 my $info =
960 {
961 'formatted' => $mesg,
962 'message' => $txt,
963 'file' => $file,
964 'line' => $line,
965 'package' => $class,
966 'sub' => $sub2,
967 0 ▶ 'level' => ( $_[0] =~ /^\d+$/ ? $_[0] : CORE::exists( $opts->{level} ) ? $opts->{level} : 0 ),
Branch: 2 branches
BranchTrueFalseTotal
$_[0] =~ /^\d+$/ ? : 0 0 0
exists $opts->{'level'} ? : 0 0 0
968 };
969 0 ▶ $info->{type} = $opts->{type} if( $opts->{type} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"type"} 0 0 0
970  
971 ## If Mod perl is activated AND we are not using a private log
972 0 ▶ if( $r && !${ "${class}::LOG_DEBUG" } )
Branch: 4 branches
BranchTrueFalseTotal
if ($r and not ${"${class}::LOG_DEBUG";}) { } 0 0 0
elsif ($HTTP::Promise::Headers::MOD_PERL and not ${"${class}::LOG_DEBUG";}) { } 0 0 0
elsif (not -t STDIN and $self->{'_log_handler'} and ref $self->{'_log_handler'} eq 'CODE') { } 0 0 0
elsif (not -t STDIN and ${$class . '::MESSAGE_HANDLER';} and ref ${$class . '::MESSAGE_HANDLER';} eq 'CODE') { } 0 0 0
Condition0%0/3
$r and not ${"${class}::LOG_DEBUG";}
!ll&&!rl&&r
000
MC/DC0%0/2
$r and not ${"${class}::LOG_DEBUG";}
$r not ${"${class}::LOG_DEBUG";}
Truth table0%0/3
A and not(B)
A= $rB= not ${"${class}::LOG_DEBUG";}
ABresult
0X0
100
111
973 {
974 0 ▶ if( my $log_handler = $r->get_handlers( 'PerlPrivateLogHandler' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (my $log_handler = $r->get_handlers('PerlPrivateLogHandler')) { } 0 0 0
elsif ($self->{'_log_handler'} and ref $self->{'_log_handler'} eq 'CODE') { } 0 0 0
975 {
976 0 $log_handler->( $mesg_raw );
977 }
978 ▶ elsif( $self->{_log_handler} && ref( $self->{_log_handler} ) eq 'CODE' )
Condition0%0/3
$self->{"_log_handler"} and ref $self->{"_log_handler"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_log_handler"} and ref $self->{"_log_handler"} eq "CODE"
$self->{"_log_handler"} ref $self->{"_log_handler"} eq "CODE"
Truth table0%0/3
A and B
A= $self->{"_log_handler"}B= ref $self->{"_log_handler"} eq "CODE"
ABresult
0X0
100
111
979 {
980 0 $self->{_log_handler}->( $info );
981 }
982 else
983 {
984 0 $r->log->debug( $mesg_raw );
985 }
986 }
987 # Using ModPerl Server to log
988 0 ▶ elsif( $MOD_PERL && !${ "${class}::LOG_DEBUG" } )
Condition0%0/3
$HTTP::Promise::Headers::MOD_PERL and not ${"${class}::LOG_DEBUG";}
!ll&&!rl&&r
000
MC/DC0%0/2
$HTTP::Promise::Headers::MOD_PERL and not ${"${class}::LOG_DEBUG";}
$HTTP::Promise::Headers::MOD_PERL not ${"${class}::LOG_DEBUG";}
Truth table0%0/3
A and not(B)
A= $HTTP::Promise::Headers::MOD_PERLB= not ${"${class}::LOG_DEBUG";}
ABresult
0X0
100
111
989 {
990 0 require Apache2::ServerUtil;
991 0 my $s = Apache2::ServerUtil->server;
992 0 $s->log->debug( $mesg );
993 }
994 # e.g. in our package, we could set the handler using the curry module like $self->{_log_handler} = $self->curry::log
995 ▶ elsif( !-t( STDIN ) && $self->{_log_handler} && ref( $self->{_log_handler} ) eq 'CODE' )
Condition0%0/6
not -t STDIN and $self->{"_log_handler"} and ref $self->{"_log_handler"} eq "CODE"
!ll&&!rl&&r
000
not -t STDIN and $self->{"_log_handler"}
!ll&&!rl&&r
000
MC/DC0%0/3
not -t STDIN and $self->{"_log_handler"} and ref $self->{"_log_handler"} eq "CODE"
not -t STDIN $self->{"_log_handler"} ref $self->{"_log_handler"} eq "CODE"
Truth table0%0/4
not(A) and B and C
A= not -t STDINB= $self->{"_log_handler"}C= ref $self->{"_log_handler"} eq "CODE"
ABCresult
0XX0
10X0
1100
1111
996 {
997 0 $self->{_log_handler}->( $info );
998 }
999 0 ▶ elsif( !-t( STDIN ) && ${ $class . '::MESSAGE_HANDLER' } && ref( ${ $class . '::MESSAGE_HANDLER' } ) eq 'CODE' )
Condition0%0/6
not -t STDIN and ${$class . '::MESSAGE_HANDLER';} and ref ${$class . '::MESSAGE_HANDLER';} eq "CODE"
!ll&&!rl&&r
000
not -t STDIN and ${$class . '::MESSAGE_HANDLER';}
!ll&&!rl&&r
000
MC/DC0%0/3
not -t STDIN and ${$class . '::MESSAGE_HANDLER';} and ref ${$class . '::MESSAGE_HANDLER';} eq "CODE"
not -t STDIN ${$class . '::MESSAGE_HANDLER';} ref ${$class . '::MESSAGE_HANDLER';} eq "CODE"
Truth table0%0/4
not(A) and B and C
A= not -t STDINB= ${$class . '::MESSAGE_HANDLER';}C= ref ${$class . '::MESSAGE_HANDLER';} eq "CODE"
ABCresult
0XX0
10X0
1100
1111
1000 {
1001 0 my $h = ${ $class . '::MESSAGE_HANDLER' };
1002 0 $h->( $info );
1003 }
1004 # Otherwise just on the stderr
1005 else
1006 {
1007 0 ▶ if( $opts->{no_encoding} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'no_encoding'}) { } 0 0 0
1008 {
1009 0 $stderr_raw->print( $mesg, "\n" );
1010 }
1011 else
1012 {
1013 0 $stderr->print( $mesg, "\n" );
1014 }
1015 }
1016 }
1017 0 return(1);
1018 }
1019  
1020 sub message_check
1021 {
1022 0 ▶ my $self = shift( @_ );
Subroutine message_check: not called CC=27 SCAR=64.5
Pod undocumented
1023 0 ▶ my $class = ref( $self ) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
1024 13 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1025 13 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1026 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1027 {
1028 0 ▶ if( $_[0] !~ /^\d/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($_[0] =~ /^\d/) 0 0 0
1029 {
1030 # The last parameter is an options parameter which has the level property set
1031 0 ▶ if( ref( $_[-1] ) eq 'HASH' && CORE::exists( $_[-1]->{level} ) )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[-1] eq 'HASH' and exists $_[-1]{'level'}) { } 0 0 0
elsif ($self->{'_message_default_level'} =~ /^\d+$/ and $self->{'_message_default_level'} > 0) { } 0 0 0
Condition0%0/3
ref $_[-1] eq "HASH" and exists $_[-1]{"level"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[-1] eq "HASH" and exists $_[-1]{"level"}
ref $_[-1] eq "HASH" exists $_[-1]{"level"}
Truth table0%0/3
A and B
A= ref $_[-1] eq "HASH"B= exists $_[-1]{"level"}
ABresult
0X0
100
111
1032 {
1033 # Then let's use this
1034 }
1035 ▶ elsif( $self->{_message_default_level} =~ /^\d+$/ &&
Condition0%0/3
$self->{"_message_default_level"} =~ /^\d+$/ and $self->{"_message_default_level"} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_message_default_level"} =~ /^\d+$/ and $self->{"_message_default_level"} > 0
$self->{"_message_default_level"} =~ /^\d+$/ $self->{"_message_default_level"} > 0
Truth table0%0/3
A and B
A= $self->{"_message_default_level"} =~ /^\d+$/B= $self->{"_message_default_level"} > 0
ABresult
0X0
100
111
1036 $self->{_message_default_level} > 0 )
1037 {
1038 0 unshift( @_, $self->{_message_default_level} );
1039 }
1040 else
1041 {
1042 0 unshift( @_, 1 );
1043 }
1044 }
1045 # If the first argument looks line a number, and there is more than 1 argument
1046 # and it is greater than 1, and greater than our current debug level
1047 # well, we do not output anything then...
1048 0 ▶ if( ( $_[0] =~ /^\d+$/ ||
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^\d+$/ || ref $_[-1] eq "HASH" && exists $_[-1]{"level"} && $_[-1]{"level"} =~ /^\d+$/ and @_ > 1) 0 0 0
Condition0%0/12
$_[0] =~ /^\d+$/ || ref $_[-1] eq "HASH" && exists $_[-1]{"level"} && $_[-1]{"level"} =~ /^\d+$/ and @_ > 1
!ll&&!rl&&r
000
$_[0] =~ /^\d+$/ or ref $_[-1] eq "HASH" and exists $_[-1]{"level"} and $_[-1]{"level"} =~ /^\d+$/
l!l&&r!l&&!r
000
ref $_[-1] eq "HASH" and exists $_[-1]{"level"} and $_[-1]{"level"} =~ /^\d+$/
!ll&&!rl&&r
000
ref $_[-1] eq "HASH" and exists $_[-1]{"level"}
!ll&&!rl&&r
000
MC/DC0%0/5
$_[0] =~ /^\d+$/ || ref $_[-1] eq "HASH" && exists $_[-1]{"level"} && $_[-1]{"level"} =~ /^\d+$/ and @_ > 1
$_[0] =~ /^\d+$/ ref $_[-1] eq "HASH" exists $_[-1]{"level"} $_[-1]{"level"} =~ /^\d+$/ @_ > 1
Truth table0%0/7
A or B and C and D and E
A= $_[0] =~ /^\d+$/B= ref $_[-1] eq "HASH"C= exists $_[-1]{"level"}D= $_[-1]{"level"} =~ /^\d+$/E= @_ > 1
ABCDEresult
00XXX0
010XX0
0110X0
1XXX00
011100
1XXX11
011111
1049 ( ref( $_[-1] ) eq 'HASH' &&
1050 CORE::exists( $_[-1]->{level} ) &&
1051 $_[-1]->{level} =~ /^\d+$/
1052 )
1053 ) && @_ > 1 )
1054 {
1055 0 my $message_level = 0;
1056 0 ▶ if( $_[0] =~ /^\d+$/ )
Branch: 2 branches
BranchTrueFalseTotal
if ($_[0] =~ /^\d+$/) { } 0 0 0
elsif (ref $_[-1] eq 'HASH' and exists $_[-1]{'level'}) { } 0 0 0
1057 {
1058 0 $message_level = shift( @_ );
1059 }
1060 ▶ elsif( ref( $_[-1] ) eq 'HASH' && CORE::exists( $_[-1]->{level} ) )
Condition0%0/3
ref $_[-1] eq "HASH" and exists $_[-1]{"level"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[-1] eq "HASH" and exists $_[-1]{"level"}
ref $_[-1] eq "HASH" exists $_[-1]{"level"}
Truth table0%0/3
A and B
A= ref $_[-1] eq "HASH"B= exists $_[-1]{"level"}
ABresult
0X0
100
111
1061 {
1062 0 $message_level = $_[-1]->{level};
1063 }
1064 0 my $target_re = '';
1065 0 ▶ if( ref( ${ "${class}::DEBUG_TARGET" } ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref ${"${class}::DEBUG_TARGET";} eq "ARRAY") 0 0 0
1066 {
1067 0 ▶ $target_re = scalar( @${ "${class}::DEBUG_TARGET" } ) ? join( '|', @${ "${class}::DEBUG_TARGET" } ) : '';
Branch: 1 branch
BranchTrueFalseTotal
scalar @${"${class}::DEBUG_TARGET";} ? : 0 0 0
1068 }
1069 0 ▶ if( int( $self->{debug} ) >= $message_level ||
Branch: 1 branch
BranchTrueFalseTotal
if (int $self->{'debug'} >= $message_level or int $self->{'verbose'} >= $message_level or defined ${$class . '::DEBUG';} and ${$class . '::DEBUG';} >= $message_level or int $self->{'debug_level'} >= $message_level or int $self->{'debug'} >= 100 or length $target_re and $class =~ /^$target_re$/ and ${$class . '::GLOBAL_DEBUG';} >= $message_level) { } 0 0 0
Condition0%0/18
int $self->{"debug"} >= $message_level or int $self->{"verbose"} >= $message_level or defined ${$class . '::DEBUG';} and ${$class . '::DEBUG';} >= $message_level or int $self->{"debug_level"} >= $message_level or int $self->{"debug"} >= 100 or length $target_re and $class =~ /^$target_re$/ and ${$class . '::GLOBAL_DEBUG';} >= $message_level
l!l&&r!l&&!r
000
int $self->{"debug"} >= $message_level or int $self->{"verbose"} >= $message_level or defined ${$class . '::DEBUG';} and ${$class . '::DEBUG';} >= $message_level or int $self->{"debug_level"} >= $message_level or int $self->{"debug"} >= 100
l!l&&r!l&&!r
000
int $self->{"debug"} >= $message_level or int $self->{"verbose"} >= $message_level or defined ${$class . '::DEBUG';} and ${$class . '::DEBUG';} >= $message_level or int $self->{"debug_level"} >= $message_level
l!l&&r!l&&!r
000
int $self->{"debug"} >= $message_level or int $self->{"verbose"} >= $message_level or defined ${$class . '::DEBUG';} and ${$class . '::DEBUG';} >= $message_level
l!l&&r!l&&!r
000
int $self->{"debug"} >= $message_level or int $self->{"verbose"} >= $message_level
l!l&&r!l&&!r
000
defined ${$class . '::DEBUG';} and ${$class . '::DEBUG';} >= $message_level
!ll&&!rl&&r
000
MC/DC0%0/7
int $self->{"debug"} >= $message_level or int $self->{"verbose"} >= $message_level or defined ${$class . '::DEBUG';} and ${$class . '::DEBUG';} >= $message_level or int $self->{"debug_level"} >= $message_level or int $self->{"debug"} >= 100 or length $target_re and $class =~ /^$target_re$/ and ${$class . '::GLOBAL_DEBUG';} >= $message_level
int $self->{"debug"} >= $message_level int $self->{"verbose"} >= $message_level defined ${$class . '::DEBUG';} ${$class . '::DEBUG';} >= $message_level int $self->{"debug_level"} >= $message_level int $self->{"debug"} >= 100 length $target_re and $class =~ /^$target_re$/ and ${$class . '::GLOBAL_DEBUG';} >= $message_level
Truth table0%0/11
A or B or C and D or E or F or G
A= int $self->{"debug"} >= $message_levelB= int $self->{"verbose"} >= $message_levelC= defined ${$class . '::DEBUG';}D= ${$class . '::DEBUG';} >= $message_levelE= int $self->{"debug_level"} >= $message_levelF= int $self->{"debug"} >= 100G= length $target_re and $class =~ /^$target_re$/ and ${$class . '::GLOBAL_DEBUG';} >= $message_level
ABCDEFGresult
1XXXXXX1
01XXXXX1
0011XXX1
000X1XX1
00101XX1
000X01X1
001001X1
000X0011
00100011
000X0000
00100000
1070 int( $self->{verbose} ) >= $message_level ||
1071 0 ▶ ( defined( ${ $class . '::DEBUG' } ) && ${ $class . '::DEBUG' } >= $message_level ) ||
Condition0%0/6
length $target_re and $class =~ /^$target_re$/ and ${$class . '::GLOBAL_DEBUG';} >= $message_level
!ll&&!rl&&r
000
length $target_re and $class =~ /^$target_re$/
!ll&&!rl&&r
000
MC/DC0%0/3
length $target_re and $class =~ /^$target_re$/ and ${$class . '::GLOBAL_DEBUG';} >= $message_level
length $target_re $class =~ /^$target_re$/ ${$class . '::GLOBAL_DEBUG';} >= $message_level
Truth table0%0/4
A and B and C
A= length $target_reB= $class =~ /^$target_re$/C= ${$class . '::GLOBAL_DEBUG';} >= $message_level
ABCresult
0XX0
10X0
1100
1111
1072 int( $self->{debug_level} ) >= $message_level ||
1073 int( $self->{debug} ) >= 100 ||
1074 0 ( length( $target_re ) && $class =~ /^$target_re$/ && ${ $class . '::GLOBAL_DEBUG' } >= $message_level ) )
1075 {
1076 0 return( [ @_ ] );
1077 }
1078 else
1079 {
1080 0 return(0);
1081 }
1082 }
1083 }
1084 0 return(0);
1085 }
1086  
1087 sub message_frame
1088 {
1089 0 ▶ my $self = shift( @_ );
Subroutine message_frame: not called CC=7 SCAR=40.3
Pod undocumented
1090 0 ▶ $self->{_message_frame } = {} if( !exists( $self->{_message_frame} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_message_frame"} 0 0 0
1091 0 my $mf = $self->{_message_frame};
1092 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1093 {
1094 0 my $args = {};
1095 0 ▶ if( ref( $_[0] ) eq 'HASH' )
Branch: 3 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 0 0
elsif (not @_ % 2) { } 0 0 0
elsif (scalar @_ == 1) { } 0 0 0
1096 {
1097 0 $args = shift( @_ );
1098 0 my @k = keys( %$args );
1099 0 @$mf{ @k } = @$args{ @k };
1100 }
1101 elsif( !( @_ % 2 ) )
1102 {
1103 0 $args = { @_ };
1104 0 my @k = keys( %$args );
1105 0 @$mf{ @k } = @$args{ @k };
1106 }
1107 elsif( scalar( @_ ) == 1 )
1108 {
1109 0 my $sub = shift( @_ );
1110 0 ▶ $sub = substr( $sub, rindex( $sub, '::' ) + 2 ) if( index( $sub, '::' ) != -1 );
Branch: 1 branch
BranchTrueFalseTotal
if (index($sub, "::") != -1) 0 0 0
1111 0 return( $mf->{ $sub } );
1112 }
1113 else
1114 {
1115 0 return( $self->error( "I was expecting a key => value pair such as routine => stack frame (integer)" ) );
1116 }
1117 }
1118 0 return( $mf );
1119 }
1120  
1121 # For compatibility for MIME::Decoder->head, itself used by HTTP::Promise::Entity
1122 # "some decoders need to know a little about the file they are encoding/decoding; e.g., x-uu likes to have the filename. The HEAD is any object which responds to messages like:
1123 # $head->mime_attr( 'content-disposition.filename' );
1124 sub mime_attr
1125 {
1126 10 ▶ my $self = shift( @_ );
Subroutine mime_attr: called CC=13 SCAR=36.5
Pod documented
1127 10 my( $attr, $value ) = @_;
1128 10 ▶ return if( !defined( $attr ) || !length( $attr ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attr and length $attr 0 10 10
Condition33%1/3
defined $attr and length $attr
!ll&&!rl&&r
0010
MC/DC0%0/2
defined $attr and length $attr
defined $attr length $attr
Truth table33%1/3
A and B
A= defined $attrB= length $attr
ABresult
0X0
100
111
1129 # Break attribute name up
1130 10 my( $tag, $subtag ) = split( /\./, $attr, 2 );
1131 10 my $v = $self->header( $tag );
1132 10 require Module::Generic::HeaderValue;
1133 10 my $hv;
1134 10 ▶ if( defined( $v ) && length( $v ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v and length $v) 10 0 10
Condition33%1/3
defined $v and length $v
!ll&&!rl&&r
0010
MC/DC0%0/2
defined $v and length $v
defined $v length $v
Truth table33%1/3
A and B
A= defined $vB= length $v
ABresult
0X0
100
111
1135 {
1136 10 $hv = Module::Generic::HeaderValue->new_from_header( $v );
1137 10 ▶ return( $self->pass_error( Module::Generic::HeaderValue->error ) ) if( !defined( $hv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hv 0 10 10
1138 }
1139 10 ▶ if( scalar( @_ ) > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 1) { } 0 10 10
1140 {
1141 0 ▶ if( defined( $subtag ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $subtag) { } 0 0 0
1142 {
1143 0 ▶ return( $self->error( "There is no header field '$tag' currently set, so you cannot assign a value for '$subtag'." ) ) if( !defined( $hv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hv 0 0 0
1144 0 $hv->param( $subtag => $value );
1145 }
1146 else
1147 {
1148 0 ▶ if( defined( $hv ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hv) { } 0 0 0
1149 {
1150 0 $hv->value( $value );
1151 }
1152 else
1153 {
1154 0 ▶ $hv = Module::Generic::HeaderValue->new( $value ) ||
Condition0%0/2
'Module::Generic::HeaderValue'->new($value) || (return $self->pass_error('Module::Generic::HeaderValue'->error))
l!l
00
MC/DC0%0/1
'Module::Generic::HeaderValue'->new($value) || (return $self->pass_error('Module::Generic::HeaderValue'->error))
'Module::Generic::HeaderValue'->new($value)
Truth table0%0/2
A
A= 'Module::Generic::HeaderValue'->new($value)
Aresult
11
00
1155 return( $self->pass_error( Module::Generic::HeaderValue->error ) );
1156 }
1157 }
1158 0 $self->replace( $tag => "$hv" );
1159 0 return( $value );
1160 }
1161 else
1162 {
1163 10 ▶ return( '' ) if( !defined( $hv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hv 0 10 10
1164 10 ▶ return( defined( $subtag ) ? $hv->param( $subtag ) : $hv->value_data );
Branch: 1 branch
BranchTrueFalseTotal
defined $subtag ? : 8 2 10
1165 }
1166 }
1167  
1168 # In HTTP parlance, the request may contain a Content-Encoding in multipart/form-data,
1169 # and the server response may contain Transfer-Encoding to indicate in which encoding the
1170 # response is provided.
1171 sub mime_encoding
1172 {
1173 0 ▶ my $self = shift( @_ );
Subroutine mime_encoding: not called CC=4 SCAR=30.0
Pod documented
1174 0 ▶ my $te = $self->header( 'Content-Encoding' ) || $self->header( 'Transfer-Encoding' );
Condition0%0/3
$self->header('Content-Encoding') || $self->header('Transfer-Encoding')
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->header('Content-Encoding') || $self->header('Transfer-Encoding')
$self->header('Content-Encoding') $self->header('Transfer-Encoding')
Truth table0%0/3
A || B
A= $self->header('Content-Encoding')B= $self->header('Transfer-Encoding')
ABresult
1X1
011
000
1175 0 ▶ return( '' ) if( !defined( $te ) || !length( $te ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $te and length $te 0 0 0
Condition0%0/3
defined $te and length $te
!ll&&!rl&&r
000
MC/DC0%0/2
defined $te and length $te
defined $te length $te
Truth table0%0/3
A and B
A= defined $teB= length $te
ABresult
0X0
100
111
1176 0 my $enc = lc( $te );
1177 # 7-bit, 7_bit -> 7bit. Same for 8-bit, 8_bit
1178 0 $enc =~ s{^([78])[ _-]bit\Z}{$1bit};
1179 0 return( $enc );
1180 }
1181  
1182 sub mime_type
1183 {
1184 51 ▶ my $self = shift( @_ );
Subroutine mime_type: called CC=5 SCAR=16.2
Pod documented
1185 51 ▶ my $default = shift( @_ ) || $self->default_type;
Condition66%2/3
shift @_ || $self->default_type
l!l&&r!l&&!r
11040
MC/DC50%1/2
shift @_ || $self->default_type
shift @_ $self->default_type
Truth table66%2/3
A || B
A= shift @_B= $self->default_type
ABresult
1X1
011
000
1186 51 my $ct = $self->type;
1187 51 ▶ if( !defined( $ct ) || !length( $ct ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ct and length $ct) 16 35 51
Condition66%2/3
defined $ct and length $ct
!ll&&!rl&&r
16035
MC/DC50%1/2
defined $ct and length $ct
defined $ct length $ct
Truth table66%2/3
A and B
A= defined $ctB= length $ct
ABresult
0X0
100
111
1188 {
1189 16 ▶ return( $default ) if( defined( $default ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $default 3 13 16
1190 13 return( '' );
1191 }
1192 35 return( $ct );
1193 }
1194  
1195 sub multipart_boundary
1196 {
1197 5 ▶ my $self = shift( @_ );
Subroutine multipart_boundary: called CC=6 SCAR=20.2
Pod documented
1198 5 my $ct = $self->content_type;
1199 5 ▶ return( '' ) unless( defined( $ct ) && length( "$ct" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ct and length "$ct" 0 5 5
Condition33%1/3
defined $ct and length "$ct"
!ll&&!rl&&r
005
MC/DC0%0/2
defined $ct and length "$ct"
defined $ct length "$ct"
Truth table33%1/3
A and B
A= defined $ctB= length "$ct"
ABresult
0X0
100
111
1200 # There is no attributes to this Content-Type, so no need to go further.
1201 5 ▶ return( '' ) if( index( $ct, ';' ) == -1 || index( $ct, 'boundary' ) == -1 );
Branch: 1 branch
BranchTrueFalseTotal
if index($ct, ";") == -1 or index($ct, "boundary") == -1 0 5 5
Condition33%1/3
index($ct, ";") == -1 or index($ct, "boundary") == -1
l!l&&r!l&&!r
005
MC/DC0%0/2
index($ct, ";") == -1 or index($ct, "boundary") == -1
index($ct, ";") == -1 index($ct, "boundary") == -1
Truth table33%1/3
A or B
A= index($ct, ";") == -1B= index($ct, "boundary") == -1
ABresult
1X1
011
000
1202 5 require Module::Generic::HeaderValue;
1203 5 ▶ my $hv = Module::Generic::HeaderValue->new_from_header( $ct ) ||
Condition50%1/2
'Module::Generic::HeaderValue'->new_from_header($ct) || (return $self->pass_error('Module::Generic::HeaderValue'->error))
l!l
50
MC/DC0%0/1
'Module::Generic::HeaderValue'->new_from_header($ct) || (return $self->pass_error('Module::Generic::HeaderValue'->error))
'Module::Generic::HeaderValue'->new_from_header($ct)
Truth table50%1/2
A
A= 'Module::Generic::HeaderValue'->new_from_header($ct)
Aresult
11
00
1204 return( $self->pass_error( Module::Generic::HeaderValue->error ) );
1205 5 my $boundary = $hv->param( 'boundary' );
1206 5 return( $boundary );
1207 }
1208  
1209 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/NEL>
1210 0 ▶sub nel { return( shift->_set_get_one( 'NEL', @_ ) ); }
Subroutine nel: not called CC=1 SCAR=6.9
Pod documented
1211  
1212 sub new_array
1213 {
1214 22 ▶ my $self = shift( @_ );
Subroutine new_array: called CC=1 SCAR=0.0
Pod undocumented
1215 22 require Module::Generic::Array;
1216 22 return( Module::Generic::Array->new( @_ ) );
1217 }
1218  
1219 sub new_field
1220 {
1221 74 ▶ my $self = shift( @_ );
Subroutine new_field: called CC=12 SCAR=37.5
Pod undocumented
1222 74 my $field = shift( @_ );
1223 74 ▶ 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 74 74
Condition33%1/3
defined $field and length "$field"
!ll&&!rl&&r
0074
MC/DC0%0/2
defined $field and length "$field"
defined $field length "$field"
Truth table33%1/3
A and B
A= defined $fieldB= length "$field"
ABresult
0X0
100
111
1224 74 ▶ unless( scalar( keys( %$SUPPORTED ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar keys %$HTTP::Promise::Headers::SUPPORTED) 0 74 74
1225 {
1226 0 ▶ $self->_load_class( 'Module::Generic::File' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::File") or return $self->pass_error 0 0 0
1227 0 ▶ my $dir = Module::Generic::File->new( ( $MOD_PATH || __FILE__ ) )->extension( undef );
Condition0%0/2
$HTTP::Promise::Headers::MOD_PATH || __FILE__
l!l
00
MC/DC0%0/1
$HTTP::Promise::Headers::MOD_PATH || __FILE__
$HTTP::Promise::Headers::MOD_PATH
Truth table0%0/2
A
A= $HTTP::Promise::Headers::MOD_PATH
Aresult
11
00
1228 0 ▶ $dir->open || return( $self->error( "Unable to open directory \"$dir\": ", $dir->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$dir->open or return $self->error(qq[Unable to open directory "$dir": ], $dir->error) 0 0 0
1229 0 my $f;
1230 0 ▶ while( defined( $f = $dir->read( exclude_invisible => 1, as_object => 1 ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($f = $dir->read("exclude_invisible", 1, "as_object", 1))) 0 0 0
1231 {
1232 0 ▶ next if( $f->extension ne 'pm' );
Branch: 1 branch
BranchTrueFalseTotal
if $f->extension ne "pm" 0 0 0
1233 0 my $base = $f->basename( '.pm' );
1234 0 $SUPPORTED->{ lc( $base ) } = "HTTP\::Promise\::Headers\::${base}";
1235 }
1236 }
1237 74 ( my $name = $field ) =~ s/[\-_]+//g;
1238 74 $name = lc( $name );
1239 74 ▶ return( $self->error( "Unsupported field \"$field\"." ) ) if( !exists( $SUPPORTED->{ $name } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $HTTP::Promise::Headers::SUPPORTED->{$name} 0 74 74
1240 74 my $class = $SUPPORTED->{ $name };
1241 74 ▶ $self->_load_class( $class ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($class) or return $self->pass_error 0 74 74
1242 74 ▶ my $o = $class->new( @_ ) ||
Condition50%1/2
$class->new(@_) || (return $self->pass_error($class->error))
l!l
740
MC/DC0%0/1
$class->new(@_) || (return $self->pass_error($class->error))
$class->new(@_)
Truth table50%1/2
A
A= $class->new(@_)
Aresult
11
00
1243 return( $self->pass_error( $class->error ) );
1244 74 return( $o );
1245 }
1246  
1247 sub new_number
1248 {
1249 1 ▶ my $self = shift( @_ );
Subroutine new_number: called CC=1 SCAR=0.0
Pod undocumented
1250 1 require Module::Generic::Number;
1251 1 return( Module::Generic::Number->new( @_ ) );
1252 }
1253  
1254 sub new_scalar
1255 {
1256 188 ▶ my $self = shift( @_ );
Subroutine new_scalar: called CC=1 SCAR=0.0
Pod undocumented
1257 188 require Module::Generic::Scalar;
1258 188 return( Module::Generic::Scalar->new( @_ ) );
1259 }
1260  
1261 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin>
1262 0 ▶sub origin { return( shift->_set_get_one_uri( 'Origin', @_ ) ); }
Subroutine origin: not called CC=1 SCAR=6.9
Pod documented
1263  
1264 # Purpose is to get an error object thrown from, possibly another package,
1265 # and make it ours and pass it along
1266 # e.g.:
1267 # $self->pass_error
1268 # $self->pass_error( 'Some error that will be passed to error()' );
1269 # $self->pass_error( $error_object );
1270 # $self->pass_error( $error_object, { class => 'Some::ExceptionClass', code => 400 } );
1271 # $self->pass_error({ class => 'Some::ExceptionClass' });
1272 sub pass_error
1273 {
1274 0 ▶ my $self = shift( @_ );
Subroutine pass_error: not called CC=41 SCAR=73.9
Pod undocumented
1275 0 ▶ my $class = ref( $self ) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
1276 0 my $opts = {};
1277 0 my $err;
1278 my $ex_class;
1279 0 my $code;
1280 0 my $callback;
1281 13 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1282 0 ▶ my $err_key = HAS_THREADS() ? join( ';', $class, $$, threads->tid ) : join( ';', $class, $$ );
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 0 0 0
1283 0 my $repo = Module::Generic::Global->new( 'errors' => $class, key => $err_key );
1284  
1285 0 ▶ if( scalar( @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 0 0 0
1286 {
1287 # Either an hash defining a new error and this will be passed along to error(); or
1288 # an hash with a single property: { class => 'Some::ExceptionClass' }
1289 0 ▶ if( scalar( @_ ) == 1 && ref( $_[0] ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1 and ref $_[0] eq 'HASH') { } 0 0 0
Condition0%0/3
scalar @_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and ref $_[0] eq "HASH"
scalar @_ == 1 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= scalar @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
1290 {
1291 0 $opts = $_[0];
1292 }
1293 else
1294 {
1295 # $self->pass_error( $error_object, { class => 'Some::ExceptionClass' } );
1296 0 ▶ if( scalar( @_ ) > 1 && ref( $_[-1] ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 1 and ref $_[-1] eq "HASH") 0 0 0
Condition0%0/3
scalar @_ > 1 and ref $_[-1] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ > 1 and ref $_[-1] eq "HASH"
scalar @_ > 1 ref $_[-1] eq "HASH"
Truth table0%0/3
A and B
A= scalar @_ > 1B= ref $_[-1] eq "HASH"
ABresult
0X0
100
111
1297 {
1298 0 $opts = pop( @_ );
1299 }
1300 0 $err = $_[0];
1301 }
1302 }
1303 0 ▶ $err = $opts->{error} if( !defined( $err ) && CORE::exists( $opts->{error} ) && defined( $opts->{error} ) && CORE::length( $opts->{error} ) );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $err and exists $opts->{"error"} and defined $opts->{"error"} and length $opts->{"error"} 0 0 0
Condition0%0/9
not defined $err and exists $opts->{"error"} and defined $opts->{"error"} and length $opts->{"error"}
!ll&&!rl&&r
000
not defined $err and exists $opts->{"error"} and defined $opts->{"error"}
!ll&&!rl&&r
000
not defined $err and exists $opts->{"error"}
!ll&&!rl&&r
000
MC/DC0%0/4
not defined $err and exists $opts->{"error"} and defined $opts->{"error"} and length $opts->{"error"}
not defined $err exists $opts->{"error"} defined $opts->{"error"} length $opts->{"error"}
Truth table0%0/5
not(A) and B and C and D
A= not defined $errB= exists $opts->{"error"}C= defined $opts->{"error"}D= length $opts->{"error"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1304 # We set $ex_class only if the hash provided is a one-element hash and not an error-defining hash
1305 # $class = CORE::delete( $opts->{class} ) if( scalar( keys( %$opts ) ) == 1 && [keys( %$opts )]->[0] eq 'class' );
1306 0 ▶ $ex_class = $opts->{class} if( CORE::exists( $opts->{class} ) && defined( $opts->{class} ) && CORE::length( $opts->{class} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"class"} and defined $opts->{"class"} and length $opts->{"class"} 0 0 0
Condition0%0/6
exists $opts->{"class"} and defined $opts->{"class"} and length $opts->{"class"}
!ll&&!rl&&r
000
exists $opts->{"class"} and defined $opts->{"class"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $opts->{"class"} and defined $opts->{"class"} and length $opts->{"class"}
exists $opts->{"class"} defined $opts->{"class"} length $opts->{"class"}
Truth table0%0/4
A and B and C
A= exists $opts->{"class"}B= defined $opts->{"class"}C= length $opts->{"class"}
ABCresult
0XX0
10X0
1100
1111
1307 0 ▶ $code = $opts->{code} if( CORE::exists( $opts->{code} ) && defined( $opts->{code} ) && CORE::length( $opts->{code} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"code"} and defined $opts->{"code"} and length $opts->{"code"} 0 0 0
Condition0%0/6
exists $opts->{"code"} and defined $opts->{"code"} and length $opts->{"code"}
!ll&&!rl&&r
000
exists $opts->{"code"} and defined $opts->{"code"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $opts->{"code"} and defined $opts->{"code"} and length $opts->{"code"}
exists $opts->{"code"} defined $opts->{"code"} length $opts->{"code"}
Truth table0%0/4
A and B and C
A= exists $opts->{"code"}B= defined $opts->{"code"}C= length $opts->{"code"}
ABCresult
0XX0
10X0
1100
1111
1308 0 ▶ $callback = $opts->{callback} if( CORE::exists( $opts->{callback} ) && defined( $opts->{callback} ) && ref( $opts->{callback} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"callback"} and defined $opts->{"callback"} and ref $opts->{"callback"} 0 0 0
Condition0%0/6
exists $opts->{"callback"} and defined $opts->{"callback"} and ref $opts->{"callback"}
!ll&&!rl&&r
000
exists $opts->{"callback"} and defined $opts->{"callback"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $opts->{"callback"} and defined $opts->{"callback"} and ref $opts->{"callback"}
exists $opts->{"callback"} defined $opts->{"callback"} ref $opts->{"callback"}
Truth table0%0/4
A and B and C
A= exists $opts->{"callback"}B= defined $opts->{"callback"}C= ref $opts->{"callback"}
ABCresult
0XX0
10X0
1100
1111
1309  
1310 # called with no argument, most likely from the same class to pass on an error
1311 # set up earlier by another method; or
1312 # with an hash containing just one argument class => 'Some::ExceptionClass'
1313 0 ▶ if( !defined( $err ) && ( !scalar( @_ ) || defined( $ex_class ) ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $err and !scalar(@_) || defined $ex_class) { } 0 0 0
elsif (defined $err and builtin::blessed($err) and scalar @_ == 1 || scalar @_ == 2 && defined $ex_class) { } 0 0 0
Condition0%0/6
not defined $err and !scalar(@_) || defined $ex_class
!ll&&!rl&&r
000
not scalar @_ or defined $ex_class
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $err and !scalar(@_) || defined $ex_class
not defined $err not scalar @_ defined $ex_class
Truth table0%0/4
not(A) and not(B) or C
A= not defined $errB= not scalar @_C= defined $ex_class
ABCresult
0XX0
1000
11X1
1011
1314 {
1315 0 my $error;
1316 0 ▶ if( Scalar::Util::blessed( $self ) )
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($self)) { } 0 0 0
elsif ($repo->exists) { } 0 0 0
1317 {
1318 0 $error = $self->{error};
1319 }
1320 elsif( $repo->exists )
1321 {
1322 0 $error = $repo->get;
1323 }
1324  
1325 0 ▶ if( !defined( $error ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $error) { } 0 0 0
1326 {
1327 0 warn( "No error object provided and no previous error set either! It seems the previous method call returned a simple undef\n", $self->_get_stack_trace );
1328 }
1329 else
1330 {
1331 0 ▶ $err = ( defined( $ex_class ) ? bless( $error => $ex_class ) : $error );
Branch: 1 branch
BranchTrueFalseTotal
defined $ex_class ? : 0 0 0
1332 0 ▶ $err->code( $code ) if( defined( $code ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $code 0 0 0
1333 }
1334 }
1335 # An error object was provided
1336 ▶ elsif( defined( $err ) &&
Condition0%0/12
defined $err and builtin::blessed($err) and scalar @_ == 1 || scalar @_ == 2 && defined $ex_class
!ll&&!rl&&r
000
defined $err and builtin::blessed($err)
!ll&&!rl&&r
000
scalar @_ == 1 or scalar @_ == 2 and defined $ex_class
l!l&&r!l&&!r
000
scalar @_ == 2 and defined $ex_class
!ll&&!rl&&r
000
MC/DC0%0/5
defined $err and builtin::blessed($err) and scalar @_ == 1 || scalar @_ == 2 && defined $ex_class
defined $err builtin::blessed($err) scalar @_ == 1 scalar @_ == 2 defined $ex_class
Truth table0%0/6
A and B and C or D and E
A= defined $errB= builtin::blessed($err)C= scalar @_ == 1D= scalar @_ == 2E= defined $ex_class
ABCDEresult
0XXXX0
10XXX0
1100X0
110100
111XX1
110111
1337 Scalar::Util::blessed( $err ) &&
1338 ( scalar( @_ ) == 1 ||
1339 ( scalar( @_ ) == 2 && defined( $ex_class ) )
1340 ) )
1341 {
1342 # If necessary, we re-bless the error object to the designated class
1343 0 ▶ my $o = ( defined( $ex_class ) ? bless( $err => $ex_class ) : $err );
Branch: 1 branch
BranchTrueFalseTotal
defined $ex_class ? : 0 0 0
1344 0 $self->{error} = $o;
1345 # We ned to be backward compatible, and allow the user to access $My::Module::ERROR
1346 0 $repo->set( $o );
1347 0 ${ $class . '::ERROR' } = $o;
1348 0 ▶ $self->{error}->code( $code ) if( defined( $code ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $code 0 0 0
1349  
1350 0 ▶ if( $self->{fatal} || ( defined( ${"${class}\::FATAL_ERROR"} ) && ${"${class}\::FATAL_ERROR"} ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"fatal"} or defined ${"${class}::FATAL_ERROR";} and ${"${class}::FATAL_ERROR";}) 0 0 0
Condition0%0/6
$self->{"fatal"} or defined ${"${class}::FATAL_ERROR";} and ${"${class}::FATAL_ERROR";}
l!l&&r!l&&!r
000
defined ${"${class}::FATAL_ERROR";} and ${"${class}::FATAL_ERROR";}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"fatal"} or defined ${"${class}::FATAL_ERROR";} and ${"${class}::FATAL_ERROR";}
$self->{"fatal"} defined ${"${class}::FATAL_ERROR";} ${"${class}::FATAL_ERROR";}
Truth table0%0/4
A or B and C
A= $self->{"fatal"}B= defined ${"${class}::FATAL_ERROR";}C= ${"${class}::FATAL_ERROR";}
ABCresult
1XX1
0111
00X0
0100
1351 {
1352 0 die( $self->{error} );
1353 }
1354 }
1355 # If the error provided is not an object, we call error to create one
1356 else
1357 {
1358 0 return( $self->error( @_ ) );
1359 }
1360  
1361 0 ▶ if( want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (want("OBJECT")) 0 0 0
1362 {
1363 0 ▶ $self->_load_class( 'Module::Generic::Null' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Null") or die "Unable to load Module::Generic::Null" 0 0 0
1364 die( "Unable to load Module::Generic::Null" );
1365 0 my $null = Module::Generic::Null->new( $err, { debug => $self->{debug}, has_error => 1 });
1366 0 rreturn( $null );
1367 }
1368 0 return;
1369 }
1370  
1371 sub print
1372 {
1373 22 ▶ my $self = shift( @_ );
Subroutine print: called CC=5 SCAR=18.1
Pod documented
1374 22 my $fh = shift( @_ );
1375 22 my $opts = $self->_get_args_as_hash( @_ );
1376 22 ▶ my $eol = $opts->{eol} || CRLF;
Condition50%1/2
$opts->{'eol'} || "\r\n"
l!l
220
MC/DC0%0/1
$opts->{'eol'} || "\r\n"
$opts->{'eol'}
Truth table50%1/2
A
A= $opts->{'eol'}
Aresult
11
00
1377 22 ▶ $fh ||= select;
Condition33%1/3
$fh ||= select
l!l&&r!l&&!r
2200
MC/DC0%0/2
$fh ||= select
$fh select
Truth table33%1/3
A ||= B
A= $fhB= select
ABresult
1X1
011
000
1378 22 ▶ return( $self->error( "Filehandle provided ($fh) is not a proper filehandle and its not a HTTP::Promise::IO object." ) ) if( !$self->_is_glob( $fh ) && !$self->_is_a( $fh => 'HTTP::Promise::IO' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_glob($fh) or $self->_is_a($fh, "HTTP::Promise::IO") 0 22 22
Condition33%1/3
$self->_is_glob($fh) or $self->_is_a($fh, "HTTP::Promise::IO")
l!l&&r!l&&!r
0220
MC/DC0%0/2
$self->_is_glob($fh) or $self->_is_a($fh, "HTTP::Promise::IO")
$self->_is_glob($fh) $self->_is_a($fh, "HTTP::Promise::IO")
Truth table33%1/3
A or B
A= $self->_is_glob($fh)B= $self->_is_a($fh, "HTTP::Promise::IO")
ABresult
1X1
011
000
1379 22 return( $fh->print( $self->as_string( $eol ) ) );
1380 }
1381  
1382 0 ▶sub proxy { return( shift->_set_get_uri( 'proxy', @_ ) ); }
Subroutine proxy: not called CC=1 SCAR=6.9
Pod documented
1383  
1384 # NOTE: proxy_authenticate() is inherited
1385 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Proxy-Authenticate>
1386 0 ▶sub proxy_authenticate { return( shift->_set_get_one( 'Proxy-Authenticate', @_ ) ); }
Subroutine proxy_authenticate: not called CC=1 SCAR=6.9
Pod documented
1387  
1388 # NOTE: proxy_authorization() is inherited
1389 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Proxy-Authorization>
1390 0 ▶sub proxy_authorization { return( shift->_set_get_one( 'Proxy-Authorization', @_ ) ); }
Subroutine proxy_authorization: not called CC=1 SCAR=6.9
Pod documented
1391  
1392 # NOTE: proxy_authorization_basic() is inherited
1393  
1394 # NOTE: push_header() is inherited
1395  
1396 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range>
1397 0 ▶sub range { return( shift->_set_get_multi( 'Range', @_ ) ); }
Subroutine range: not called CC=1 SCAR=6.9
Pod documented
1398  
1399 sub recommended_filename
1400 {
1401 1 ▶ my $self = shift( @_ );
Subroutine recommended_filename: called CC=5 SCAR=16.6
Pod documented
1402 1 foreach my $attr_name ( qw( content-disposition.filename* content-disposition.filename content-type.name ) )
1403 {
1404 2 my $value = $self->mime_attr( $attr_name );
1405 2 ▶ if( defined( $value ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and $value ne "" and $value =~ /\S/) 1 1 2
Condition66%4/6
defined $value and $value ne "" and $value =~ /\S/
!ll&&!rl&&r
101
defined $value and $value ne ""
!ll&&!rl&&r
101
MC/DC33%1/3
defined $value and $value ne "" and $value =~ /\S/
defined $value $value ne "" $value =~ /\S/
Truth table50%2/4
A and B and C
A= defined $valueB= $value ne ""C= $value =~ /\S/
ABCresult
0XX0
10X0
1100
1111
1406 $value ne '' &&
1407 $value =~ /\S/ )
1408 {
1409 1 return( $self->decode_filename( $value ) );
1410 }
1411 }
1412 0 return;
1413 }
1414  
1415 # NOTE: referer() and referrer() are inherited
1416 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer>
1417 0 ▶sub referer { return( shift->_set_get_one_uri( 'Referer', @_ ) ); }
Subroutine referer: not called CC=1 SCAR=6.9
Pod documented
1418  
1419 0 ▶sub referrer { return( shift->referer( @_ ) ); }
Subroutine referrer: not called CC=1 SCAR=6.9
Pod documented
1420  
1421 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy>
1422 0 ▶sub referrer_policy { return( shift->_set_get_one( 'Referrer-Policy', @_ ) ); }
Subroutine referrer_policy: not called CC=1 SCAR=6.9
Pod documented
1423  
1424 8 ▶sub remove { return( shift->remove_header( @_ ) ); }
Subroutine remove: called CC=1 SCAR=0.0
Pod documented
1425  
1426 # NOTE: remove_header() is inherited
1427  
1428 # NOTE: remove_content_headers() is inherited
1429  
1430 sub replace
1431 {
1432 30 ▶ my $self = shift( @_ );
Subroutine replace: called CC=5 SCAR=18.3
Pod documented
1433 30 my( $field, $value ) = @_;
1434 30 ▶ unless( defined( $field ) && length( $field // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $field and length($field // "")) 0 30 30
Condition40%2/5
defined $field and length($field // "")
!ll&&!rl&&r
0030
$field // ""
l!l
300
MC/DC0%0/2
defined $field and length($field // "")
defined $field $field
Truth table33%1/3
A and B
A= defined $fieldB= $field
ABresult
0X0
100
111
1435 {
1436 0 return( $self->error( "No header name was provided." ) );
1437 }
1438 30 ( my $meth = $field ) =~ tr/-/_/;
1439 30 $meth = lc( $meth );
1440 30 ▶ if( my $ref = $self->can( $meth ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $ref = $self->can($meth)) { } 30 0 30
1441 {
1442 30 $ref->( $self, $value );
1443 }
1444 else
1445 {
1446 0 $self->header( $field => $value );
1447 }
1448 30 return( $self );
1449 }
1450  
1451 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Request-Headers>
1452 0 ▶sub request_headers { return( shift->_set_get_one( 'Access-Control-Request-Headers', @_ ) ); }
Subroutine request_headers: not called CC=1 SCAR=6.9
Pod documented
1453  
1454 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Request-Method>
1455 0 ▶sub request_method { return( shift->_set_get_one( 'Access-Control-Request-Method', @_ ) ); }
Subroutine request_method: not called CC=1 SCAR=6.9
Pod documented
1456  
1457 0 ▶sub request_timeout { return( shift->_set_get_number( 'request_timeout', @_ ) ); }
Subroutine request_timeout: not called CC=1 SCAR=6.9
Pod documented
1458  
1459 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After>
1460 0 ▶sub retry_after { return( shift->_set_get_one( 'Retry-After', @_ ) ); }
Subroutine retry_after: not called CC=1 SCAR=6.9
Pod documented
1461  
1462 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Save-Data>
1463 0 ▶sub save_data { return( shift->_set_get_one( 'Save-Data', @_ ) ); }
Subroutine save_data: not called CC=1 SCAR=6.9
Pod documented
1464  
1465 # NOTE: scan() is inherited
1466  
1467 # NOTE: server() is inherited
1468 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server>
1469 0 ▶sub server { return( shift->_set_get_one( 'Server', @_ ) ); }
Subroutine server: not called CC=1 SCAR=6.9
Pod documented
1470  
1471 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server-Timing>
1472 0 ▶sub server_timing { return( shift->_set_get_one( 'Server-Timing', @_ ) ); }
Subroutine server_timing: not called CC=1 SCAR=6.9
Pod documented
1473  
1474 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie>
1475 0 ▶sub set_cookie { return( shift->_set_get_one( 'Set-Cookie', @_ ) ); }
Subroutine set_cookie: not called CC=1 SCAR=6.9
Pod documented
1476  
1477 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/SourceMap>
1478 0 ▶sub sourcemap { return( shift->_set_get_one( 'SourceMap', @_ ) ); }
Subroutine sourcemap: not called CC=1 SCAR=6.9
Pod documented
1479  
1480 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security>
1481 0 ▶sub strict_transport_security { return( shift->_set_get_one( 'Strict-Transport-Security', @_ ) ); }
Subroutine strict_transport_security: not called CC=1 SCAR=6.9
Pod documented
1482  
1483 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/TE>
1484 0 ▶sub te { return( shift->_set_get_one( 'TE', @_ ) ); }
Subroutine te: not called CC=1 SCAR=6.9
Pod documented
1485  
1486 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Timing-Allow-Origin>
1487 0 ▶sub timing_allow_origin { return( shift->_set_get_multi( 'Timing-Allow-Origin', @_ ) ); }
Subroutine timing_allow_origin: not called CC=1 SCAR=6.9
Pod documented
1488  
1489 # NOTE: title() is inherited and sucks really
1490 0 ▶sub title { return( shift->_set_get_one( 'Title', @_ ) ); }
Subroutine title: not called CC=1 SCAR=6.9
Pod documented
1491  
1492 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Tk>
1493 0 ▶sub tk { return( shift->_set_get_one( 'Tk', @_ ) ); }
Subroutine tk: not called CC=1 SCAR=6.9
Pod documented
1494  
1495 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Trailer>
1496 0 ▶sub trailer { return( shift->_set_get_one( 'Trailer', @_ ) ); }
Subroutine trailer: not called CC=1 SCAR=6.9
Pod documented
1497  
1498 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Transfer-Encoding>
1499 0 ▶sub transfer_encoding { return( shift->_set_get_one( 'Transfer-Encoding', @_ ) ); }
Subroutine transfer_encoding: not called CC=1 SCAR=6.9
Pod documented
1500  
1501 sub type
1502 {
1503 123 ▶ my $self = shift( @_ );
Subroutine type: called CC=11 SCAR=25.5
Pod documented
1504 123 ▶ if( @_ )
Branch: 2 branches
BranchTrueFalseTotal
if (@_) { } 0 123 123
elsif (length $self->{'type'} and $self->{'_ctype_cached'} eq $self->content_type) { } 47 76 123
1505 {
1506 # mime-type like text/html, text/plain or application/json, etc...
1507 0 my $type = shift( @_ );
1508 0 $self->{type} = $type;
1509 # We are being provided with content type parameters, such as charset=utf8, or version=1
1510 0 my $ct = $self->new_field( 'Content-Type' => $type, @_ );
1511 0 $self->header( 'Content-Type' => "$ct" );
1512 0 $self->{_ctype_cached} = "$ct";
1513 0 ▶ $self->{boundary} = $ct->boundary if( $ct->boundary );
Branch: 1 branch
BranchTrueFalseTotal
if $ct->boundary 0 0 0
1514 }
1515 # Cached
1516 ▶ elsif( CORE::length( $self->{type} ) && $self->{_ctype_cached} eq $self->content_type )
Condition100%3/3
length $self->{"type"} and $self->{"_ctype_cached"} eq $self->content_type
!ll&&!rl&&r
70647
MC/DC100%2/2
length $self->{"type"} and $self->{"_ctype_cached"} eq $self->content_type
length $self->{"type"} $self->{"_ctype_cached"} eq $self->content_type
Truth table100%3/3
A and B
A= length $self->{"type"}B= $self->{"_ctype_cached"} eq $self->content_type
ABresult
0X0
100
111
1517 {
1518 47 return( $self->{type} );
1519 }
1520 else
1521 {
1522 76 my $ctype_raw = $self->content_type;
1523 76 ▶ return if( !defined( $ctype_raw ) || !length( "$ctype_raw" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ctype_raw and length "$ctype_raw" 48 28 76
Condition66%2/3
defined $ctype_raw and length "$ctype_raw"
!ll&&!rl&&r
48028
MC/DC50%1/2
defined $ctype_raw and length "$ctype_raw"
defined $ctype_raw length "$ctype_raw"
Truth table66%2/3
A and B
A= defined $ctype_rawB= length "$ctype_raw"
ABresult
0X0
100
111
1524 28 $self->{_ctype_cached} = $ctype_raw;
1525 # There is nothing, but the mime-type itself, so no need to bother
1526 28 ▶ if( index( $ctype_raw, ';' ) == -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($ctype_raw, ';') == -1) { } 16 12 28
1527 {
1528 16 $self->{type} = $ctype_raw;
1529 16 $self->{boundary} = '';
1530 }
1531 else
1532 {
1533 # Content-Type: application/json; encoding=utf-8
1534 12 my $ct = $self->new_field( 'Content-Type' => $ctype_raw );
1535 12 ▶ return( $self->pass_error ) if( !defined( $ct ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ct 0 12 12
1536 # Accept: application/json; version=1.0; charset=utf-8
1537 12 $self->{type} = lc( $ct->type );
1538 12 my $charset = $ct->charset;
1539 12 ▶ $charset = lc( $charset ) if( defined( $charset ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $charset 1 11 12
1540 12 $self->{charset} = $charset;
1541 12 ▶ $self->{boundary} = $ct->boundary if( $ct->boundary );
Branch: 1 branch
BranchTrueFalseTotal
if $ct->boundary 5 7 12
1542 }
1543 }
1544 28 return( $self->{type} );
1545 }
1546  
1547 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Upgrade>
1548 0 ▶sub upgrade { return( shift->_set_get_multi( 'Upgrade', @_ ) ); }
Subroutine upgrade: not called CC=1 SCAR=6.9
Pod documented
1549  
1550 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Upgrade-Insecure-Requests>
1551 0 ▶sub upgrade_insecure_requests { return( shift->_set_get_one( 'Upgrade-Insecure-Requests', @_ ) ); }
Subroutine upgrade_insecure_requests: not called CC=1 SCAR=6.9
Pod documented
1552  
1553 3 ▶sub uri_escape_utf8 { return( URI::Escape::XS::uri_escape( Encode::encode( 'UTF-8', $_[1] ) ) ); }
Subroutine uri_escape_utf8: called CC=1 SCAR=0.0
Pod documented
1554  
1555 # NOTE: user_agent() is inherited
1556 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent>
1557 0 ▶sub user_agent { return( shift->_set_get_one( 'user_agent', @_ ) ); }
Subroutine user_agent: not called CC=1 SCAR=6.9
Pod documented
1558  
1559 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Vary>
1560 0 ▶sub vary { return( shift->_set_get_multi( 'Vary', @_ ) ); }
Subroutine vary: not called CC=1 SCAR=6.9
Pod documented
1561  
1562 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Via>
1563 0 ▶sub via { return( shift->_set_get_multi( 'Via', @_ ) ); }
Subroutine via: not called CC=1 SCAR=6.9
Pod documented
1564  
1565 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Want-Digest>
1566 0 ▶sub want_digest { return( shift->_set_get_multi( 'Want-Digest', @_ ) ); }
Subroutine want_digest: not called CC=1 SCAR=6.9
Pod documented
1567  
1568 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Warning>
1569 0 ▶sub warning { return( shift->_set_get_one( 'Warning', @_ ) ); }
Subroutine warning: not called CC=1 SCAR=6.9
Pod documented
1570  
1571 # NOTE: www_authenticate() is superseded
1572 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/WWW-Authenticate>
1573 0 ▶sub www_authenticate { return( shift->_set_get_one( 'WWW-Authenticate', @_ ) ); }
Subroutine www_authenticate: not called CC=1 SCAR=6.9
Pod documented
1574  
1575 0 ▶sub x { return( shift->_set_get_one( 'X-' . $_[0], @_ ) ); }
Subroutine x: not called CC=1 SCAR=6.9
Pod documented
1576  
1577 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options>
1578 0 ▶sub x_content_type_options { return( shift->_set_get_one( 'X-Content-Type-Options', @_ ) ); }
Subroutine x_content_type_options: not called CC=1 SCAR=6.9
Pod documented
1579  
1580 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-DNS-Prefetch-Control>
1581 0 ▶sub x_dns_prefetch_control { return( shift->_set_get_one( 'X-DNS-Prefetch-Control', @_ ) ); }
Subroutine x_dns_prefetch_control: not called CC=1 SCAR=6.9
Pod documented
1582  
1583 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For>
1584 0 ▶sub x_forwarded_for { return( shift->_set_get_one( 'X-Forwarded-For', @_ ) ); }
Subroutine x_forwarded_for: not called CC=1 SCAR=6.9
Pod documented
1585  
1586 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host>
1587 0 ▶sub x_forwarded_host { return( shift->_set_get_one( 'X-Forwarded-Host', @_ ) ); }
Subroutine x_forwarded_host: not called CC=1 SCAR=6.9
Pod documented
1588  
1589 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto>
1590 0 ▶sub x_forwarded_proto { return( shift->_set_get_one( 'X-Forwarded-Proto', @_ ) ); }
Subroutine x_forwarded_proto: not called CC=1 SCAR=6.9
Pod documented
1591  
1592 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options>
1593 0 ▶sub x_frame_options { return( shift->_set_get_one( 'X-Frame-Options', @_ ) ); }
Subroutine x_frame_options: not called CC=1 SCAR=6.9
Pod documented
1594  
1595 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection>
1596 0 ▶sub x_xss_protection { return( shift->_set_get_one( 'X-XSS-Protection', @_ ) ); }
Subroutine x_xss_protection: not called CC=1 SCAR=6.9
Pod documented
1597  
1598 sub _basic_auth
1599 {
1600 0 ▶ my $self = shift( @_ );
Subroutine _basic_auth: not called CC=12 SCAR=50.5
1601 0 my $field = shift( @_ );
1602 0 ▶ 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 0 0
Condition0%0/3
defined $field and length $field
!ll&&!rl&&r
000
MC/DC0%0/2
defined $field and length $field
defined $field length $field
Truth table0%0/3
A and B
A= defined $fieldB= length $field
ABresult
0X0
100
111
1603 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
1604 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
1605 {
1606 0 my( $user, $pwd ) = @_;
1607 0 ▶ return( $self->error( "Basic authorisation user name cannot contain ':'." ) ) if( index( $user, ':' ) != -1 );
Branch: 1 branch
BranchTrueFalseTotal
if (index($user, ":") != -1) 0 0 0
1608 0 ▶ $pwd = '' if( !defined( $pwd ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pwd 0 0 0
1609 0 $self->header( $field => sprintf( 'Basic %s', Crypt::Misc::encode_b64( "${user}:${pwd}" ) ) );
1610 0 return( "${user}:${pwd}" );
1611 }
1612 else
1613 {
1614 0 my $v = $self->header( $field );
1615 0 ▶ return( $v ) if( !defined( $v ) && !want( 'OBJECT' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v or want("OBJECT") 0 0 0
Condition0%0/3
defined $v or want("OBJECT")
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $v or want("OBJECT")
defined $v want("OBJECT")
Truth table0%0/3
A or B
A= defined $vB= want("OBJECT")
ABresult
1X1
011
000
1616 0 ▶ if( defined( $v ) && $v =~ /^[[:blank:]\h]*Basic[[:blank:]\h]+(.+?)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v and $v =~ /^[[:blank:]\h]*Basic[[:blank:]\h]+(.+?)$/) 0 0 0
Condition0%0/3
defined $v and $v =~ /^[[:blank:]\h]*Basic[[:blank:]\h]+(.+?)$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $v and $v =~ /^[[:blank:]\h]*Basic[[:blank:]\h]+(.+?)$/
defined $v $v =~ /^[[:blank:]\h]*Basic[[:blank:]\h]+(.+?)$/
Truth table0%0/3
A and B
A= defined $vB= $v =~ /^[[:blank:]\h]*Basic[[:blank:]\h]+(.+?)$/
ABresult
0X0
100
111
1617 {
1618 0 $v = Crypt::Misc::decode_b64( $1 );
1619 }
1620 0 ▶ return( wantarray() ? split( /:/, "$v" ) : $self->new_scalar( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1621 }
1622 }
1623  
1624 sub _date_header
1625 {
1626 8 ▶ my $self = shift( @_ );
Subroutine _date_header: called CC=27 SCAR=51.9
1627 8 my $f = shift( @_ );
1628 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
1629 8 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 5 3 8
1630 {
1631 5 my $this = shift( @_ );
1632 5 ▶ return( $self->remove_header( "$f" ) ) if( !defined( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this 0 5 5
1633 5 my $opts = $self->_get_args_as_hash( @_ );
1634 5 ▶ $opts->{time_zone} = 'GMT' if( !defined( $opts->{time_zone} ) || !length( $opts->{time_zone} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"time_zone"} and length $opts->{"time_zone"} 5 0 5
Condition33%1/3
defined $opts->{"time_zone"} and length $opts->{"time_zone"}
!ll&&!rl&&r
500
MC/DC0%0/2
defined $opts->{"time_zone"} and length $opts->{"time_zone"}
defined $opts->{"time_zone"} length $opts->{"time_zone"}
Truth table33%1/3
A and B
A= defined $opts->{"time_zone"}B= length $opts->{"time_zone"}
ABresult
0X0
100
111
1635 5 require Module::Generic::DateTime;
1636 5 require DateTime::Format::Strptime;
1637 5 ▶ if( ref( $this ) && Scalar::Util::blessed( $this ) && $this->isa( 'Module::Generic::DateTime' ) )
Branch: 3 branches
BranchTrueFalseTotal
if (ref $this and builtin::blessed($this) and $this->isa('Module::Generic::DateTime')) { } 0 5 5
elsif (ref $this and builtin::blessed($this) and $this->isa('DateTime')) { } 0 5 5
elsif ($this =~ /^\d+$/) { } 5 0 5
Condition33%2/6
ref $this and builtin::blessed($this) and $this->isa("Module::Generic::DateTime")
!ll&&!rl&&r
500
ref $this and builtin::blessed($this)
!ll&&!rl&&r
500
MC/DC0%0/3
ref $this and builtin::blessed($this) and $this->isa("Module::Generic::DateTime")
ref $this builtin::blessed($this) $this->isa("Module::Generic::DateTime")
Truth table25%1/4
A and B and C
A= ref $thisB= builtin::blessed($this)C= $this->isa("Module::Generic::DateTime")
ABCresult
0XX0
10X0
1100
1111
1638 {
1639 # Ok, pass through
1640 }
1641 ▶ elsif( ref( $this ) && Scalar::Util::blessed( $this ) && $this->isa( 'DateTime' ) )
Condition33%2/6
ref $this and builtin::blessed($this) and $this->isa("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("DateTime")
ref $this builtin::blessed($this) $this->isa("DateTime")
Truth table25%1/4
A and B and C
A= ref $thisB= builtin::blessed($this)C= $this->isa("DateTime")
ABCresult
0XX0
10X0
1100
1111
1642 {
1643 0 $this = Module::Generic::DateTime->new( $this );
1644 }
1645 elsif( $this =~ /^\d+$/ )
1646 {
1647 # try-catch
1648 5 local $@;
1649 eval
1650 5 {
1651 5 $this = Module::Generic::DateTime->from_epoch( epoch => "$this", time_zone => $opts->{time_zone} );
1652 };
1653 5 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 5 5
1654 {
1655 0 return( $self->error( "An error occurred while trying to get the DateTime object for epoch value '$this': $@" ) );
1656 }
1657 }
1658 else
1659 {
1660 0 return( $self->error( "I was expecting an integer representing a unix time or a DateTime object, but instead got '$this'." ) );
1661 }
1662  
1663 # try-catch
1664 5 local $@;
1665 eval
1666 5 {
1667 5 $this->set_time_zone( 'GMT' );
1668 5 my $fmt = DateTime::Format::Strptime->new(
1669 pattern => '%a, %d %b %Y %H:%M:%S GMT',
1670 locale => 'en_GB',
1671 time_zone => 'GMT',
1672 );
1673 5 $this->set_formatter( $fmt );
1674 5 $self->header( $f => $this );
1675 };
1676 5 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 5 5
1677 {
1678 0 return( $self->error( "An error occurred while trying to format the datetime '$this': $@" ) );
1679 }
1680 5 return( $this );
1681 }
1682 else
1683 {
1684 3 my $v = $self->header( "$f" );
1685 3 ▶ return( $v ) if( !defined( $v ) || !length( "${v}" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v and length "$v" 1 0 1
Condition66%2/3
defined $v and length "$v"
!ll&&!rl&&r
120
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
1686 0 ▶ 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 0 0
Condition0%0/6
not length "$v" or ref $v and not overload::Method($v, "\"\"")
l!l&&r!l&&!r
000
ref $v and not overload::Method($v, "\"\"")
!ll&&!rl&&r
000
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 table0%0/4
not(A) or B and not(C)
A= not length "$v"B= ref $vC= not overload::Method($v, "\"\"")
ABCresult
1XX1
0111
00X0
0100
1687 {
1688 0 ▶ warn( "I do not know what to do with this supposedly datetime header $f with value '$v'\n" ) if( length( "$v" ) );
Branch: 1 branch
BranchTrueFalseTotal
if length "$v" 0 0 0
1689 0 return( '' );
1690 }
1691  
1692 # try-catch
1693 0 local $@;
1694 eval
1695 0 {
1696 0 ▶ unless( Scalar::Util::blessed( $v ) && $v->isa( 'Module::Generic::DateTime' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($v) and $v->isa("Module::Generic::DateTime")) 0 0 0
Condition0%0/3
builtin::blessed($v) and $v->isa("Module::Generic::DateTime")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($v) and $v->isa("Module::Generic::DateTime")
builtin::blessed($v) $v->isa("Module::Generic::DateTime")
Truth table0%0/3
A and B
A= builtin::blessed($v)B= $v->isa("Module::Generic::DateTime")
ABresult
0X0
100
111
1697 {
1698 # IE6 appends "; length = NNNN" on If-Modified-Since (can we handle it)
1699 # e.g.: Sat, 29 Oct 1994 19:43:31 GMT; length=34343
1700 0 ▶ if( index( $v, ';' ) != -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($v, ";") != -1) 0 0 0
1701 {
1702 0 $v = [split( /[[:blank:]\h]*;[[:blank:]\h]*/, "${v}", 2 )]->[0];
1703 }
1704 0 require Module::Generic;
1705 0 my $dt = Module::Generic->_parse_timestamp( "$v" );
1706 0 ▶ return( $self->pass_error( Module::Generic->error ) ) if( !defined( $dt ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dt 0 0 0
1707 0 my $fmt = DateTime::Format::Strptime->new( pattern => '%s' );
1708 0 $dt->set_formatter( $fmt );
1709 0 $v = Module::Generic::DateTime->new( $dt );
1710 }
1711 };
1712 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1713 {
1714 0 return( $self->error( "An error occurred while parsing datetime '$v': $@" ) );
1715 }
1716 0 return( $v );
1717 }
1718 }
1719  
1720 sub _get_args_as_array
1721 {
1722 74 ▶ my $self = shift( @_ );
Subroutine _get_args_as_array: called CC=6 SCAR=33.4
1723 74 ▶ return( [] ) if( !scalar( @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ 74 0 74
1724 0 my $ref = [];
1725 0 ▶ if( scalar( @_ ) == 1 &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1 and defined $_[0] and ref $_[0] and builtin::reftype($_[0]) eq 'ARRAY') { } 0 0 0
Condition0%0/9
scalar @_ == 1 and defined $_[0] and ref $_[0] and builtin::reftype($_[0]) eq "ARRAY"
!ll&&!rl&&r
000
scalar @_ == 1 and defined $_[0] and ref $_[0]
!ll&&!rl&&r
000
scalar @_ == 1 and defined $_[0]
!ll&&!rl&&r
000
MC/DC0%0/4
scalar @_ == 1 and defined $_[0] and ref $_[0] and builtin::reftype($_[0]) eq "ARRAY"
scalar @_ == 1 defined $_[0] ref $_[0] builtin::reftype($_[0]) eq "ARRAY"
Truth table0%0/5
A and B and C and D
A= scalar @_ == 1B= defined $_[0]C= ref $_[0]D= builtin::reftype($_[0]) eq "ARRAY"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1726 defined( $_[0] ) &&
1727 # Scalar::Util::reftype returns undef if the value is not a reference, which
1728 # causes a warning to pop up since we then compare an undefined value.
1729 ref( $_[0] ) &&
1730 Scalar::Util::reftype( $_[0] ) eq 'ARRAY' )
1731 {
1732 0 $ref = shift( @_ );
1733 }
1734 else
1735 {
1736 0 $ref = [ @_ ];
1737 }
1738 0 return( $ref );
1739 }
1740  
1741 sub _get_args_as_hash
1742 {
1743 27 ▶ my $self = shift( @_ );
Subroutine _get_args_as_hash: called CC=10 SCAR=29.7
1744 27 ▶ return( {} ) if( !scalar( @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ 5 22 27
1745 13 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1746 22 my $ref = {};
1747 22 my $order = $self->new_array;
1748 22 ▶ my $need_list = want( 'LIST' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
want('LIST') ? : 0 22 22
1749 22 ▶ if( scalar( @_ ) == 1 && Scalar::Util::reftype( $_[0] ) eq 'HASH' )
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_ == 1 and builtin::reftype($_[0]) eq 'HASH') { } 22 0 22
elsif (not scalar(@_) % 2) { } 0 0 0
Condition33%1/3
scalar @_ == 1 and builtin::reftype($_[0]) eq "HASH"
!ll&&!rl&&r
0022
MC/DC0%0/2
scalar @_ == 1 and builtin::reftype($_[0]) eq "HASH"
scalar @_ == 1 builtin::reftype($_[0]) eq "HASH"
Truth table33%1/3
A and B
A= scalar @_ == 1B= builtin::reftype($_[0]) eq "HASH"
ABresult
0X0
100
111
1750 {
1751 22 $ref = shift( @_ );
1752 22 ▶ $order = $self->new_array( [sort( keys( %$ref ) )] ) if( $need_list );
Branch: 1 branch
BranchTrueFalseTotal
if $need_list 0 22 22
1753 }
1754 elsif( !( scalar( @_ ) % 2 ) )
1755 {
1756 0 $ref = { @_ };
1757 0 ▶ if( $need_list )
Branch: 1 branch
BranchTrueFalseTotal
if ($need_list) 0 0 0
1758 {
1759 0 ▶ for( my $i = 0; $i < scalar( @_ ); $i += 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @_) 0 0 0
1760 {
1761 0 $order->push( $_[$i] );
1762 }
1763 }
1764 }
1765 22 ▶ return( $need_list ? ( $ref, $order ) : $ref );
Branch: 1 branch
BranchTrueFalseTotal
$need_list ? : 0 22 22
1766 }
1767  
1768 sub _header_get
1769 {
1770 0 ▶ my $self = shift( @_ );
Subroutine _header_get: not called CC=5 SCAR=34.0
1771 0 my $f = shift( @_ );
1772 0 ▶ return( $self->error( "No header field was provided." ) ) if( !defined( $f ) || !length( "$f" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f and length "$f" 0 0 0
Condition0%0/3
defined $f and length "$f"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $f and length "$f"
defined $f length "$f"
Truth table0%0/3
A and B
A= defined $fB= length "$f"
ABresult
0X0
100
111
1773 0 my @values = ();
1774 0 ▶ if( wantarray() )
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
1775 {
1776 0 @values = $self->header( "$f" );
1777 0 ▶ return if( !@values );
Branch: 1 branch
BranchTrueFalseTotal
unless @values 0 0 0
1778 0 return( @values );
1779 }
1780 else
1781 {
1782 0 return( $self->header( "$f" ) );
1783 }
1784 }
1785  
1786 sub _header_set
1787 {
1788 0 ▶ my $self = shift( @_ );
Subroutine _header_set: not called CC=7 SCAR=40.3
1789 0 ▶ return( $self->SUPER::error( "Uneven number of parameters provided. I was expecting field-value pairs." ) ) if( @_ % 2 );
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 0 0
1790 0 my @args = ();
1791 0 ▶ for( my $i = 0; $i < scalar( @_ ); $i += 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @_) 0 0 0
1792 {
1793 0 my( $f, $v ) = @_[$i..$i+1];
1794 0 ▶ next if( !defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
1795 0 ▶ if( $self->_is_array( $v ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_array($v)) { } 0 0 0
1796 {
1797 0 ▶ my $ref = $self->_is_object( $v ) ? [@$v] : $v;
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_object($v) ? : 0 0 0
1798 0 push( @args, "$f" => $ref );
1799 }
1800 else
1801 {
1802 0 push( @args, "$f" => $v );
1803 }
1804 }
1805  
1806 # try-catch
1807 0 local $@;
1808 eval
1809 0 {
1810 0 $self->header( @args );
1811 };
1812 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1813 {
1814 0 return( $self->error( "Error trying to set headers with values: $@" ) );
1815 }
1816 0 return( $self );
1817 }
1818  
1819 sub _is_a
1820 {
1821 22 ▶ my $self = shift( @_ );
Subroutine _is_a: called CC=4 SCAR=14.5
1822 22 my $obj = shift( @_ );
1823 22 my $pkg = shift( @_ );
1824 13 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
1825 22 ▶ return if( !$obj || !$pkg );
Branch: 1 branch
BranchTrueFalseTotal
unless $obj and $pkg 0 22 22
Condition33%1/3
$obj and $pkg
!ll&&!rl&&r
0022
MC/DC0%0/2
$obj and $pkg
$obj $pkg
Truth table33%1/3
A and B
A= $objB= $pkg
ABresult
0X0
100
111
1826 22 ▶ return if( !Scalar::Util::blessed( $obj ) );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($obj) 0 22 22
1827 22 return( $obj->isa( $pkg ) );
1828 }
1829  
1830 sub _is_class_loaded
1831 {
1832 84 ▶ my $self = shift( @_ );
Subroutine _is_class_loaded: called CC=12 SCAR=30.9
1833 84 my $class = shift( @_ );
1834 84 ▶ my $key = HAS_THREADS ? join( ';', $class, threads->tid() ) : $class;
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 0 84 84
1835 84 ▶ my $repo = Module::Generic::Global->new( 'loaded_classes' => ( ref( $self ) || $self ), key => $key );
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
8400
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
1836 84 ▶ if( $MOD_PERL )
Branch: 2 branches
BranchTrueFalseTotal
if ($HTTP::Promise::Headers::MOD_PERL) { } 0 84 84
elsif ($repo->exists) { } 54 30 84
1837 {
1838 # https://perl.apache.org/docs/2.0/api/Apache2/Module.html#C_loaded_
1839 0 my $rv = Apache2::Module::loaded( $class );
1840 0 ▶ return(1) if( $rv );
Branch: 1 branch
BranchTrueFalseTotal
if $rv 0 0 0
1841 }
1842 # elsif( HAS_THREADS && $repo->exists )
1843 elsif( $repo->exists )
1844 {
1845 54 return(1);
1846 }
1847 else
1848 {
1849 30 ( my $pm = $class ) =~ s{::}{/}gs;
1850 30 $pm .= '.pm';
1851 30 ▶ if( CORE::exists( $INC{ $pm } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $INC{$pm}) 20 10 30
1852 {
1853 20 $repo->set(1);
1854 20 return(1);
1855 }
1856 }
1857 13 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1858 10 my $ns = \%{ $class . '::' };
1859 10 ▶ 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 10 10
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
0010
exists $ns->{"ISA"} or exists $ns->{"BEGIN"}
l!l&&r!l&&!r
0010
exists $ns->{"VERSION"} and builtin::reftype(\$ns->{"VERSION"}) eq "GLOB" and defined ${*{\$ns->{"VERSION"};}{"SCALAR"};}
!ll&&!rl&&r
1000
exists $ns->{"VERSION"} and builtin::reftype(\$ns->{"VERSION"}) eq "GLOB"
!ll&&!rl&&r
1000
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 table0%0/6
A or B or C and D and E
A= exists $ns->{"ISA"}B= exists $ns->{"BEGIN"}C= exists $ns->{"VERSION"}D= builtin::reftype(\$ns->{"VERSION"}) eq "GLOB"E= defined ${*{\$ns->{"VERSION"};}{"SCALAR"};}
ABCDEresult
1XXXX1
01XXX1
001111
000XX0
0010X0
001100
1860 exists( $ns->{BEGIN} ) ||
1861 (
1862 exists( $ns->{VERSION} ) &&
1863 Scalar::Util::reftype( \$ns->{VERSION} ) eq 'GLOB' &&
1864 0 defined( ${*{\$ns->{VERSION}}{SCALAR}} )
1865 ) )
1866 {
1867 0 $repo->set(1);
1868 0 return(1);
1869 }
1870 10 return(0);
1871 }
1872  
1873 sub _is_glob
1874 {
1875 22 ▶ return(0) if( scalar( @_ < 2 ) );
Subroutine _is_glob: called CC=4 SCAR=14.6
Branch: 1 branch
BranchTrueFalseTotal
if scalar(@_ < 2) 0 22 22
1876 22 ▶ return(0) if( !defined( $_[1] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] 0 22 22
1877 22 my $type = Scalar::Util::reftype( $_[1] );
1878 22 ▶ return(0) if( !defined( $type ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 22 22
1879 22 return( $type eq 'GLOB' );
1880 }
1881  
1882 sub _load_class
1883 {
1884 74 ▶ my $self = shift( @_ );
Subroutine _load_class: called CC=25 SCAR=44.8
1885 74 ▶ 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
740
MC/DC0%0/1
shift @_ || (return $self->error('No package name was provided to load.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
1886  
1887 # Rigorous validation
1888 74 ▶ return( $self->error( "Class name is empty." ) ) unless( length( $class ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $class 0 74 74
1889  
1890 74 my $opts = {};
1891 74 ▶ $opts = pop( @_ ) if ( ref( $_[-1] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 0 74 74
1892  
1893 # Validate options
1894 74 my %valid_opts = map { $_ => 1 } qw( caller version no_import );
1895 74 foreach my $key ( keys( %$opts ) )
1896 {
1897 0 ▶ return( $self->error( "Invalid option: $key" ) ) unless ( exists( $valid_opts{ $key } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $valid_opts{$key} 0 0 0
1898 }
1899 74 ▶ if( exists( $opts->{version} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"version"}) 0 74 74
1900 {
1901 0 ▶ return( $self->error( "Version must be defined and non-empty." ) ) unless( defined( $opts->{version} ) && length( $opts->{version} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"version"} and length $opts->{"version"} 0 0 0
Condition0%0/3
defined $opts->{"version"} and length $opts->{"version"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opts->{"version"} and length $opts->{"version"}
defined $opts->{"version"} length $opts->{"version"}
Truth table0%0/3
A and B
A= defined $opts->{"version"}B= length $opts->{"version"}
ABresult
0X0
100
111
1902 }
1903  
1904 74 my $args = $self->_get_args_as_array( @_ );
1905  
1906 # Get the caller's package so we load the module in context
1907 74 ▶ my $caller_class = $opts->{caller} || CORE::caller;
Condition33%1/3
$opts->{'caller'} || caller
l!l&&r!l&&!r
0740
MC/DC0%0/2
$opts->{'caller'} || caller
$opts->{'caller'} caller
Truth table33%1/3
A || B
A= $opts->{'caller'}B= caller
ABresult
1X1
011
000
1908  
1909 # Return if already loaded (threads aware)
1910 74 my $is_loaded = $self->_is_class_loaded( $class );
1911 74 ▶ if( $is_loaded )
Branch: 1 branch
BranchTrueFalseTotal
if ($is_loaded) 64 10 74
1912 {
1913 64 ▶ if( scalar( @$args ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args) 0 64 64
1914 {
1915 0 ▶ my $pl = "package ${caller_class}; $class->import(" . ( scalar( @$args ) ? "'" . join( "', '", @$args ) . "'" : '' ) . ");";
Branch: 1 branch
BranchTrueFalseTotal
scalar @$args ? : 0 0 0
1916 0 eval( $pl );
1917 0 ▶ return( $self->error( "Error importing class $class into caller's namespace ${caller_class}: $@" ) ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1918 }
1919 64 return( $class );
1920 }
1921 # Use a shared variable for locking in threaded environments
1922 # What we retrieved from _is_class_loaded is not a threaded shared value, so we have to do this instead:
1923 10 ▶ my $key = HAS_THREADS ? join( ';', $class, threads->tid() ) : $class;
Branch: 1 branch
BranchTrueFalseTotal
&HAS_THREADS() ? : 0 10 10
1924 10 ▶ my $repo = Module::Generic::Global->new( 'loaded_classes' => ( ref( $self ) || $self ), key => $key );
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
1000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
1925  
1926 # Load the module with thread safety
1927 {
1928 10 ▶ my $has_version = ( CORE::exists( $opts->{version} ) && CORE::length( $opts->{version} // '' ) ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'version'} && length($opts->{'version'} // '') ? : 0 10 10
Condition20%1/5
exists $opts->{"version"} and length($opts->{"version"} // "")
!ll&&!rl&&r
1000
$opts->{"version"} // ""
l!l
00
MC/DC0%0/2
exists $opts->{"version"} and length($opts->{"version"} // "")
exists $opts->{"version"} $opts->{"version"}
Truth table33%1/3
A and B
A= exists $opts->{"version"}B= $opts->{"version"}
ABresult
0X0
100
111
1929 10 ▶ local $SIG{__DIE__} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=0.0
1930 10 local $@;
1931 10 my $pl = "package ${caller_class}; require $class;";
1932 10 eval( $pl );
1933 10 ▶ return( $self->error( "Unable to load package ${class}: $@\nCode executed was:\n${pl}" ) ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 10 10
1934 10 ▶ if( $has_version )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_version) 0 10 10
1935 {
1936 0 eval{ $class->VERSION( $opts->{version} ) };
1937 0 ▶ return( $self->error( "Insufficient version ", $class->VERSION(), ", for class $class. $opts->{version} minimum is required." ) ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1938 }
1939  
1940 10 ▶ $pl = "package ${caller_class}; $class->import(" . ( scalar( @$args ) ? "'" . join( "', '", @$args ) . "'" : '' ) . ");";
Branch: 1 branch
BranchTrueFalseTotal
scalar @$args ? : 0 10 10
1941 10 eval( $pl );
1942 10 ▶ return( $self->error( "Error importing class $class into caller's namespace ${caller_class}: $@" ) ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 10 10
1943 10 $repo->set(1);
1944 }
1945  
1946 10 ▶ return( $self->_is_class_loaded( $class ) ? $class : '' );
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_class_loaded($class) ? : 10 0 10
1947 }
1948  
1949 sub _set_get
1950 {
1951 40 ▶ my $self = shift( @_ );
Subroutine _set_get: called CC=2 SCAR=7.0
1952 40 my $prop = shift( @_ );
1953 40 ▶ $self->{ $prop } = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 40 40
1954 40 return( $self->{ $prop } );
1955 }
1956  
1957 # If there can be multiple instance of the given header
1958 sub _set_get_multi
1959 {
1960 0 ▶ my $self = shift( @_ );
Subroutine _set_get_multi: not called CC=9 SCAR=45.0
1961 0 my $f = shift( @_ );
1962 0 ▶ 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 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
1963 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
1964 {
1965 0 my $v = shift( @_ );
1966 0 ▶ return( $self->remove_header( "$f" ) ) if( !defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
1967 # Too dangerous and unnecessary. The value type the user provides us defines how it will be set in the HTTP headers
1968 # An array reference means there will be possibly multiple instance of the header
1969 # A string, means there will be only one instance.
1970 # my $ref = Scalar::Util::reftype( $v ) eq 'ARRAY' ? $v : [split( /\,[[:blank:]\h]*/, $v)];
1971 # $self->header( "$f" => $ref );
1972 0 $self->header( "$f" => $v );
1973 0 return( $v );
1974 }
1975 else
1976 {
1977 0 my @vals = $self->header( "$f" );
1978 0 my $ref;
1979 0 ▶ if( @vals > 1 )
Branch: 2 branches
BranchTrueFalseTotal
if (@vals > 1) { } 0 0 0
elsif (not defined $vals[0]) { } 0 0 0
1980 {
1981 0 $ref = \@vals;
1982 }
1983 elsif( !defined( $vals[0] ) )
1984 {
1985 0 ▶ if( want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (want('OBJECT')) { } 0 0 0
1986 {
1987 0 return( Module::Generic::Null->new );
1988 }
1989 else
1990 {
1991 0 return;
1992 }
1993 }
1994 else
1995 {
1996 0 $vals[0] =~ s/^[[:blank:]\h]+|[[:blank:]\h]+$//g;
1997 0 $ref = [split( /\,[[:blank:]\h]*/, $vals[0] )];
1998 }
1999 # Thi is not such a good idea after all. It is better to return a list in list
2000 # context or a scalar object otherwise
2001 # return( $self->new_array( $ref ) );
2002 0 ▶ return( wantarray() ? @$ref : $self->new_scalar( join( ', ', @$ref ) ) );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2003 }
2004 }
2005  
2006 # If there can be only one instance of the given header
2007 sub _set_get_one
2008 {
2009 123 ▶ my $self = shift( @_ );
Subroutine _set_get_one: called CC=8 SCAR=21.4
2010 123 my $f = shift( @_ );
2011 123 ▶ 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 123 123
Condition33%1/3
defined $f and length "$f"
!ll&&!rl&&r
00123
MC/DC0%0/2
defined $f and length "$f"
defined $f length "$f"
Truth table33%1/3
A and B
A= defined $fB= length "$f"
ABresult
0X0
100
111
2012 123 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 20 103 123
2013 {
2014 20 my $v = shift( @_ );
2015 20 ▶ return( $self->remove_header( "$f" ) ) if( !defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 20 20
2016 20 $self->header( "$f" => $v );
2017 20 return( $v );
2018 }
2019 else
2020 {
2021 103 my @vals = $self->header( "$f" );
2022 103 ▶ if( @vals > 1 )
Branch: 2 branches
BranchTrueFalseTotal
if (@vals > 1) { } 0 103 103
elsif (not defined $vals[0]) { } 48 55 103
2023 {
2024 # return( $self->new_array( \@vals ) );
2025 0 return( $self->new_scalar( join( ', ', @vals ) ) );
2026 }
2027 elsif( !defined( $vals[0] ) )
2028 {
2029 48 ▶ if( want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (want('OBJECT')) { } 8 40 48
2030 {
2031 8 return( Module::Generic::Null->new );
2032 }
2033 else
2034 {
2035 40 return;
2036 }
2037 }
2038 else
2039 {
2040 55 $vals[0] =~ s/^[[:blank:]\h]+|[[:blank:]\h]+$//g;
2041 55 return( $self->new_scalar( $vals[0] ) );
2042 }
2043 }
2044 }
2045  
2046 sub _set_get_one_number
2047 {
2048 17 ▶ my $self = shift( @_ );
Subroutine _set_get_one_number: called CC=11 SCAR=31.4
2049 17 my $f = shift( @_ );
2050 17 ▶ return( $self->error( "No field was provided to get or set its value." ) ) if( !defined( $f ) || !length( "$f" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f and length "$f" 0 17 17
Condition33%1/3
defined $f and length "$f"
!ll&&!rl&&r
0017
MC/DC0%0/2
defined $f and length "$f"
defined $f length "$f"
Truth table33%1/3
A and B
A= defined $fB= length "$f"
ABresult
0X0
100
111
2051 17 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 17 17
2052 {
2053 0 my $v = shift( @_ );
2054 0 ▶ return( $self->remove_header( "$f" ) ) if( !defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
2055 0 $self->header( "$f" => $v );
2056 0 return( $v );
2057 }
2058 else
2059 {
2060 17 my $v = $self->header( "$f" );
2061 17 ▶ if( !defined( $v ) || !length( $v ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $v and length $v) 16 1 17
Condition66%2/3
defined $v and length $v
!ll&&!rl&&r
1601
MC/DC50%1/2
defined $v and length $v
defined $v length $v
Truth table66%2/3
A and B
A= defined $vB= length $v
ABresult
0X0
100
111
2062 {
2063 16 ▶ if( want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (want('OBJECT')) { } 0 16 16
2064 {
2065 0 require Module::Generic::Null;
2066 0 my $null = Module::Generic::Null->new( '', { debug => $self->debug });
2067 0 rreturn( $null );
2068 }
2069 else
2070 {
2071 16 return( $v );
2072 }
2073 }
2074 # Ignore overflow values
2075 # 16 digits corresponding to 2^53-1 or 9007199254740991
2076 1 ▶ if( $v =~ /^[[:blank:]\h]*(\d{1,16})[[:blank:]\h]*$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /^[[:blank:]\h]*(\d{1,16})[[:blank:]\h]*$/) { } 1 0 1
2077 {
2078 1 $v = $1;
2079 }
2080 else
2081 {
2082 0 return( '' );
2083 }
2084 1 ▶ return( $v ) if( ref( $v ) && !overload::Method( $v, '""' ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $v and not overload::Method($v, "\"\"") 0 1 1
Condition33%1/3
ref $v and not overload::Method($v, "\"\"")
!ll&&!rl&&r
100
MC/DC0%0/2
ref $v and not overload::Method($v, "\"\"")
ref $v not overload::Method($v, "\"\"")
Truth table33%1/3
A and not(B)
A= ref $vB= not overload::Method($v, "\"\"")
ABresult
0X0
100
111
2085 1 return( $self->new_number( "$v" ) );
2086 }
2087 }
2088  
2089 sub _set_get_one_uri
2090 {
2091 0 ▶ my $self = shift( @_ );
Subroutine _set_get_one_uri: not called CC=6 SCAR=37.4
2092 0 my $f = shift( @_ );
2093 0 ▶ 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 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
2094 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
2095 {
2096 0 my $v = shift( @_ );
2097 0 ▶ return( $self->remove_header( "$f" ) ) if( !defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
2098 0 $self->header( "$f" => $v );
2099 0 return( $v );
2100 }
2101 else
2102 {
2103 0 my $v = $self->header( "$f" );
2104 0 my $uri;
2105 # try-catch
2106 0 local $@;
2107 eval
2108 0 {
2109 0 require URI;
2110 0 $uri = URI->new( $v );
2111 };
2112 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2113 {
2114 0 return( $self->error( "Unable to create an URI object from the header value for \"$f\": $@" ) );
2115 }
2116 0 return( $uri );
2117 }
2118 }
2119  
2120 # $obj->_str_val( $some_object );
2121 # $obj->_str_val( undef );
2122 sub _str_val
2123 {
2124 13 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
2125 0 ▶ return( '' ) unless( scalar( @_ ) > 1 && defined( $_[1] ) );
Subroutine _str_val: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ > 1 and defined $_[1] 0 0 0
Condition0%0/3
scalar @_ > 1 and defined $_[1]
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ > 1 and defined $_[1]
scalar @_ > 1 defined $_[1]
Truth table0%0/3
A and B
A= scalar @_ > 1B= defined $_[1]
ABresult
0X0
100
111
2126 0 return( "$_[1]" );
2127 }
2128  
2129 # NOTE: For CBOR and Sereal
2130 sub FREEZE
2131 {
2132 10 ▶ my $self = CORE::shift( @_ );
Subroutine FREEZE: called CC=5 SCAR=17.2
Pod undocumented
2133 10 ▶ my $serialiser = CORE::shift( @_ ) // '';
Condition50%1/2
shift @_ // ""
l!l
100
MC/DC0%0/1
shift @_ // ""
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
2134 10 my $class = CORE::ref( $self );
2135 10 my $h = {};
2136 10 my $headers = [];
2137 10 my $order = [];
2138 $self->scan(sub
2139 {
2140 20 ▶ my( $f, $val ) = @_;
Subroutine __ANON__: called CC=3 SCAR=15.0
2141 20 ▶ if( CORE::exists( $h->{ $f } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $h->{$f}) { } 0 20 20
2142 {
2143 0 ▶ $h->{ $f } = [ $h->{ $f } ] unless( CORE::ref( $h->{ $f } ) eq 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $h->{$f} eq "ARRAY" 0 0 0
2144 0 CORE::push( @{$h->{ $f }}, $val );
2145 }
2146 else
2147 {
2148 20 $h->{ $f } = $val;
2149 20 CORE::push( @$order, $f );
2150 }
2151 10 });
2152 10 foreach my $f ( @$order )
2153 {
2154 20 CORE::push( @$headers, $f, $h->{ $f } );
2155 }
2156 10 my %hash = %$self;
2157 10 $hash{_headers_to_restore} = $headers;
2158 # Return an array reference rather than a list so this works with Sereal and CBOR
2159 10 ▶ CORE::return( [$class, \%hash] ) if( $serialiser eq 'Sereal' && Sereal::Encoder->VERSION <= version->parse( '4.023' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $serialiser eq "Sereal" and "Sereal::Encoder"->VERSION <= "version"->parse("4.023") 0 10 10
Condition66%2/3
$serialiser eq "Sereal" and "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
!ll&&!rl&&r
550
MC/DC0%0/2
$serialiser eq "Sereal" and "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
$serialiser eq "Sereal" "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
Truth table66%2/3
A and B
A= $serialiser eq "Sereal"B= "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
ABresult
0X0
100
111
2160 # But Storable want a list with the first element being the serialised element
2161 10 CORE::return( $class, \%hash );
2162 }
2163  
2164 5 ▶sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: called CC=1 SCAR=0.0
Pod undocumented
2165  
2166 # NOTE: Storable creates an instance of HTTP:::Promise::Headers. The only problem is that it does not work with XS module and that Storable discard whatever value is returned by STORABLE_thaw. See issue #19984 <https://github.com/Perl/perl5/issues/19984>
2167 # So instead, we use this hook to store some data into the object created by Storable, and we call STORABLE_thaw_post_processing() with it and take what it returns.
2168 sub STORABLE_thaw
2169 {
2170 5 ▶ my( $self, undef, $class, $hash ) = @_;
Subroutine STORABLE_thaw: called CC=4 SCAR=16.6
Pod undocumented
2171 5 ▶ $class //= CORE::ref( $self ) || $self;
Condition16%1/6
$class //= ref $self || $self
l!l&&r!l&&!r
500
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/3
$class //= ref $self || $self
$class ref $self $self
Truth table0%0/4
A //= B || C
A= $classB= ref $selfC= $self
ABCresult
1XX1
01X1
0011
0000
2172 5 ▶ $hash //= {};
Condition50%1/2
$hash //= {}
l!l
50
MC/DC0%0/1
$hash //= {}
$hash
Truth table50%1/2
A
A= $hash
Aresult
11
00
2173 5 $hash->{_class} = $class;
2174 5 $self->{_deserialisation_params} = $hash;
2175 # Useles to do more in STORABLE_thaw, because Storable anyway ignores the value returned
2176 # so we just store our hash of parameters for STORABLE_thaw_post_processing to do its actual job
2177 5 CORE::return( $self );
2178 }
2179  
2180 sub STORABLE_thaw_post_processing
2181 {
2182 4 ▶ my $obj = CORE::shift( @_ );
Subroutine STORABLE_thaw_post_processing: called CC=7 SCAR=22.7
Pod undocumented
2183 my $hash = ( CORE::exists( $obj->{_deserialisation_params} ) && CORE::ref( $obj->{_deserialisation_params} ) eq 'HASH' )
2184 ? CORE::delete( $obj->{_deserialisation_params} )
2185 4 ▶ : {};
Branch: 1 branch
BranchTrueFalseTotal
exists $obj->{'_deserialisation_params'} && ref $obj->{'_deserialisation_params'} eq 'HASH' ? : 4 0 4
Condition33%1/3
exists $obj->{"_deserialisation_params"} and ref $obj->{"_deserialisation_params"} eq "HASH"
!ll&&!rl&&r
004
MC/DC0%0/2
exists $obj->{"_deserialisation_params"} and ref $obj->{"_deserialisation_params"} eq "HASH"
exists $obj->{"_deserialisation_params"} ref $obj->{"_deserialisation_params"} eq "HASH"
Truth table33%1/3
A and B
A= exists $obj->{"_deserialisation_params"}B= ref $obj->{"_deserialisation_params"} eq "HASH"
ABresult
0X0
100
111
2186 4 ▶ my $class = CORE::delete( $hash->{_class} ) || CORE::ref( $obj ) || $obj;
Condition33%2/6
delete $hash->{'_class'} || ref $obj || $obj
l!l&&r!l&&!r
400
delete $hash->{"_class"} or ref $obj
l!l&&r!l&&!r
400
MC/DC0%0/3
delete $hash->{'_class'} || ref $obj || $obj
delete $hash->{"_class"} ref $obj $obj
Truth table25%1/4
A or B || C
A= delete $hash->{"_class"}B= ref $objC= $obj
ABCresult
1XX1
01X1
0011
0000
2187 my $headers = CORE::ref( $hash->{_headers_to_restore} ) eq 'ARRAY'
2188 ? CORE::delete( $hash->{_headers_to_restore} )
2189 4 ▶ : [];
Branch: 1 branch
BranchTrueFalseTotal
ref $hash->{'_headers_to_restore'} eq 'ARRAY' ? : 4 0 4
2190 4 my $new = $class->new( @$headers );
2191 4 foreach( CORE::keys( %$hash ) )
2192 {
2193 19 $new->{ $_ } = CORE::delete( $hash->{ $_ } );
2194 }
2195 4 CORE::return( $new );
2196 }
2197  
2198 # NOTE: CBOR will call the THAW method with the stored classname as first argument, the constant string CBOR as second argument, and all values returned by FREEZE as remaining arguments.
2199 # NOTE: Storable calls STORABLE_thaw with a blessed object it created followed with $cloning and any other arguments initially provided by STORABLE_freeze. Then, after receiving $self from STORABLE_thaw, we call THAW which return a useable object. The one generated by Storable triggers the exception: "hl is not an instance of HTTP::XSHeader"
2200 sub THAW
2201 {
2202 # STORABLE_thaw would issue $cloning as the 2nd argument, while CBOR would issue
2203 # 'CBOR' as the second value.
2204 5 ▶ my( $self, undef, @args ) = @_;
Subroutine THAW: called CC=12 SCAR=33.5
Pod undocumented
2205 5 ▶ my $ref = ( CORE::scalar( @args ) == 1 && CORE::ref( $args[0] ) eq 'ARRAY' ) ? CORE::shift( @args ) : \@args;
Branch: 1 branch
BranchTrueFalseTotal
scalar @args == 1 && ref $args[0] eq 'ARRAY' ? : 0 5 5
Condition33%1/3
scalar @args == 1 and ref $args[0] eq "ARRAY"
!ll&&!rl&&r
500
MC/DC0%0/2
scalar @args == 1 and ref $args[0] eq "ARRAY"
scalar @args == 1 ref $args[0] eq "ARRAY"
Truth table33%1/3
A and B
A= scalar @args == 1B= ref $args[0] eq "ARRAY"
ABresult
0X0
100
111
2206 5 ▶ my $class = ( CORE::defined( $ref ) && CORE::ref( $ref ) eq 'ARRAY' && CORE::scalar( @$ref ) > 1 ) ? CORE::shift( @$ref ) : ( CORE::ref( $self ) || $self );
Branch: 1 branch
BranchTrueFalseTotal
defined $ref && ref $ref eq 'ARRAY' && scalar @$ref > 1 ? : 5 0 5
Condition22%2/9
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
!ll&&!rl&&r
005
defined $ref and ref $ref eq "ARRAY"
!ll&&!rl&&r
005
ref $self or $self
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
defined $ref ref $ref eq "ARRAY" scalar @$ref > 1
MC/DC0%0/2
ref $self or $self
ref $self $self
Truth table25%1/4
A and B and C
A= defined $refB= ref $ref eq "ARRAY"C= scalar @$ref > 1
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
A or B
A= ref $selfB= $self
ABresult
1X1
011
000
2207 5 ▶ my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 5 0 5
2208 my $headers = ( CORE::exists( $hash->{_headers_to_restore} ) && CORE::ref( $hash->{_headers_to_restore} ) eq 'ARRAY' )
2209 ? CORE::delete( $hash->{_headers_to_restore} )
2210 5 ▶ : [];
Branch: 1 branch
BranchTrueFalseTotal
exists $hash->{'_headers_to_restore'} && ref $hash->{'_headers_to_restore'} eq 'ARRAY' ? : 5 0 5
Condition33%1/3
exists $hash->{"_headers_to_restore"} and ref $hash->{"_headers_to_restore"} eq "ARRAY"
!ll&&!rl&&r
005
MC/DC0%0/2
exists $hash->{"_headers_to_restore"} and ref $hash->{"_headers_to_restore"} eq "ARRAY"
exists $hash->{"_headers_to_restore"} ref $hash->{"_headers_to_restore"} eq "ARRAY"
Truth table33%1/3
A and B
A= exists $hash->{"_headers_to_restore"}B= ref $hash->{"_headers_to_restore"} eq "ARRAY"
ABresult
0X0
100
111
2211  
2212 5 my $new = $class->new( @$headers );
2213 5 foreach( CORE::keys( %$hash ) )
2214 {
2215 23 ▶ next if( CORE::scalar( CORE::grep( $_, @$headers ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar grep($_, @$headers) 23 0 23
2216 0 $new->{ $_ } = CORE::delete( $hash->{ $_ } );
2217 }
2218 5 CORE::return( $new );
2219 }
2220  
2221 sub TO_JSON
2222 {
2223 0 ▶ my $self = shift( @_ );
Subroutine TO_JSON: not called CC=1 SCAR=6.9
Pod undocumented
2224 0 my $ref = [];
2225 $self->scan(sub
2226 {
2227 0 ▶ my( $header, $val ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
2228 0 CORE::push( @$ref, [ $header, $val ] );
2229 0 });
2230 0 return( $ref );
2231 }
2232  
2233 13 1;
2234 # NOTE: POD
2235 __END__
2236  
2237 =encoding utf-8
2238  
2239 =head1 NAME
2240  
2241 HTTP::Promise::Headers - HTTP Headers Class
2242  
2243 =head1 SYNOPSIS
2244  
2245 use HTTP::Promise::Headers;
2246 my $h = HTTP::Promise::Headers->new ||
2247 die( HTTP::Promise::Headers->error, "\n" );
2248  
2249 =head1 VERSION
2250  
2251 v0.3.2
2252  
2253 =head1 DESCRIPTION
2254  
2255 This class uses for the most part an XS module (L<HTTP::XSHeaders>) to be very fast, and yet provides a convenient and versatile interface to retrieve and manipulate HTTP headers.
2256  
2257 A number of classes has been created to have a more granular control on the creation of some header values. See L</SEE ALSO>
2258  
2259 All HTTP headers known today have their corresponding method that can be used to easily get or set their corresponding header value.
2260  
2261 =head1 CONSTRUCTOR
2262  
2263 =head2 new
2264  
2265 This instantiates a new L<HTTP::Promise::Headers> object. You might pass some initial
2266 attribute-value pairs as parameters to the constructor.
2267  
2268 For example:
2269  
2270 $h = HTTP::Headers->new(
2271 Date => 'Mon, 09 May 2022 09:00:00 GMT',
2272 Content_Type => 'text/html; charset=utf-8; version=5.0',
2273 Content_Base => 'http://www.example.org/'
2274 );
2275  
2276 The constructor arguments are passed to the L</header> method described below.
2277  
2278 =head1 METHODS
2279  
2280 =head2 add
2281  
2282 This is an alias for L</push_header>
2283  
2284 =head2 as_string
2285  
2286 Provided with an optional C<EOL> to be used as End-Of-Line character, and this will return a string representation of the headers. C<EOL> defaults to C<\015\012>. Embedded "\n" characters in header field values will be substituted with this line ending sequence.
2287  
2288 This uses L</scan> internally and use header field case as suggested by HTTP specifications. It will also follow recommended "Good Practice" of ordering the header fields. Long header values are not folded.
2289  
2290 =head2 authorization_basic
2291  
2292 This is a convenience method around the L</authorization> method for the C<Authorization> header using the "Basic Authentication Scheme".
2293  
2294 To set the related header value, you provide a login and an optional password, and this will set the C<Authorization> header value and return the current headers object for chaining.
2295  
2296 $h->authorization_basic( $user, $password );
2297  
2298 If no value is provided, this will get the curent value of the C<Authorization> header field, base64 decode it, and return the decoded string as a L<scalar object|Module::Generic::Scalar>, i.e. something like C<usernaem:password>
2299  
2300 my $str = $h->authorization_basic;
2301  
2302 =head2 boundary
2303  
2304 This is a convenience method to set or get the boundary, if any, used for multipart C<Content-Type>
2305  
2306 If provided, this will add the C<boundary> parameter with the given value to the C<Content-Type> header field.
2307  
2308 If no value is provided, this returns the current boundary, if any, or an empty string.
2309  
2310 =head2 charset
2311  
2312 This is a convenience method to set or get the charset associated with the C<Content-Type> header field.
2313  
2314 If provided, this will add the C<charset> parameter with the given value to the C<Content-Type> header field.
2315  
2316 If no value is provided, this returns the current charset, if any, or an empty string.
2317  
2318 =head2 clear
2319  
2320 This will remove all header fields.
2321  
2322 =for Pod::Coverage:: client_date
2323  
2324 =head2 clone
2325  
2326 Returns a copy of this L<HTTP::Promise::Headers> object.
2327  
2328 =head2 content_is_text
2329  
2330 Returns true if the C<Content-Type> mime-type is textual in nature, i.e. its first half is C<text>, false otherwise. For example: C<text/plain> or C<text/html>
2331  
2332 =head2 content_is_html
2333  
2334 Returns true if the C<Content-Type> mime-type is html, such as C<text/html>, false otherwise.
2335  
2336 =head2 content_is_json
2337  
2338 Returns true if the C<Content-Type> mime-type is C<application/json>, false otherwise.
2339  
2340 =head2 content_is_xhtml
2341  
2342 Returns true if the C<Content-Type> mime-type is C<application/xhtml+xml> or C<application/vnd.wap.xhtml+xml>, false otherwise.
2343  
2344 =head2 content_is_xml
2345  
2346 Returns true if the C<Content-Type> mime-type is C<text/xml> or C<application/xml>, or contains the keyword C<xml>, false otherwise.
2347  
2348 =head2 content_type_charset
2349  
2350 This is a legacy method and it returns the upper-cased charset specified in the Content-Type header.
2351 In list context return the lower-cased bare content type followed by the upper-cased charset.
2352 Both values will be C<undef> if not specified in the header.
2353  
2354 =head2 decode_filename
2355  
2356 This takes a file name from the C<Content-Disposition> header value typically and returns it decoded if it was encoded as per the L<rfc2231|https://tools.ietf.org/html/rfc2231>
2357  
2358 For example:
2359  
2360 Content-Disposition: form-data; name="fileField"; filename*=UTF-8''%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB.txt
2361  
2362 my $fname = $h->decode_filename( "UTF-8''%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB.txt" );
2363  
2364 or
2365  
2366 Content-Disposition: form-data; name="fileField"; filename*=UTF-8'ja-JP'%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB.txt
2367  
2368 my $fname = $h->decode_filename( "UTF-8'ja-JP'%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB.txt" );
2369  
2370 or encoded with quoted-printable
2371  
2372 Content-Disposition: attachment; filename="=?UTF-8?Q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB.txt?="
2373  
2374 my $fname = $h->decode_filename( "=?UTF-8?Q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB.txt?=" );
2375  
2376 or encoded with base64
2377  
2378 Content-Disposition: attachment; filename="=?UTF-8?B?44OV44Kh44Kk44OrLnR4dAo?="
2379  
2380 my $fname = $h->decode_filename( "=?UTF-8?B?44OV44Kh44Kk44OrLnR4dAo?=" );
2381  
2382 In the above example, the result for C<$fname> would yield C<ファイル.txt> (i.e. file.txt in Japanese)
2383  
2384 =head2 debug
2385  
2386 Sets or gets the debug value. If positive, this will trigger an output of debugging messages on the STDERR or in the web server log files. Be mindful that this slows down the script, so make sure to switch it off once you are done.
2387  
2388 =head2 default_type
2389  
2390 Sets or gets the default mime-type to be used.
2391  
2392 =head2 delete
2393  
2394 This is an alias for L</remove_header>
2395  
2396 =head2 encode_filename
2397  
2398 This takes a file name to be used in the C<Content-Disposition> header value, and an optional language iso 639 code (see L<rfc1766|https://tools.ietf.org/html/rfc1766>), and if it contains non ascii characters, it will utf-8 encode it and URI escape it according to L<rfc2231|https://tools.ietf.org/html/rfc2231> and return the newly encoded file name.
2399  
2400 If the file name did not require any encoding, it will return C<undef>, so you can write something like this:
2401  
2402 my $filename = q{マイファイル.txt};
2403 if( my $enc = $h->encode_filename( $filename ) )
2404 {
2405 $filename = $enc;
2406 # Now $filename is: UTF-8''%E3%83%9E%E3%82%A4%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB.txt
2407 }
2408  
2409 You can optionally pass a language code argument:
2410  
2411 if( my $enc = $h->encode_filename( $filename, 'ja-JP' ) )
2412 {
2413 $filename = $enc;
2414 # Now $filename is: UTF-8'ja-JP'%E3%83%9E%E3%82%A4%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB.txt
2415 }
2416  
2417 The C<Content-Disposition> header value would then contain a property C<filename*> (with the trailing wildcard).
2418  
2419 =head2 error
2420  
2421 Sets or gets an error and when set, this returns C<undef>. When no argument is provided, this returns the latest error set.
2422  
2423 The error returned is actually a L<HTTP::Promise::Exception> object.
2424  
2425 =head2 exists
2426  
2427 Provided with a header field name and this returns true if it exists, or false otherwise.
2428  
2429 =head2 flatten
2430  
2431 $h->flatten();
2432  
2433 Returns the list of pairs of keys and values.
2434  
2435 =head2 get
2436  
2437 This is an alias for L</header>, mainly used without argument.
2438  
2439 =head2 header
2440  
2441 $h->header( $field );
2442 $h->header( $field => $value );
2443 $h->header( $f1 => $v1, $f2 => $v2, ... );
2444  
2445 The following is an extract from the original L<HTTP::Headers> class.
2446  
2447 Sets or gets the value of one or more header fields.
2448 The header field name (C<$field>) is not case sensitive.
2449 To make the life easier for perl users who wants to avoid quoting before the => operator, you can use '_' as a replacement for '-' in header names.
2450  
2451 The L</header> method accepts multiple field-value (C<$field => $value>) pairs, which means that you can update several header field values with a single invocation.
2452  
2453 The C<$value> argument may be a plain string or an array reference of strings for a multi-valued field. If the C<$value> is provided as C<undef> then the field is removed.
2454  
2455 If the C<$value> is not given, then that header field will remain unchanged. In addition to being a string, C<$value> may be something that stringifies.
2456  
2457 The old value (or values) of the last of the header fields is returned. If no such field exists C<undef> will be returned.
2458  
2459 A multi-valued field will be returned as separate values in list context and will be concatenated with ", " as separator in scalar context.
2460 The HTTP spec (L<rfc7230|https://tools.ietf.org/html/rfc7230> which obsoleted L<rfc2616|https://tools.ietf.org/html/rfc2616>) promises that joining multiple values in this way will not change the semantic of a header field, but in practice there are cases like old-style Netscape cookies where "," is used as part of the syntax of a single field value.
2461  
2462 Examples:
2463  
2464 $h->header( MIME_Version => '1.0',
2465 User_Agent => 'My-Web-Client/0.01' );
2466 $h->header( Accept => "text/html, text/plain, image/*" );
2467 $h->header( Accept => [qw( text/html text/plain image/* )] );
2468 @accepts = $h->header( 'Accept' ); # get multiple values
2469 $accepts = $h->header( 'Accept' ); # get values as a single string
2470  
2471 =head2 header_field_names
2472  
2473 The following is an extract from the original L<HTTP::Headers> class.
2474  
2475 Returns the list of distinct names for the fields present in the header.
2476 The field names have case as suggested by HTTP spec, and the names are returned in the recommended "Good Practice" order.
2477  
2478 In scalar context return the number of distinct field names.
2479  
2480 =head2 init_header
2481  
2482 $h->init_header( $field => $value );
2483  
2484 Set the specified header to the given value, but only if no previous value for that field is set.
2485  
2486 The header field name (C<$field>) is not case sensitive and '_' can be used as a replacement for '-'.
2487  
2488 The $value argument may be a scalar or a reference to a list of scalars.
2489  
2490 =head2 make_boundary
2491  
2492 Returns a new boundary using L<Data::UUID>
2493  
2494 =for Pod::Coverage message
2495  
2496 =for Pod::Coverage message_check
2497  
2498 =for Pod::Coverage message_frame
2499  
2500 =head2 mime_attr
2501  
2502 Provided with a header field name and an attribute name separated by a dot, such as C<content-disposition.filename> and this will return the value for that attribute in this header.
2503  
2504 If a value is provided, it will be set, otherwise it will be returned.
2505  
2506 If no attribute is provided, it will set or get the header field main value.
2507  
2508 For example:
2509  
2510 Content-Disposition: attachment; filename="hello.txt"
2511 my $dispo = $h->mime_attr( 'content-disposition' );
2512  
2513 will return C<attachment>
2514  
2515 =head2 mime_encoding
2516  
2517 Returns the value of the C<Content-Encoding>, C<Transfer-Encoding> or C<Content-Transfer-Encoding> (the latter only exists in mail, not in HTTP)
2518  
2519 =head2 mime_type
2520  
2521 Returns the mime-type from the C<Content-Type> header value, or the one from L<default_type>, if it is set. If nothing is found, this returns an empty string (not C<undef>).
2522  
2523 =head2 multipart_boundary
2524  
2525 Returns the multipart boundary used, if any, or an empty string otherwise.
2526  
2527 my $boundary = $h->multipart_boundary;
2528 # or you can provide the Content-Type if you already have it; it will save a few cycle
2529 my $boundary = $h->multipart_boundary( $content_type );
2530  
2531 =head2 print
2532  
2533 Provided with a filehandle, or an L<HTTP::Promise::IO> object and this will print on it the string representation of the headers and return whatever value L<perlfunc/print> will return.
2534  
2535 =head2 proxy_authorization_basic
2536  
2537 =head2 push_header
2538  
2539 $h->push_header( $field => $value );
2540 $h->push_header( $f1 => $v1, $f2 => $v2, ... );
2541  
2542 Add a new value for the specified header. Previous values for the same header are retained.
2543  
2544 As for the L</header> method, the field name (C<$field>) is not case sensitive and '_' can be used as a replacement for '-'.
2545  
2546 The $value argument may be a scalar or a reference to a list of scalars.
2547  
2548 $header->push_header( Accept => 'image/jpeg' );
2549 $header->push_header( Accept => [ map( "image/$_", qw( gif png tiff ) )] );
2550  
2551 =head2 recommended_filename
2552  
2553 This returns the filename set in either C<Content-Disposition> with the C<filename> property or in C<Content-Type> with the C<name> property.
2554  
2555 If none exists, this returns C<undef>.
2556  
2557 =head2 remove
2558  
2559 This is an alias for L</remove_header>
2560  
2561 =head2 remove_content_headers
2562  
2563 This will remove all the headers used to describe the content of a message.
2564  
2565 All header field names prefixed with C<Content-> are included in this category, as well as C<Allow>, C<Expires> and
2566 C<Last-Modified>. L<rfc7230|https://tools.ietf.org/html/rfc7230> denotes these headers as I<Entity Header Fields>.
2567  
2568 The return value is a new L<HTTP::Promise::Headers> object that contains the removed headers only.
2569  
2570 =head2 remove_header
2571  
2572 my @values = $h->remove_header( $field, ... );
2573 my $total_values_removed = $h->remove_header( $field, ... );
2574  
2575 This function removes the header with the specified names.
2576  
2577 The header names (C<$field>) are not case sensitive and '_' can be used as a replacement for '-'.
2578  
2579 The return value is the values of the headers removed. In scalar context the number of headers removed is returned.
2580  
2581 Note that if you pass in multiple header names then it is generally not possible to tell which of the returned values belonged to which field.
2582  
2583 =head2 replace
2584  
2585 Provided with a header field name and a value and this replace whatever current value with the value provided.
2586  
2587 It returns the current object for chaining.
2588  
2589 =head2 request_timeout
2590  
2591 Sets or gets the request timeout. This takes an integer.
2592  
2593 =head2 scan
2594  
2595 $h->scan( \&process_header_field );
2596  
2597 Apply a subroutine to each header field in turn.
2598 The callback routine is called with two parameters; the name of the field and a single value (a string).
2599 If a header field is multi-valued, then the routine is called once for each value.
2600 The field name passed to the callback routine has case as suggested by HTTP spec, and the headers will be visited in the recommended "Good Practice" order.
2601  
2602 Any return values of the callback routine are ignored.
2603 The loop can be broken by raising an exception (C<die>), but the caller of scan() would have to trap the exception itself.
2604  
2605 =head2 type
2606  
2607 This sets or gets the C<Content-Type> header value when setting a value, and returns only the mime-type when retrieving the value.
2608  
2609 $h->type( 'text/plain' );
2610 # Assuming Content-Type: text/html; charset=utf-8
2611 my $type = $h->type; # text/html
2612  
2613 =head2 uri_escape_utf8
2614  
2615 Provided with a string and this returns an URI-escaped string using L<URI::Escape::XS>
2616  
2617 =head1 HTTP HEADERS METHODS
2618  
2619 =head2 accept
2620  
2621 $h->accept( q{text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8} );
2622 $h->accept( [qw( text/html application/xhtml+xml application/xml;q=0.9 */*;q=0.8 )] );
2623  
2624 Sets or gets the C<Accept> header field value. It takes either a string or an array or array reference of values.
2625  
2626 See L<rfc7231, section 5.3.2|https://tools.ietf.org/html/rfc7231#section-5.3.2> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept>
2627  
2628 See also L<HTTP::Promise::Headers::Accept>
2629  
2630 =head2 accept_charset
2631  
2632 $h->accept( 'utf-8' );
2633  
2634 Sets or gets the C<Accept-Charset> headers field value. It takes a single string value.
2635  
2636 You should know that the C<Accept-Charset> header is deprecated by HTTP standards and that no modern web browsers is sending nor any modern HTTP server recognising it.
2637  
2638 See L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Charset>
2639  
2640 =head2 accept_encoding
2641  
2642 $h->accept_encoding( 'gzip, deflate, br' );
2643 $h->accept_encoding( [qw( gzip deflate br )] );
2644 $h->accept_encoding( 'br;q=1.0, gzip;q=0.8, *;q=0.1' );
2645  
2646 Sets or gets the C<Accept-Encoding> header field value. It takes either a string or an array or array reference of values.
2647  
2648 See also L<HTTP::Promise::Headers::AcceptEncoding> to have a more granular control.
2649  
2650 Encoding header fields and their nuances:
2651  
2652 =over 4
2653  
2654 =item C<Accept-Encoding>
2655  
2656 The encodings accepted by the client.
2657  
2658 =item C<Content-Encoding>
2659  
2660 Contains the encodings that have been applied to the content, before transport
2661  
2662 =item C<TE>
2663  
2664 The encodings the user agent accepts.
2665  
2666 =item C<Transfer-Encoding>
2667  
2668 The encoding applied during transfer, such as C<chunked>
2669  
2670 =back
2671  
2672 See L<rfc7231, section 5.3.4|https://tools.ietf.org/html/rfc7231#section-5.3.4> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding>
2673  
2674 =head2 accept_language
2675  
2676 $h->accept_language( 'fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5' );
2677 $h->accept_language( [qw(fr-CH fr;q=0.9 en;q=0.8 de;q=0.7 *;q=0.5 )] );
2678  
2679 Sets or gets the C<Accept-Language> header field value. It takes either a string or an array or array reference of values.
2680  
2681 See also L<HTTP::Promise::Headers::AcceptLanguage> to have a more granular control.
2682  
2683 See L<rfc7231, section 5.3.5|https://tools.ietf.org/html/rfc7231#section-5.3.5> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language>
2684  
2685 =head2 accept_patch
2686  
2687 $h->accept_patch( 'application/example, text/example' );
2688 $h->accept_patch( [qw( application/example text/example )] );
2689 $h->accept_patch( 'text/example;charset=utf-8' );
2690 $h->accept_patch( 'application/merge-patch+json' );
2691  
2692 Sets or gets the C<Accept-Patch> header field value. It takes either a string or an array or array reference of values.
2693  
2694 This is a server response header.
2695  
2696 See L<rfc5789, section 3.1|https://tools.ietf.org/html/rfc5789#section-3.1>, L<rfc7231, section 4.3.4|https://tools.ietf.org/html/rfc7231#section-4.3.4> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Patch>
2697  
2698 =head2 accept_post
2699  
2700 $h->accept_post( 'application/example, text/example' );
2701 $h->accept_post( [qw( application/example text/example )] );
2702 $h->accept_post( 'image/webp' );
2703 $h->accept_post( '*/*' );
2704  
2705 Sets or gets the C<Accept-Post> header field value. It takes either a string or an array or array reference of values.
2706  
2707 This is a server response header.
2708  
2709 See L<rfc7231, section 4.3.3|https://tools.ietf.org/html/rfc7231#section-4.3.3> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Post>
2710  
2711 =head2 accept_ranges
2712  
2713 $h->accept_ranges(1234);
2714  
2715 Sets or gets the C<Accept-Ranges> header field value. It takes either a string or an array or array reference of values.
2716  
2717 This is a server response header.
2718  
2719 See L<rfc7233, section 2.3|https://tools.ietf.org/html/rfc7233#section-2.3> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Ranges>
2720  
2721 =head2 acceptables
2722  
2723 This returns a new L<HTTP::Promise::Headers::Accept> object based on the content of the C<Accept> header value.
2724  
2725 =head2 age
2726  
2727 $h->age(1234);
2728  
2729 Sets or gets the C<Age> header field value. It takes a numeric value.
2730  
2731 This is a server response header.
2732  
2733 See L<rfc7234, section 5.1|https://tools.ietf.org/html/rfc7234#section-5.1> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Age>
2734  
2735 =head2 allow
2736  
2737 $h->allow( 'GET, POST, HEAD' );
2738 $h->allow( [qw( GET POST HEAD )] );
2739  
2740 Sets or gets the C<Allow> header field value. It takes either a string or an array or array reference of values.
2741  
2742 This is a server response header.
2743  
2744 See L<rfc7231, section 7.4.1|https://tools.ietf.org/html/rfc7231#section-7.4.1> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Age>
2745  
2746 =head2 allow_credentials
2747  
2748 # Access-Control-Allow-Credentials: true
2749 $h->allow_credentials( 'true' );
2750  
2751 Sets or gets the C<Access-Control-Allow-Credentials> header field value. It takes a string boolean value: C<true> or C<false>.
2752  
2753 See L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials>
2754  
2755 =head2 allow_headers
2756  
2757 # Access-Control-Allow-Headers: X-Custom-Header, Upgrade-Insecure-Requests
2758 $h->allow_headers( 'X-Custom-Header, Upgrade-Insecure-Requests' );
2759 $h->allow_headers( [qw( X-Custom-Header Upgrade-Insecure-Requests )] );
2760  
2761 Sets or gets the C<Access-Control-Allow-Headers> header field value. It takes either a string or an array or array reference of values.
2762  
2763 This is a server response header.
2764  
2765 See L<rfc7231, section 7.4.1|https://tools.ietf.org/html/rfc7231#section-7.4.1> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Age>
2766  
2767 =head2 allow_methods
2768  
2769 # Access-Control-Allow-Methods: POST, GET, OPTIONS
2770 $h->allow_methods( 'POST, GET, OPTIONS' );
2771 $h->allow_methods( [qw( POST GET OPTIONS )] );
2772 # Access-Control-Allow-Methods: *
2773 $h->allow_methods( '*' );
2774  
2775 Sets or gets the C<Access-Control-Allow-Methods> header field value. It takes either a string or an array or array reference of values.
2776  
2777 This is a server response header.
2778  
2779 See L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods>
2780  
2781 =head2 allow_origin
2782  
2783 # Access-Control-Allow-Origin: *
2784 $h->allow_origin( '*' );
2785 # Access-Control-Allow-Origin: https://food.example.org
2786 $h->allow_origin( 'https://food.example.org' );
2787 # Access-Control-Allow-Origin: null
2788 $h->allow_origin( 'null' );
2789  
2790 Sets or gets the C<Access-Control-Allow-Origin> header field value. It takes a string value.
2791  
2792 This is a server response header.
2793  
2794 See L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods>
2795  
2796 =head2 alt_svc
2797  
2798 # Alt-Svc: h2=":443"; ma=2592000;
2799 $h->alt_svc( 'h2=":443"; ma=2592000' );
2800 # Alt-Svc: h2=":443"; ma=2592000; persist=1
2801 $h->alt_svc( 'h2=":443"; ma=2592000; persist=1' );
2802 # Alt-Svc: h2="alt.example.com:443", h2=":443"
2803 $h->alt_svc( 'h2="alt.example.com:443", h2=":443"' );
2804 # Alt-Svc: h3-25=":443"; ma=3600, h2=":443"; ma=3600
2805 $h->alt_svc( 'h3-25=":443"; ma=3600, h2=":443"; ma=3600' );
2806  
2807 Sets or gets the C<Alt-Svc> header field value. It takes either a string or an array or array reference of values.
2808  
2809 See also L<HTTP::Promise::Headers::AltSvc> to have a more granular control.
2810  
2811 See L<rfc7838, section 3|https://tools.ietf.org/html/rfc7838#section-3> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Alt-Svc>
2812  
2813 =head2 alternate_server
2814  
2815 This is a convenience method for the header field C<Alt-Svc>.
2816  
2817 To et it value, you provide a hash or hash reference of properties, including C<name> and C<value> respectively for the protocol-id and the alternate authority.
2818  
2819 $h->alternate_server( name => 'h2', value => ':443', ma => 2592000, persist => 1 );
2820  
2821 would create the header value:
2822  
2823 Alt-Svc: h2=":443"; ma=2592000; persist=1
2824  
2825 Without any parameter, it creates a new L<HTTP::Promise::Headers::AltSvc> object for each C<Alt-Svc> header value and returns an L<array object|Module::Generic::Array> of all those L<HTTP::Promise::Headers::AltSvc> objects.
2826  
2827 =head2 authorization
2828  
2829 # Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l
2830 $h->authorization( 'Basic YWxhZGRpbjpvcGVuc2VzYW1l' );
2831  
2832 Sets or gets the C<Authorization> header field value. It takes a string value.
2833  
2834 See also L</authorization_basic>
2835  
2836 See L<rfc7235, section 4.2|https://tools.ietf.org/html/rfc7235#section-4.2> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization>
2837  
2838 =head2 cache_control
2839  
2840 # Cache-Control: max-age=604800
2841 $h->cache_control( 'max-age=604800' );
2842 # Cache-Control: s-maxage=604800
2843 $h->cache_control( 's-maxage=604800' );
2844 # Cache-Control: no-cache
2845 $h->cache_control( 'no-cache' );
2846 # Cache-Control: max-age=604800, must-revalidate
2847 $h->cache_control( 'max-age=604800, must-revalidate' );
2848 # Cache-Control: public, max-age=604800, immutable
2849 $h->cache_control( 'public, max-age=604800, immutable' );
2850  
2851 Sets or gets the C<Cache-Control> header field value. It takes either a string or an array or array reference of values.
2852  
2853 See also L<HTTP::Promise::Headers::CacheControl> to have a more granular control.
2854  
2855 See L<rfc7234, section 5.2|https://tools.ietf.org/html/rfc7234#section-5.2> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control>
2856  
2857 =head2 clear_site_data
2858  
2859 # Clear-Site-Data: "cache", "cookies", "storage", "executionContexts"
2860 $h->clear_site_data( q{"cache", "cookies", "storage", "executionContexts"} );
2861 $h->clear_site_data( [qw( cache cookies storage executionContexts )] );
2862  
2863 The Clear-Site-Data header accepts one or more directives. If all types of data should be cleared, the wildcard directive ("*") can be used.
2864  
2865 See also L<HTTP::Promise::Headers::ClearSiteData> to have a more granular control.
2866  
2867 See L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Clear-Site-Data>
2868  
2869 =head2 connection
2870  
2871 # Connection: keep-alive
2872 # Connection: close
2873  
2874 Sets or gets the C<Connection> header field value. It takes a string value.
2875  
2876 See L<rfc7230, section 6.1|https://tools.ietf.org/html/rfc7230#section-6.1> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Connection>
2877  
2878 =head2 content_disposition
2879  
2880 # Content-Disposition: inline
2881 # Content-Disposition: attachment
2882 # Content-Disposition: attachment; filename="filename.jpg"
2883 # Content-Disposition: form-data; name="fieldName"
2884 # Content-Disposition: form-data; name="fieldName"; filename="filename.jpg"
2885  
2886 Sets or gets the C<Content-Disposition> header field value. It takes a string value.
2887  
2888 See also L<HTTP::Promise::Headers::ContentDisposition> to have a more granular control.
2889  
2890 See L<rfc6266, section 4|https://tools.ietf.org/html/rfc6266#section-4>, L<rfc7578, section 4.2|https://tools.ietf.org/html/rfc7578#section-4.2> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition>
2891  
2892 =head2 content_encoding
2893  
2894 # Content-Encoding: gzip
2895 # Content-Encoding: compress
2896 # Content-Encoding: deflate
2897 # Content-Encoding: br
2898  
2899 # Multiple, in the order in which they were applied
2900 # Content-Encoding: deflate, gzip
2901  
2902 Sets or gets the C<Cache-Encoding> header field value. It takes either a string or an array or array reference of values.
2903  
2904 Encoding header fields and their nuances:
2905  
2906 =over 4
2907  
2908 =item C<Accept-Encoding>
2909  
2910 The encodings accepted by the client.
2911  
2912 =item C<Content-Encoding>
2913  
2914 Contains the encodings that have been applied to the content, before transport
2915  
2916 =item C<TE>
2917  
2918 The encodings the user agent accepts.
2919  
2920 =item C<Transfer-Encoding>
2921  
2922 The encoding applied during transfer, such as C<chunked>
2923  
2924 =back
2925  
2926 See L<rfc7230, section 3.3.1|https://tools.ietf.org/html/rfc7230#section-3.3.1>:
2927 "Unlike Content-Encoding (L<Section 3.1.2.1 of [RFC7231]|https://tools.ietf.org/html/rfc7231#section-3.1.2.1>), Transfer-Encoding is a property of the message, not of the representation"
2928  
2929 See also L</accept_encoding>, L</transfer_encoding> and L</te> and this L<Stackoverflow discussion|https://stackoverflow.com/questions/11641923/transfer-encoding-gzip-vs-content-encoding-gzip>
2930  
2931 See L<rfc7231, section 3.1.2.2|https://tools.ietf.org/html/rfc7231#section-3.1.2.2> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding>
2932  
2933 =head2 content_language
2934  
2935 # Content-Language: de-DE
2936 # Content-Language: en-US
2937 $h->content_language( 'en-GB' );
2938 # Content-Language: de-DE, en-CA
2939 $h->content_language( 'de-DE, en-CA' );
2940 $h->content_language( [qw( de-DE en-CA )] );
2941  
2942 Sets or gets the C<Cache-Language> header field value. It takes either a string or an array or array reference of values.
2943  
2944 There is no enforcement on the value provided, so it is up to you to set the proper value or values.
2945  
2946 See L<rfc7231, section 3.1.3.2|https://tools.ietf.org/html/rfc7231#section-3.1.3.2>, L<rfc5646|https://tools.ietf.org/html/rfc5646> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Language>
2947  
2948 =head2 content_length
2949  
2950 # Content-Length: 72
2951 $h->content_length(72);
2952  
2953 Sets or gets the C<Connection> header field value. It takes a numeric value.
2954  
2955 See L<rfc7230, section 3.3.2|https://tools.ietf.org/html/rfc7230#section-3.3.2> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Length>
2956  
2957 =head2 content_location
2958  
2959 # Content-Location: /some/where/file.html
2960 $h->content_location( '/some/where/file.html' );
2961  
2962 Sets or gets the C<Connection> header field value. It takes a numeric value.
2963  
2964 See L<rfc7231, section 3.1.4.2|https://tools.ietf.org/html/rfc7231#section-3.1.4.2> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Location>
2965  
2966 =head2 content_range
2967  
2968 # Content-Range: bytes 200-1000/67589
2969 # Unsatisfiable range value
2970 # Content-Range: bytes */1234
2971  
2972 Sets or gets the C<Content-Range> header field value. It takes a string value.
2973  
2974 See also L<HTTP::Promise::Headers::ContentRange> to have a more granular control.
2975  
2976 See L<rfc7233, section 4.2|https://tools.ietf.org/html/rfc7233#section-4.2> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range>
2977  
2978 =head2 content_security_policy
2979  
2980 # Content-Security-Policy: default-src 'self' http://example.com;
2981 # connect-src 'none';
2982 # Content-Security-Policy: connect-src http://example.com/;
2983 # script-src http://example.com/
2984  
2985 Sets or gets the C<Content-Security-Policy> header field value. It takes a string value.
2986  
2987 See also L<HTTP::Promise::Headers::ContentSecurityPolicy> to have a more granular control.
2988  
2989 See L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy>
2990  
2991 =head2 content_security_policy_report_only
2992  
2993 # Content-Security-Policy-Report-Only: default-src https:; report-uri /csp-violation-report-endpoint/
2994  
2995 Sets or gets the C<Content-Security-Policy-Report-Only> header field value. It takes a string value of properly formatted header value.
2996  
2997 See also L<HTTP::Promise::Headers::ContentSecurityPolicyReportOnly> to have a more granular control.
2998  
2999 =head2 content_type
3000  
3001 This sets or gets the C<Content-Type> header value. It takes a string value.
3002  
3003 If a value is provided, this will set the header value. If no value is provided, this simply return the header field value.
3004  
3005 See also L<HTTP::Promise::Headers::ContentType> to have a more granular control.
3006  
3007 See also L<rfc7233, section 4.1|https://tools.ietf.org/html/rfc7233#section-4.1>, L<rfc7231, section 3.1.1.5|https://tools.ietf.org/html/rfc7231#section-3.1.1.5> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types>, and L<this Mozilla documentation too|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type>
3008  
3009 =head2 cross_origin_embedder_policy
3010  
3011 # Cross-Origin-Embedder-Policy: require-corp
3012 # Cross-Origin-Opener-Policy: same-origin
3013  
3014 This sets or gets the C<Cross-Origin-Embedder-Policy> header value. It takes a string value.
3015  
3016 It can have either of the following value: C<require-corp> or C<same-origin>
3017  
3018 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Embedder-Policy>
3019  
3020 =head2 cross_origin_opener_policy
3021  
3022 # Cross-Origin-Opener-Policy: unsafe-none
3023 # Cross-Origin-Opener-Policy: same-origin-allow-popups
3024 # Cross-Origin-Opener-Policy: same-origin
3025  
3026 This sets or gets the C<Cross-Origin-Opener-Policy> header value. It takes a string value.
3027  
3028 It can have either of the following value: C<unsafe-none> or C<same-origin-allow-popups> or C<same-origin>
3029  
3030 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy>
3031  
3032 =head2 cross_origin_resource_policy
3033  
3034 This sets or gets the C<Cross-Origin-Resource-Policy> header value. It takes a string value.
3035  
3036 It can have either of the following value: C<same-site> or C<same-origin> or C<same-origin>
3037  
3038 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy>
3039  
3040 For more example: L<https://resourcepolicy.fyi/>
3041  
3042 =head2 cspro
3043  
3044 This is an alias for L</content_security_policy_report_only>
3045  
3046 =head2 date
3047  
3048 This sets or gets the C<Date> header value. It takes a date string value, a unix timestamp or a L<DateTime> value.
3049  
3050 If no value is provided, it returns the current value of the C<Date> header field as a L<DateTime> object.
3051  
3052 =head2 device_memory
3053  
3054 # Device-Memory: 1
3055  
3056 This sets or gets the C<Device-Memory> header value. It takes a number.
3057  
3058 L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Device-Memory>
3059  
3060 =head2 digest
3061  
3062 # Digest: sha-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=
3063 # Digest: sha-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=,unixsum=30637
3064  
3065 This sets or gets the C<Digest> header value. It takes either a string or an array or array reference of properly formatted values.
3066  
3067 See L<draft rfc|https://tools.ietf.org/html/draft-ietf-httpbis-digest-headers-05#section-3> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Digest>
3068  
3069 =head2 dnt
3070  
3071 # DNT: 0
3072 # DNT: 1
3073 # DNT: null
3074  
3075 This sets or gets the C<DNT> header value. It takes a string value.
3076  
3077 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/DNT>
3078  
3079 =head2 early_data
3080  
3081 # Early-Data: 1
3082  
3083 This sets or gets the C<Early-Data> header value. It takes a string value.
3084  
3085 See also L<rfc8470, section 5.1|https://tools.ietf.org/html/rfc8470#section-5.1> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Early-Data>
3086  
3087 =head2 etag
3088  
3089 # ETag: "33a64df551425fcc55e4d42a148795d9f25f89d4"
3090 # ETag: W/"0815"
3091  
3092 This sets or gets the C<Etag> header value. It takes a string of properly formatted value.
3093  
3094 See also L<rfc7232, section 2.3|https://tools.ietf.org/html/rfc7232#section-2.3> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag>
3095  
3096 =head2 expect
3097  
3098 This sets or gets the C<Expect> header value. It takes a string of properly formatted value, typically C<100-continue>
3099  
3100 For example, before sending a very large file:
3101  
3102 PUT /some/where HTTP/1.1
3103 Host: origin.example.com
3104 Content-Type: video/h264
3105 Content-Length: 1234567890987
3106 Expect: 100-continue
3107  
3108 If the server is ok, it would return a C<100 Continue>
3109  
3110 See also L<rfc7231, section 5.1.1|https://tools.ietf.org/html/rfc7231#section-5.1.1> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expect>, L<interesting article|https://www.bram.us/2020/04/14/about-the-http-expect-100-continue-header/>
3111  
3112 =head2 expect_ct
3113  
3114 # Expect-CT: max-age=86400, enforce, report-uri="https://foo.example.com/report"
3115 $h->expect_ct( q{max-age=86400, enforce, report-uri="https://foo.example.com/report"} );
3116 $h->expect_ct( [qw( max-age=86400 enforce report-uri="https://foo.example.com/report" )] );
3117  
3118 This sets or gets the C<Expect-CT> header value. It takes a string of properly formatted value.
3119  
3120 See also L<HTTP::Promise::Headers::ExpectCT> to have a more granular control.
3121  
3122 See also L<rfc draft|https://tools.ietf.org/html/draft-ietf-httpbis-expect-ct-08> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expect-CT>
3123  
3124 =head2 expires
3125  
3126 This sets or gets the C<Expires> header value. It takes a date string value, a unix timestamp or a L<DateTime> value.
3127  
3128 If no value is provided, it returns the current value of the C<Date> header field as a L<DateTime> object.
3129  
3130 For example:
3131  
3132 Expires: Wed, 21 Oct 2015 07:28:00 GMT
3133  
3134 See also L<rfc7234, section 5.3|https://tools.ietf.org/html/rfc7234#section-5.3> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expires>
3135  
3136 =head2 expose_headers
3137  
3138 This sets or gets the C<Expose-Headers> header value. It takes either a string or an array or array reference of properly formatted values.
3139  
3140 For example:
3141  
3142 Access-Control-Expose-Headers: *, Authorization
3143  
3144 See also L<rfc7234, section 5.3|https://tools.ietf.org/html/rfc7234#section-5.3> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers>
3145  
3146 =head2 forwarded
3147  
3148 This sets or gets the C<Forwarded> header value. It takes either a string or an array or array reference of properly formatted values.
3149  
3150 See also L<HTTP::Promise::Headers::Forwarded> to have a more granular control.
3151  
3152 For example:
3153  
3154 Forwarded: for=192.0.2.60;proto=http;by=203.0.113.43
3155 # Values from multiple proxy servers can be appended using a comma
3156 Forwarded: for=192.0.2.43, for=198.51.100.17
3157  
3158 See also L<rfc7239, section 4|https://tools.ietf.org/html/rfc7239#section-4> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded>
3159  
3160 =head2 from
3161  
3162 This sets or gets the C<From> header value. It takes a string value.
3163  
3164 For example:
3165  
3166 From: webmaster@example.org
3167  
3168 See also L<rfc7231, section 5.5.1|https://tools.ietf.org/html/rfc7231#section-5.5.1> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/From>
3169  
3170 =head2 host
3171  
3172 This sets or gets the C<Host> header value. It takes a string value.
3173  
3174 For example:
3175  
3176 Host: dev.example.org
3177  
3178 See also L<rfc7230, section 5.4|https://tools.ietf.org/html/rfc7230#section-5.4> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Host>
3179  
3180 =head2 if_match
3181  
3182 This sets or gets the C<If-Match> header value. It takes a string value.
3183  
3184 For example:
3185  
3186 If-Match: "bfc13a64729c4290ef5b2c2730249c88ca92d82d"
3187 If-Match: "67ab43", "54ed21", "7892dd"
3188 If-Match: *
3189  
3190 See also L<rfc7232, section 3.1|https://tools.ietf.org/html/rfc7232#section-3.1> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match>
3191  
3192 =head2 if_modified_since
3193  
3194 This sets or gets the C<If-Modified-Since> header value. It takes a date string value, a unix timestamp or a L<DateTime> value.
3195  
3196 If no value is provided, it returns the current value of the C<Date> header field as a L<DateTime> object.
3197  
3198 For example:
3199  
3200 If-Modified-Since: Wed, 21 Oct 2015 07:28:00 GMT
3201  
3202 See also L<rfc7232, section 3.3|https://tools.ietf.org/html/rfc7232#section-3.3> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Modified-Since>
3203  
3204 =head2 if_none_match
3205  
3206 This sets or gets the C<If-None-Match> header value. It takes a string value.
3207  
3208 For example:
3209  
3210 If-None-Match: "bfc13a64729c4290ef5b2c2730249c88ca92d82d"
3211 If-None-Match: W/"67ab43", "54ed21", "7892dd"
3212 If-None-Match: *
3213  
3214 See also L<rfc7232, section 3.2|https://tools.ietf.org/html/rfc7232#section-3.2> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Modified-Since>
3215  
3216 =head2 if_range
3217  
3218 This sets or gets the C<If-Range> header value. It takes a string value.
3219  
3220 For example:
3221  
3222 If-Range: Wed, 21 Oct 2015 07:28:00 GMT
3223  
3224 See also L<rfc7233, section 3.2|https://tools.ietf.org/html/rfc7233#section-3.2> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Range>
3225  
3226 =head2 if_unmodified_since
3227  
3228 This sets or gets the C<If-Unmodified-Since> header value. It takes a date string value, a unix timestamp or a L<DateTime> value.
3229  
3230 If no value is provided, it returns the current value of the C<Date> header field as a L<DateTime> object.
3231  
3232 For example:
3233  
3234 If-Unmodified-Since: Wed, 21 Oct 2015 07:28:00 GMT
3235  
3236 See also L<rfc7232, section 3.4|https://tools.ietf.org/html/rfc7232#section-3.4> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Unmodified-Since>
3237  
3238 =head2 keep_alive
3239  
3240 This sets or gets the C<Keep-Alive> header value. It takes either a string or an array or array reference of properly formatted values.
3241  
3242 See also L<HTTP::Promise::Headers::KeepAlive> to have a more granular control.
3243  
3244 Example response containing a Keep-Alive header:
3245  
3246 HTTP/1.1 200 OK
3247 Connection: Keep-Alive
3248 Content-Encoding: gzip
3249 Content-Type: text/html; charset=utf-8
3250 Date: Thu, 11 Aug 2016 15:23:13 GMT
3251 Keep-Alive: timeout=5, max=1000
3252 Last-Modified: Mon, 25 Jul 2016 04:32:39 GMT
3253 Server: Apache
3254  
3255 See also L<rfc7230, section A.1.2|https://tools.ietf.org/html/rfc7230#section-A.1.2> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive>
3256  
3257 =head2 last_modified
3258  
3259 This sets or gets the C<Last-Modified> header value. It takes a date string value, a unix timestamp or a L<DateTime> value.
3260  
3261 If no value is provided, it returns the current value of the C<Date> header field as a L<DateTime> object.
3262  
3263 For example:
3264  
3265 Last-Modified: Wed, 21 Oct 2015 07:28:00 GMT
3266  
3267 See also L<rfc7232, section 2.2|https://tools.ietf.org/html/rfc7232#section-2.2> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Last-Modified>
3268  
3269 =head2 link
3270  
3271 This sets or gets the C<Link> header value. It takes a string value.
3272  
3273 See also L<HTTP::Promise::Headers::Link> to have a more granular control.
3274  
3275 Example:
3276  
3277 Link: <https://example.com>; rel="preconnect"
3278  
3279 See also L<rfc8288, section 3|https://tools.ietf.org/html/rfc8288#section-3> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link>
3280  
3281 =head2 location
3282  
3283 This sets or gets the C<Location> header value. It takes a string value.
3284  
3285 Example:
3286  
3287 Location: /index.html
3288  
3289 See also L<rfc7231, section 7.1.2|https://tools.ietf.org/html/rfc7231#section-7.1.2> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location>
3290  
3291 =head2 max_age
3292  
3293 This sets or gets the C<Location> header value. It takes a numeric value.
3294  
3295 Example:
3296  
3297 Access-Control-Max-Age: 600
3298  
3299 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age>
3300  
3301 =head2 nel
3302  
3303 This sets or gets the C<NEL> header value. It takes a string of properly formatted json value.
3304  
3305 Example:
3306  
3307 NEL: { "report_to": "name_of_reporting_group", "max_age": 12345, "include_subdomains": false, "success_fraction": 0.0, "failure_fraction": 1.0 }
3308  
3309 See also L<rfc8288, section 3|https://tools.ietf.org/html/rfc8288#section-3> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/NEL>
3310  
3311 =for Pod::Coverage new_array
3312  
3313 =for Pod::Coverage new_field
3314  
3315 =for Pod::Coverage new_number
3316  
3317 =for Pod::Coverage new_scalar
3318  
3319 =head2 origin
3320  
3321 This sets or gets the C<Origin> header value. It takes a string of properly formatted json value.
3322  
3323 Example:
3324  
3325 Origin: http://dev.example.org:80
3326  
3327 See also L<rfc6454, section 7|https://tools.ietf.org/html/rfc6454#section-7> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin>
3328  
3329 =for Pod::Coverage pass_error
3330  
3331 =head2 proxy
3332  
3333 Sets or gets the URI used for the proxy. It returns a L<URI> object.
3334  
3335 =head2 proxy_authenticate
3336  
3337 This sets or gets the C<Proxy-Authenticate> header value. It takes a string value.
3338  
3339 Example:
3340  
3341 Proxy-Authenticate: Basic realm="Access to the internal site"
3342  
3343 See also L<rfc6454, section 7|https://tools.ietf.org/html/rfc6454#section-7> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Proxy-Authenticate>
3344  
3345 =head2 proxy_authorization
3346  
3347 This sets or gets the C<Proxy-Authorization> header value. It takes a string value.
3348  
3349 Example:
3350  
3351 Proxy-Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l
3352  
3353 See also L<rfc7235, section 4.4|https://tools.ietf.org/html/rfc7235#section-4.4> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Proxy-Authorization>
3354  
3355 =head2 range
3356  
3357 This sets or gets the C<Range> header value. It takes a string value.
3358  
3359 See also L<HTTP::Promise::Headers::Range> to have a more granular control.
3360  
3361 Example:
3362  
3363 Range: bytes=200-1000, 2000-6576, 19000-
3364  
3365 See also L<rfc7233, section 3.1|https://tools.ietf.org/html/rfc7233#section-3.1> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range>
3366  
3367 =head2 referer
3368  
3369 This sets or gets the C<Referer> header value. It takes a string value.
3370  
3371 Example:
3372  
3373 Referer: https://dev.example.org/some/where
3374 Referer: https://example.org/page?q=123
3375 Referer: https://example.org/
3376  
3377 See also L<rfc7231, section 5.5.2|https://tools.ietf.org/html/rfc7231#section-5.5.2> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer>
3378  
3379 =head2 referrer
3380  
3381 This is an alias for L</referer>
3382  
3383 =head2 referrer_policy
3384  
3385 This sets or gets the C<Referrer-Policy> header value. It takes a string value.
3386  
3387 The allowed values can be: C<no-referrer>, C<no-referrer-when-downgrade>, C<origin>, C<origin-when-cross-origin>, C<same-origin>, C<strict-origin>, C<strict-origin-when-cross-origin>, C<unsafe-url>
3388  
3389 Example:
3390  
3391 Referrer-Policy: no-referrer
3392 # With fallback
3393 Referrer-Policy: no-referrer, strict-origin-when-cross-origin
3394  
3395 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy>
3396  
3397 =head2 request_headers
3398  
3399 This sets or gets the C<Access-Control-Request-Headers> header value. It takes a string value.
3400  
3401 Example:
3402  
3403 Access-Control-Request-Headers: X-PINGOTHER, Content-Type
3404  
3405 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Request-Headers>
3406  
3407 =head2 request_method
3408  
3409 This sets or gets the C<Access-Control-Request-Method> header value. It takes a string value.
3410  
3411 Example:
3412  
3413 Access-Control-Request-Method: POST
3414  
3415 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Request-Method>
3416  
3417 =head2 retry_after
3418  
3419 This sets or gets the C<Retry-After> header value. It takes a string value.
3420  
3421 Example:
3422  
3423 Retry-After: Wed, 21 Oct 2015 07:28:00 GMT
3424 Retry-After: 120
3425  
3426 See also L<rfc7231, section 7.1.3|https://tools.ietf.org/html/rfc7231#section-7.1.3> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After>
3427  
3428 =head2 save_data
3429  
3430 This sets or gets the C<Save-Data> header value. It takes a string value.
3431  
3432 The value can be either C<on> or C<off>
3433  
3434 Example:
3435  
3436 Save-Data: on
3437  
3438 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Save-Data>
3439  
3440 =head2 server
3441  
3442 This sets or gets the C<Server> header value. It takes a string value.
3443  
3444 Example:
3445  
3446 Server: Apache/2.4.1 (Unix)
3447  
3448 See also L<rfc7231, section 7.4.2|https://tools.ietf.org/html/rfc7231#section-7.4.2> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server>
3449  
3450 =head2 server_timing
3451  
3452 This sets or gets the C<Server> header value. It takes a string value.
3453  
3454 See also L<HTTP::Promise::Headers::ServerTiming> to have a more granular control.
3455  
3456 Example:
3457  
3458 # Single metric without value
3459 Server-Timing: missedCache
3460  
3461 # Single metric with value
3462 Server-Timing: cpu;dur=2.4
3463  
3464 # Single metric with description and value
3465 Server-Timing: cache;desc="Cache Read";dur=23.2
3466  
3467 # Two metrics with value
3468 Server-Timing: db;dur=53, app;dur=47.2
3469  
3470 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server-Timing>
3471  
3472 =head2 set_cookie
3473  
3474 This sets or gets the C<Set-Cookie> header value. It takes a string value.
3475  
3476 See also L<Cookie> to have a more granular control.
3477  
3478 Example:
3479  
3480 Set-Cookie: sessionId=38afes7a8
3481 Set-Cookie: __Secure-ID=123; Secure; Domain=example.com
3482 Set-Cookie: __Host-ID=123; Secure; Path=/
3483  
3484 See also L<rfc6265, section 4.1|https://tools.ietf.org/html/rfc6265#section-4.1> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie>
3485  
3486 =head2 sourcemap
3487  
3488 This sets or gets the C<SourceMap> header value. It takes a string value.
3489  
3490 Example:
3491  
3492 SourceMap: /path/to/file.js.map
3493  
3494 See also L<draft specifications|https://sourcemaps.info/spec.html> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/SourceMap>
3495  
3496 =head2 strict_transport_security
3497  
3498 This sets or gets the C<Strict-Transport-Security> header value. It takes a string value.
3499  
3500 See also L<HTTP::Promise::Headers::StrictTransportSecurity> to have a more granular control.
3501  
3502 Example:
3503  
3504 Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
3505  
3506 See also L<rfc6797, section 6.1|https://tools.ietf.org/html/rfc6797#section-6.1> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security>
3507  
3508 =head2 te
3509  
3510 This sets or gets the C<TE> header value. It takes a string value.
3511  
3512 See also L<HTTP::Promise::Headers::TE> to have a more granular control.
3513  
3514 Example:
3515  
3516 TE: deflate
3517 TE: gzip
3518 TE: trailers
3519  
3520 # Multiple directives, weighted with the quality value syntax:
3521 TE: trailers, deflate;q=0.5
3522  
3523 Notably, the value C<trailers> means the HTTP client support trailers, which are a set of headers sent after the body.
3524  
3525 Encoding header fields and their nuances:
3526  
3527 =over 4
3528  
3529 =item C<Accept-Encoding>
3530  
3531 The encodings accepted by the client.
3532  
3533 =item C<Content-Encoding>
3534  
3535 Contains the encodings that have been applied to the content, before transport
3536  
3537 =item C<TE>
3538  
3539 The encodings the user agent accepts.
3540  
3541 =item C<Transfer-Encoding>
3542  
3543 The encoding applied during transfer, such as C<chunked>
3544  
3545 =back
3546  
3547 See also L</transfer_encoding>, L<rfc7230, section 4.3|https://tools.ietf.org/html/rfc7230#section-4.3> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/TE>, L<article on trailers|https://httptoolkit.tech/blog/http-wtf/#http-trailers>
3548  
3549 =head2 timing_allow_origin
3550  
3551 This sets or gets the C<Timing-Allow-Origin> header value. It takes a string value.
3552  
3553 Example:
3554  
3555 Timing-Allow-Origin: *
3556 Timing-Allow-Origin: https://dev.example.org, https://example.com
3557  
3558 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Timing-Allow-Origin>
3559  
3560 =head2 title
3561  
3562 Sets or gets the C<Title> of the HTML document if that were the case. This is here for legacy.
3563  
3564 =head2 tk
3565  
3566 This sets or gets the deprecated C<Tk> header value. It takes a string value.
3567  
3568 Example:
3569  
3570 Tk: N
3571  
3572 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Tk>
3573  
3574 =head2 trailer
3575  
3576 This sets or gets the C<Trailer> header value. It takes a string value.
3577  
3578 Example:
3579  
3580 Trailer: Expires
3581  
3582 See also L<rfc7230, section 4.4|https://tools.ietf.org/html/rfc7230#section-4.4>, L<rfc7230, section 4.1.2|https://tools.ietf.org/html/rfc7230#section-4.1.2> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Trailer>
3583  
3584 =head2 transfer_encoding
3585  
3586 This sets or gets the C<Transfer-Encoding> header value. It takes a string value.
3587  
3588 Example:
3589  
3590 Transfer-Encoding: chunked
3591 Transfer-Encoding: compress
3592 Transfer-Encoding: deflate
3593 Transfer-Encoding: gzip
3594  
3595 # Several values can be listed, separated by a comma
3596 Transfer-Encoding: gzip, chunked
3597  
3598 Encoding header fields and their nuances:
3599  
3600 =over 4
3601  
3602 =item C<Accept-Encoding>
3603  
3604 The encodings accepted by the client.
3605  
3606 =item C<Content-Encoding>
3607  
3608 Contains the encodings that have been applied to the content, before transport
3609  
3610 =item C<TE>
3611  
3612 The encodings the user agent accepts.
3613  
3614 =item C<Transfer-Encoding>
3615  
3616 The encoding applied during transfer, such as C<chunked>
3617  
3618 =back
3619  
3620 See L<rfc7230, section 3.3.1|https://tools.ietf.org/html/rfc7230#section-3.3.1>:
3621 "Unlike Content-Encoding (L<Section 3.1.2.1 of [RFC7231]|https://tools.ietf.org/html/rfc7231#section-3.1.2.1>), Transfer-Encoding is a property of the message, not of the representation"
3622  
3623 See also L</te>, L<rfc7230, section 3.3.1|https://tools.ietf.org/html/rfc7230#section-3.3.1> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Transfer-Encoding> and L<Wikipedia|https://en.wikipedia.org/wiki/Chunked_transfer_encoding>
3624  
3625 =head2 upgrade
3626  
3627 This sets or gets the C<Upgrade> header value. It takes a string value.
3628  
3629 Example:
3630  
3631 Connection: upgrade
3632 Upgrade: HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11
3633  
3634 Connection: Upgrade
3635 Upgrade: websocket
3636  
3637 See also L<rfc7230, section 6.7|https://tools.ietf.org/html/rfc7230#section-6.7>, L<rfc7231, section 6.6.15|https://tools.ietf.org/html/rfc7231#section-6.6.15>, L<rfc7240, section 8.1.1|https://tools.ietf.org/html/rfc7240#section-8.1.1> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Upgrade>
3638  
3639 =head2 upgrade_insecure_requests
3640  
3641 This sets or gets the C<Upgrade-Insecure-Requests> header value. It takes a string value.
3642  
3643 Example:
3644  
3645 Upgrade-Insecure-Requests: 1
3646  
3647 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Upgrade-Insecure-Requests>
3648  
3649 =head2 user_agent
3650  
3651 This sets or gets the C<User-Agent> header value. It takes a string value.
3652  
3653 Example:
3654  
3655 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0
3656 User-Agent: curl/7.64.1
3657  
3658 See also L<rfc7231, section 5.5.3|https://tools.ietf.org/html/rfc7231#section-5.5.3> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent>
3659  
3660 =head2 vary
3661  
3662 This sets or gets the C<Vary> header value. It takes a string value.
3663  
3664 Example:
3665  
3666 Vary: *
3667 Vary: Accept-Encoding, User-Agent
3668  
3669 See also L<rfc7231, section 7.1.4|https://tools.ietf.org/html/rfc7231#section-7.1.4> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Vary>
3670  
3671 =head2 via
3672  
3673 This sets or gets the C<Via> header value. It takes a string value.
3674  
3675 Example:
3676  
3677 Via: 1.1 vegur
3678 Via: HTTP/1.1 GWA
3679 Via: 1.0 fred, 1.1 p.example.net
3680  
3681 See also L<rfc7230, section 5.7.1|https://tools.ietf.org/html/rfc7230#section-5.7.1> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Via>
3682  
3683 =head2 want_digest
3684  
3685 This sets or gets the C<Want-Digest> header value. It takes a string value.
3686  
3687 Example:
3688  
3689 Want-Digest: sha-256
3690 Want-Digest: SHA-512;q=0.3, sha-256;q=1, md5;q=0
3691  
3692 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Want-Digest>
3693  
3694 =head2 warning
3695  
3696 This sets or gets the C<Warning> header value. It takes a string value.
3697  
3698 Example:
3699  
3700 Warning: 110 anderson/1.3.37 "Response is stale"
3701  
3702 See also L<rfc7234, section 5.5|https://tools.ietf.org/html/rfc7234#section-5.5> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Warning>
3703  
3704 =head2 www_authenticate
3705  
3706 This sets or gets the C<WWW-Authenticate> header value. It takes a string value.
3707  
3708 Example:
3709  
3710 WWW-Authenticate: Basic realm="Access to the staging site", charset="UTF-8"
3711 WWW-Authenticate: Digest
3712 realm="http-auth@example.org",
3713 qop="auth, auth-int",
3714 algorithm=SHA-256,
3715 nonce="7ypf/xlj9XXwfDPEoM4URrv/xwf94BcCAzFZH4GiTo0v",
3716 opaque="FQhe/qaU925kfnzjCev0ciny7QMkPqMAFRtzCUYo5tdS"
3717 WWW-Authenticate: Digest
3718 realm="http-auth@example.org",
3719 qop="auth, auth-int",
3720 algorithm=MD5,
3721 nonce="7ypf/xlj9XXwfDPEoM4URrv/xwf94BcCAzFZH4GiTo0v",
3722 opaque="FQhe/qaU925kfnzjCev0ciny7QMkPqMAFRtzCUYo5tdS"
3723  
3724 See also L<rfc7235, section 4.1|https://tools.ietf.org/html/rfc7235#section-4.1> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/WWW-Authenticate>
3725  
3726 =head2 x
3727  
3728 Sets or gets an arbitrary C<X-*> header. For example:
3729  
3730 $h->x( 'Spip-Cache' => 3600 );
3731  
3732 would set the C<X-Spip-Cache> header value to C<3600>
3733  
3734 my $value = $h->x( 'Spip-Cache' );
3735  
3736 =head2 x_content_type_options
3737  
3738 This sets or gets the C<X-Content-Type-Options> header value. It takes a string value.
3739  
3740 Example:
3741  
3742 X-Content-Type-Options: nosniff
3743  
3744 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options>
3745  
3746 =head2 x_dns_prefetch_control
3747  
3748 This sets or gets the C<X-DNS-Prefetch-Control> header value. It takes a string value.
3749  
3750 Example:
3751  
3752 X-DNS-Prefetch-Control: on
3753 X-DNS-Prefetch-Control: off
3754  
3755 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-DNS-Prefetch-Control>
3756  
3757 =head2 x_forwarded_for
3758  
3759 This sets or gets the C<X-Forwarded-For> header value. It takes a string value.
3760  
3761 Example:
3762  
3763 X-Forwarded-For: 2001:db8:85a3:8d3:1319:8a2e:370:7348
3764 X-Forwarded-For: 203.0.113.195
3765 X-Forwarded-For: 203.0.113.195, 2001:db8:85a3:8d3:1319:8a2e:370:7348
3766  
3767 See also L</host>, L</forwarded>, L</x_forwarded_host>, L</x_forwarded_proto>, L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For>
3768  
3769 =head2 x_forwarded_host
3770  
3771 This sets or gets the C<X-Forwarded-Host> header value. It takes a string value.
3772  
3773 Example:
3774  
3775 X-Forwarded-Host: id42.example-cdn.com
3776  
3777 See also L</host>, L</forwarded>, L</x_forwarded_for>, L</x_forwarded_proto>, L<https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host>
3778  
3779 =head2 x_forwarded_proto
3780  
3781 This sets or gets the C<X-Forwarded-Proto> header value. It takes a string value.
3782  
3783 Example:
3784  
3785 X-Forwarded-Proto: https
3786  
3787 See also L</host>, L</forwarded>, L</x_forwarded_for>, L</x_forwarded_host>, L<https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto>
3788  
3789 =head2 x_frame_options
3790  
3791 This sets or gets the C<X-Frame-Options> header value. It takes a string value.
3792  
3793 Example:
3794  
3795 X-Frame-Options: DENY
3796 X-Frame-Options: SAMEORIGIN
3797  
3798 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options>
3799  
3800 =head2 x_xss_protection
3801  
3802 This sets or gets the C<X-XSS-Protection> header value. It takes a string value.
3803  
3804 Example:
3805  
3806 X-XSS-Protection: 0
3807 X-XSS-Protection: 1
3808 X-XSS-Protection: 1; mode=block
3809 X-XSS-Protection: 1; report=https://example.org/some/where
3810  
3811 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection>
3812  
3813 =for Pod::Coverage STORABLE_thaw_post_processing
3814  
3815 =head1 THREAD-SAFETY
3816  
3817 This module is thread-safe for all operations, as it operates on per-object state and uses thread-safe external libraries.
3818  
3819 =head1 AUTHOR
3820  
3821 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
3822  
3823 =head1 SEE ALSO
3824  
3825 L<Mozilla documentation on HTTP headers|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers>
3826  
3827 L<HTTP::Promise::Headers::AcceptEncoding>, L<HTTP::Promise::Headers::AcceptLanguage>, L<HTTP::Promise::Headers::Accept>, L<HTTP::Promise::Headers::AltSvc>, L<HTTP::Promise::Headers::CacheControl>, L<HTTP::Promise::Headers::ClearSiteData>, L<HTTP::Promise::Headers::ContentDisposition>, L<HTTP::Promise::Headers::ContentRange>, L<HTTP::Promise::Headers::ContentSecurityPolicy>, L<HTTP::Promise::Headers::ContentSecurityPolicyReportOnly>, L<HTTP::Promise::Headers::ContentType>, L<HTTP::Promise::Headers::Cookie>, L<HTTP::Promise::Headers::ExpectCT>, L<HTTP::Promise::Headers::Forwarded>, L<HTTP::Promise::Headers::Generic>, L<HTTP::Promise::Headers::KeepAlive>, L<HTTP::Promise::Headers::Link>, L<HTTP::Promise::Headers::Range>, L<HTTP::Promise::Headers::ServerTiming>, L<HTTP::Promise::Headers::StrictTransportSecurity>, L<HTTP::Promise::Headers::TE>
3828  
3829 L<rfc7230, section 3.2 on headers field names|https://tools.ietf.org/html/rfc7230#section-3.2>,
3830 L<rfc6838 on mime types|https://tools.ietf.org/html/rfc6838>
3831  
3832 L<HTTP::Promise>, L<HTTP::Promise::Request>, L<HTTP::Promise::Response>, L<HTTP::Promise::Message>, L<HTTP::Promise::Entity>, L<HTTP::Promise::Headers>, L<HTTP::Promise::Body>, L<HTTP::Promise::Body::Form>, L<HTTP::Promise::Body::Form::Data>, L<HTTP::Promise::Body::Form::Field>, L<HTTP::Promise::Status>, L<HTTP::Promise::MIME>, L<HTTP::Promise::Parser>, L<HTTP::Promise::IO>, L<HTTP::Promise::Stream>, L<HTTP::Promise::Exception>
3833  
3834 =head1 COPYRIGHT & LICENSE
3835  
3836 Copyright(c) 2022 DEGUEST Pte. Ltd.
3837  
3838 All rights reserved
3839 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
3840  
3841 =cut
« blib/lib/HTTP/Promise/Stream.pm ↑ Summary blib/lib/HTTP/Promise/Entity.pm »