lib/HTTP/Promise/Headers/Generic.pm

filter: Statementstmt 72.7% 248 / 341 Branchbran 43.6% 75 / 172 Conditioncond 42.2% 41 / 97 MC/DCmcdc 20.0% 11 / 55 Subroutinesub 79.6% 51 / 64 Podpod 66.6% 4 / 6 totaltotal 58.5% 430 / 735 CC 132 SCAR 38.2
CC
132
Cov
60%
_qv_match
240.0
_qv_match_wildcard
182.0
_set_get_property_value
83.7
CRAP 45.8
« lib/HTTP/Promise/Headers/AltSvc.pm ↑ Summary lib/HTTP/Promise/Body/Form.pm »
1 ##----------------------------------------------------------------------------
2 ## Asynchronous HTTP Request and Promise - ~/lib/HTTP/Promise/Headers/Generic.pm
3 ## Version v0.1.3
4 ## Copyright(c) 2025 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2022/05/06
7 ## Modified 2025/10/15
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::Generic;
15 BEGIN
16 {
17 8 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 8 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 8 ▶ warnings::register_categories( 'HTTP::Promise' );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 8 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 8 ▶ use vars qw( $VERSION $QV_ELEMENT $QV_VALUE );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 8 ▶ use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 8 ▶ use URI::Escape::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 8 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 use overload (
26 '""' => 'as_string',
27 532 ▶ 'bool' => sub{1},
Subroutine __ANON__: called CC=1 SCAR=0.0
28 # No fallback on purpose
29 8 ▶ );
Subroutine BEGIN: called CC=1 SCAR=0.0
30 # Accept: audio/*; q=0.2, audio/basic
31 8 our $QV_ELEMENT = qr/(?:[^\;\,]+)/;
32 8 our $QV_VALUE = qr/(?:0(?:\.[0-9]{0,3})?|1(?:\.0{0,3})?)/;
33 8 our $VERSION = 'v0.1.3';
34 };
35  
36 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 0 ▶sub as_string { return( shift->value ); }
Subroutine as_string: not called CC=1 SCAR=6.9
Pod documented
40  
41 0 ▶sub field_name { return( shift->_set_get_scalar( '_name', @_ ) ); }
Subroutine field_name: not called CC=1 SCAR=6.9
Pod documented
42  
43 2 ▶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
44  
45 # By default and superseded by inheriting classes such as Content-Type that has more
46 # elaborate value with parameters
47 0 ▶sub value { return( shift->_set_get_scalar( '_value', @_ ) ); }
Subroutine value: not called CC=1 SCAR=6.9
Pod documented
48  
49 174 ▶sub _field_name { return( shift->_set_get_scalar( '_name', @_ ) ); }
Subroutine _field_name: called CC=1 SCAR=0.0
50  
51 # rfc2231 <https://tools.ietf.org/html/rfc2231>
52 sub _filename_decode
53 {
54 7 ▶ my $self = shift( @_ );
Subroutine _filename_decode: called CC=4 SCAR=14.3
55 7 my $fname = shift( @_ );
56 7 ▶ $self->_load_class( 'HTTP::Promise::Headers' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTTP::Promise::Headers") or return $self->pass_error 0 7 7
57 7 my( $new_fname, $charset, $lang ) = HTTP::Promise::Headers->decode_filename( $fname );
58 7 ▶ if( defined( $new_fname ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new_fname) 7 0 7
59 {
60 7 $fname = $new_fname;
61 }
62 7 ▶ return( wantarray() ? ( $fname, $charset, $lang ) : $fname );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 7 0 7
63 }
64  
65 # rfc2231 <https://tools.ietf.org/html/rfc2231>
66 sub _filename_encode
67 {
68 5 ▶ my $self = shift( @_ );
Subroutine _filename_encode: called CC=3 SCAR=11.0
69 5 my $fname = shift( @_ );
70 5 my $lang = shift( @_ );
71 5 ▶ if( $fname =~ /[^\x00-\x7f]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($fname =~ /[^\x00-\x7f]/) 2 3 5
72 {
73 2 ▶ $lang = '' if( !defined( $lang ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lang 0 2 2
74 2 return( sprintf( "UTF-8'${lang}'%s", $self->uri_escape_utf8( $fname ) ) );
75 }
76 # Nothing to be done. We return undef on purpose to indicate nothing was done
77 3 return;
78 }
79  
80 280 ▶sub _hv { return( shift->_set_get_object_without_init( '_hv', 'Module::Generic::HeaderValue', @_ ) ); }
Subroutine _hv: called CC=1 SCAR=0.0
81  
82 sub _hv_as_string
83 {
84 44 ▶ my $self = shift( @_ );
Subroutine _hv_as_string: called CC=2 SCAR=7.0
85 44 my $hv = $self->_hv;
86 44 ▶ return( '' ) if( !$hv );
Branch: 1 branch
BranchTrueFalseTotal
unless $hv 0 44 44
87 44 return( $hv->as_string( @_ ) );
88 }
89  
90 sub _get_header_value_object
91 {
92 0 ▶ my $self = shift( @_ );
Subroutine _get_header_value_object: not called CC=3 SCAR=24.8
93 0 ▶ $self->_load_class( 'Module::Generic::HeaderValue' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::HeaderValue") or return $self->pass_error 0 0 0
94 return( $self->pass_error );
95 0 ▶ my $hv = Module::Generic::HeaderValue->new( shift( @_ ) ) ||
Condition0%0/2
'Module::Generic::HeaderValue'->new(shift @_) || (return $self->pass_error('Module::Generic::HeaderValue'->error))
l!l
00
MC/DC0%0/1
'Module::Generic::HeaderValue'->new(shift @_) || (return $self->pass_error('Module::Generic::HeaderValue'->error))
'Module::Generic::HeaderValue'->new(shift @_)
Truth table0%0/2
A
A= 'Module::Generic::HeaderValue'->new(shift @_)
Aresult
11
00
96 return( $self->pass_error( Module::Generic::HeaderValue->error ) );
97 0 return( $hv );
98 }
99  
100 0 ▶sub _make_boundary { return( Data::UUID->new->create_str ); }
Subroutine _make_boundary: not called CC=1 SCAR=6.9
101  
102 sub _new_hv
103 {
104 11 ▶ my $self = shift( @_ );
Subroutine _new_hv: called CC=2 SCAR=7.1
105 11 ▶ $self->_load_class( 'Module::Generic::HeaderValue' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::HeaderValue") or return $self->pass_error 0 11 11
106 11 return( Module::Generic::HeaderValue->new( @_ ) );
107 }
108  
109 sub _new_qv_object
110 {
111 52 ▶ my $self = shift( @_ );
Subroutine _new_qv_object: called CC=2 SCAR=7.0
112 52 my $o = HTTP::Promise::Field::QualityValue->new( @_ );
113 52 ▶ return( $self->pass_error( HTTP::Promise::Field::QualityValue->error ) ) if( !defined( $o ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o 0 52 52
114 52 return( $o );
115 }
116  
117 sub _parse_header_value
118 {
119 66 ▶ my $self = shift( @_ );
Subroutine _parse_header_value: called CC=5 SCAR=17.8
120 66 my $this = shift( @_ );
121 66 ▶ return( $self->error( "No header value was provided to parse." ) ) if( !defined( $this ) || !length( "$this" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this and length "$this" 0 66 66
Condition33%1/3
defined $this and length "$this"
!ll&&!rl&&r
0066
MC/DC0%0/2
defined $this and length "$this"
defined $this length "$this"
Truth table33%1/3
A and B
A= defined $thisB= length "$this"
ABresult
0X0
100
111
122 66 ▶ $self->_load_class( 'Module::Generic::HeaderValue' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::HeaderValue") or return $self->pass_error 0 66 66
123 return( $self->pass_error );
124 66 ▶ my $hv = Module::Generic::HeaderValue->new_from_header( $this, @_ ) ||
Condition50%1/2
'Module::Generic::HeaderValue'->new_from_header($this, @_) || (return $self->pass_error('Module::Generic::HeaderValue'->error))
l!l
660
MC/DC0%0/1
'Module::Generic::HeaderValue'->new_from_header($this, @_) || (return $self->pass_error('Module::Generic::HeaderValue'->error))
'Module::Generic::HeaderValue'->new_from_header($this, @_)
Truth table50%1/2
A
A= 'Module::Generic::HeaderValue'->new_from_header($this, @_)
Aresult
11
00
125 return( $self->pass_error( Module::Generic::HeaderValue->error ) );
126 66 return( $hv );
127 }
128  
129 # rfc7231, section 5.3.1
130 # <https://tools.ietf.org/html/rfc7231#section-5.3.1>
131 sub _parse_quality_value
132 {
133 15 ▶ my $self = shift( @_ );
Subroutine _parse_quality_value: called CC=5 SCAR=16.6
134 15 my $str = shift( @_ );
135 15 ▶ return( $self->error( "No header value was provided to parse." ) ) if( !defined( $str ) || !length( "$str" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str and length "$str" 0 15 15
Condition33%1/3
defined $str and length "$str"
!ll&&!rl&&r
0015
MC/DC0%0/2
defined $str and length "$str"
defined $str length "$str"
Truth table33%1/3
A and B
A= defined $strB= length "$str"
ABresult
0X0
100
111
136 # No blank
137 15 $str =~ s/[[:blank:]\h]]+//g;
138 15 my $choices = $self->new_array;
139 # Credits: HTTP::AcceptLanguage from Kazuhiro Osawa
140 15 for my $def ( split( /,[[:blank:]\h]*/, $str ) )
141 {
142 52 my( $element, $quality ) = $def =~ /\A($QV_ELEMENT)(?:;[[:blank:]\h]*[qQ]=($QV_VALUE))?\z/;
143 # rfc7231, section 5.3.1:
144 # "If no "q" parameter is present, the default weight is 1."
145 # rfc7231, section 5.3.5
146 # "no value is the same as q=1"
147 # $quality = 1 unless( defined( $quality ) );
148 # next unless( $element && $quality > 0 );
149 52 ▶ next unless( $element );
Branch: 1 branch
BranchTrueFalseTotal
unless $element 0 52 52
150 52 my $qv = $self->_new_qv_object( $element => $quality );
151 52 $choices->push( $qv );
152 }
153 15 return( $choices );
154 }
155  
156 sub _qstring_join
157 {
158 8 ▶ my $self = shift( @_ );
Subroutine _qstring_join: called CC=2 SCAR=6.9
159 8 my @parts = ();
160 8 foreach my $s ( @_ )
161 {
162 34 $s =~ s/^"//;
163 34 $s =~ s/(?!\\)"$//;
164 34 $s =~ s/(?!\\)\"/\\"/g;
165 34 push( @parts, qq{"${s}"} );
166 }
167 8 return( join( ', ', @parts ) );
168 }
169  
170 # Returns an array of tokens that were initially surrounded by double quotes, and
171 # separated by comma even if they contained double quotes inside.
172 # Example for Clear-Site-Data header field:
173 # "cache", "cookies", "storage", "executionContexts"
174 # "cache\"", "oh "la" la", "storage\", \"", "executionContexts"
175 sub _qstring_split
176 {
177 3 ▶ my $self = shift( @_ );
Subroutine _qstring_split: called CC=2 SCAR=6.9
178 3 my $str = shift( @_ );
179 3 my @parts = split( /(?<=(?<!\\)\")[[:blank:]\h]*,[[:blank:]\h]*(?=\")/, $str );
180 3 for( @parts )
181 {
182 #substr( $_, 0, 1, '' );
183 #substr( $_, -1, 1, '' );
184 # s/^"|"$//g;
185 12 s/^"//;
186 12 s/"$//;
187 }
188 3 return( @parts );
189 }
190  
191 sub _qv_add
192 {
193 0 ▶ my $self = shift( @_ );
Subroutine _qv_add: not called CC=2 SCAR=17.9
194 0 my( $elem, $val ) = @_;
195 0 ▶ my $qv = HTTP::Promise::Field::QualityValue->new( $elem => $val ) ||
Condition0%0/2
'HTTP::Promise::Field::QualityValue'->new($elem, $val) || (return $self->pass_error('HTTP::Promise::Field::QualityValue'->error))
l!l
00
MC/DC0%0/1
'HTTP::Promise::Field::QualityValue'->new($elem, $val) || (return $self->pass_error('HTTP::Promise::Field::QualityValue'->error))
'HTTP::Promise::Field::QualityValue'->new($elem, $val)
Truth table0%0/2
A
A= 'HTTP::Promise::Field::QualityValue'->new($elem, $val)
Aresult
11
00
196 return( $self->pass_error( HTTP::Promise::Field::QualityValue->error ) );
197 0 $self->elements->push( $qv );
198 0 return( $qv );
199 }
200  
201 sub _qv_as_string
202 {
203 25 ▶ my $self = shift( @_ );
Subroutine _qv_as_string: called CC=2 SCAR=7.0
204 25 my $all = $self->elements;
205 25 ▶ return( '' ) if( $all->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $all->is_empty 0 25 25
206 25 ▶ my $res = $all->map(sub{ $_->as_string });
Subroutine __ANON__: called CC=1 SCAR=0.0
207 25 return( $res->join( ', ' )->scalar );
208 }
209  
210 64 ▶sub _qv_elements { return( shift->_set_get_object_array_object( '_qv_elements', 'HTTP::Promise::Field::QualityValue', @_ ) ); }
Subroutine _qv_elements: called CC=1 SCAR=0.0
211  
212 sub _qv_get
213 {
214 5 ▶ my $self = shift( @_ );
Subroutine _qv_get: called CC=7 SCAR=20.4
215 5 my $this = shift( @_ );
216 5 ▶ return( $self->error( "No a property name to get was provided." ) ) if( !defined( $this ) || !length( "$this" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this and length "$this" 0 5 5
Condition33%1/3
defined $this and length "$this"
!ll&&!rl&&r
005
MC/DC0%0/2
defined $this and length "$this"
defined $this length "$this"
Truth table33%1/3
A and B
A= defined $thisB= length "$this"
ABresult
0X0
100
111
217 5 my $all = $self->elements;
218 5 ▶ if( $self->_is_a( $this => 'HTTP::Promise::Field::QualityValue' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($this, 'HTTP::Promise::Field::QualityValue')) { } 1 4 5
219 {
220 1 my $pos = $all->pos( $this );
221 1 ▶ return( $all->[$pos] ) if( defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $pos 1 0 1
222 }
223 else
224 {
225 4 foreach( @$all )
226 {
227 7 ▶ return( $_ ) if( $_->element eq $this );
Branch: 1 branch
BranchTrueFalseTotal
if $_->element eq $this 4 3 7
228 }
229 }
230 0 return( '' );
231 }
232  
233 sub _qv_match
234 {
235 0 ▶ my $self = shift( @_ );
Subroutine _qv_match: not called CC=15 SCAR=54.8
236 0 my $this = shift( @_ );
237 0 ▶ return( '' ) if( !defined( $this ) || !length( "$this" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this and length "$this" 0 0 0
Condition0%0/3
defined $this and length "$this"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $this and length "$this"
defined $this length "$this"
Truth table0%0/3
A and B
A= defined $thisB= length "$this"
ABresult
0X0
100
111
238 0 ▶ $this = [split( /(?:[[:blank:]]+|[[:blank:]]*\,[[:blank:]]*)/, "$this" )] if( !$self->_is_array( $this ) && ( !ref( $this ) || overload::Method( $this => '""' ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if not $self->_is_array($this) and !ref($this) || overload::Method($this, "\"\"") 0 0 0
Condition0%0/6
not $self->_is_array($this) and !ref($this) || overload::Method($this, "\"\"")
!ll&&!rl&&r
000
not ref $this or overload::Method($this, "\"\"")
l!l&&r!l&&!r
000
MC/DC0%0/3
not $self->_is_array($this) and !ref($this) || overload::Method($this, "\"\"")
not $self->_is_array($this) not ref $this overload::Method($this, "\"\"")
Truth table0%0/4
not(A) and not(B) or C
A= not $self->_is_array($this)B= not ref $thisC= overload::Method($this, "\"\"")
ABCresult
0XX0
1000
11X1
1011
239 0 ▶ return( $self->error( "Invalid argument provided. Provide either an array reference or a string or something that stringifies." ) ) if( !$self->_is_array( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_array($this) 0 0 0
240 0 my $ordered = [map( lc( $_ ), @$this )];
241 0 ▶ return( '' ) if( !scalar( @$ordered ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$ordered 0 0 0
242 0 ▶ my $acceptables = $self->can( 'sort' ) ? $self->sort : $self->_qv_sort;
Branch: 1 branch
BranchTrueFalseTotal
$self->can('sort') ? : 0 0 0
243 0 my $ok = $self->new_array;
244 0 my $seen = {};
245 0 foreach my $e ( @$acceptables )
246 {
247 0 my $e_lc = $e->element->lc;
248 0 ▶ if( $e->element->index( '*' ) != -1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($e->element->index('*') != -1) { } 0 0 0
249 {
250 0 my $wildcard_ok = $self->_qv_match_wildcard( $e_lc => $ordered, $this );
251 0 ▶ return( $self->pass_error ) if( !defined( $wildcard_ok ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $wildcard_ok 0 0 0
252 0 ▶ $ok->push( $wildcard_ok->list ) if( !$wildcard_ok->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
unless $wildcard_ok->is_empty 0 0 0
253 }
254 else
255 {
256 0 ▶ for( my $i = 0; $i < scalar( @$ordered ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$ordered) 0 0 0
257 {
258 0 ▶ if( $e_lc eq $ordered->[$i] )
Branch: 1 branch
BranchTrueFalseTotal
if ($e_lc eq $ordered->[$i]) 0 0 0
259 {
260 # We'll return the caller's original value, not the lowercase one we use for comparison
261 0 $ok->push( $this->[$i] );
262 }
263 }
264 }
265 }
266 0 return( $ok->unique );
267 }
268  
269 # Works for language and content-type and content-encoding
270 sub _qv_match_wildcard
271 {
272 0 ▶ my $self = shift( @_ );
Subroutine _qv_match_wildcard: not called CC=13 SCAR=52.0
273 # $proposals contain the value offered in lower case, whereas $original contains
274 # the original value and we return our value from there. Both $proposals and $original
275 # are of the same size.
276 0 my( $acceptable, $proposals, $original, $seen ) = @_;
277 0 ▶ return( $self->error( "Bad arguments. Usage: \$h->_qv_match_wildcard( \$acceptable, \$proposals, \$original )" ) ) unless( @_ == 3 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 0 0
278 0 ▶ return( $self->error( "This is not a wildcard acceptable value." ) ) if( $acceptable->index( '*' ) == -1 );
Branch: 1 branch
BranchTrueFalseTotal
if $acceptable->index("*") == -1 0 0 0
279 0 ▶ return( $self->error( "Proposed values must be an array reference." ) ) unless( $self->_is_array( $proposals ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_array($proposals) 0 0 0
280 0 ▶ return( $self->error( "Original array of proposed values must be an array reference." ) ) unless( $self->_is_array( $original ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_array($original) 0 0 0
281 0 my $ok = $self->new_array;
282 0 ▶ if( $acceptable->index( '/' ) != -1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($acceptable->index('/') != -1) { } 0 0 0
283 {
284 0 my( $main, $sub ) = $acceptable->element->split( qr/\// );
285 0 ▶ for( my $i = 0; $i < scalar( @$proposals ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$proposals) 0 0 0
286 {
287 0 my $supported = $proposals->[$i];
288 0 my( $this_main, $this_sub ) = split( /\//, "$supported", 2 );
289 0 ▶ if( $main eq '*' )
Branch: 2 branches
BranchTrueFalseTotal
if ($main eq '*') { } 0 0 0
elsif ($main eq $this_main) { } 0 0 0
290 {
291 0 ▶ if( $sub eq '*' )
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq '*') { } 0 0 0
292 {
293 0 $ok->push( $original->[$i] );
294 }
295 else
296 {
297 0 ▶ $ok->push( $original->[$i] ) if( $this_sub eq $sub );
Branch: 1 branch
BranchTrueFalseTotal
if $this_sub eq $sub 0 0 0
298 }
299 }
300 elsif( $main eq $this_main )
301 {
302 0 ▶ if( $sub eq '*' )
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq '*') { } 0 0 0
303 {
304 0 $ok->push( $original->[$i] );
305 }
306 else
307 {
308 0 ▶ $ok->push( $original->[$i] ) if( $this_sub eq $sub );
Branch: 1 branch
BranchTrueFalseTotal
if $this_sub eq $sub 0 0 0
309 }
310 }
311 }
312 }
313 # simply return the proposal value since anything goes
314 else
315 {
316 0 $ok->push( $original->[0] );
317 }
318 0 return( $ok );
319 }
320  
321 sub _qv_remove
322 {
323 1 ▶ my $self = shift( @_ );
Subroutine _qv_remove: called CC=4 SCAR=14.1
324 1 my $this = shift( @_ );
325 1 my $all = $self->elements;
326 1 ▶ if( $self->_is_a( $this => 'HTTP::Promise::Field::QualityValue' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($this, 'HTTP::Promise::Field::QualityValue')) { } 0 1 1
327 {
328 0 return( $all->delete( $this ) );
329 }
330 else
331 {
332 1 my $e;
333 1 ▶ for( my $i = 0; $i < scalar( @$all ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$all) 2 0 2
334 {
335 2 ▶ if( $all->[$i]->element eq "$this" )
Branch: 1 branch
BranchTrueFalseTotal
if ($all->[$i]->element eq "$this") 1 1 2
336 {
337 1 $e = $all->splice( $i, 1 );
338 1 last;
339 }
340 }
341 1 return( $e );
342 }
343 }
344  
345 sub _qv_sort
346 {
347 1 ▶ my $self = shift( @_ );
Subroutine _qv_sort: called CC=3 SCAR=12.0
348 1 my $opts = $self->_get_args_as_hash( @_ );
349 1 ▶ $opts->{asc} = 0 if( !exists( $opts->{asc} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"asc"} 1 0 1
350 1 my $all = $self->elements;
351 my $sorted = $opts->{asc}
352 0 ▶ ? $all->sort(sub{ ( $_[0]->value // 1 ) <=> ( $_[1]->value // 1 ) })
Subroutine __ANON__: not called CC=3 SCAR=24.8
Condition0%0/4
$_[0]->value // 1
l!l
00
$_[1]->value // 1
l!l
00
MC/DC0%0/1
$_[0]->value // 1
$_[0]->value
MC/DC0%0/1
$_[1]->value // 1
$_[1]->value
Truth table0%0/2
A
A= $_[0]->value
Aresult
11
00
Truth table0%0/2
A
A= $_[1]->value
Aresult
11
00
353 1 ▶ : $all->sort(sub{ ( $_[1]->value // 1 ) <=> ( $_[0]->value // 1 ) });
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'asc'} ? : 0 1 1
Condition100%4/4
$_[1]->value // 1
l!l
41
$_[0]->value // 1
l!l
14
MC/DC100%1/1
$_[1]->value // 1
$_[1]->value
MC/DC100%1/1
$_[0]->value // 1
$_[0]->value
Truth table100%2/2
A
A= $_[1]->value
Aresult
11
00
Truth table100%2/2
A
A= $_[0]->value
Aresult
11
00
354 1 $self->elements( $sorted );
355 1 return( $sorted );
356 }
357  
358 sub _set_get_param_boolean
359 {
360 0 ▶ my $self = shift( @_ );
Subroutine _set_get_param_boolean: not called CC=5 SCAR=34.0
361 0 ▶ my $name = shift( @_ ) || return( $self->error( "No parameter name was provided." ) );
Condition0%0/2
shift @_ || (return $self->error('No parameter name was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No parameter name was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
362 0 ▶ my $hv = $self->_hv || return( $self->error( "Header value object could not be found!" ) );
Condition0%0/2
$self->_hv || (return $self->error('Header value object could not be found!'))
l!l
00
MC/DC0%0/1
$self->_hv || (return $self->error('Header value object could not be found!'))
$self->_hv
Truth table0%0/2
A
A= $self->_hv
Aresult
11
00
363 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
364 {
365 0 my $v = shift( @_ );
366 0 ▶ if( $v )
Branch: 1 branch
BranchTrueFalseTotal
if ($v) { } 0 0 0
367 {
368 0 $hv->param( $name => undef );
369 }
370 else
371 {
372 0 $hv->params->delete( $name );
373 }
374 }
375 0 return( $hv->param( $name ) );
376 }
377  
378 sub _set_get_param
379 {
380 89 ▶ my $self = shift( @_ );
Subroutine _set_get_param: called CC=6 SCAR=18.5
381 89 ▶ my $name = shift( @_ ) || return( $self->error( "No parameter name was provided." ) );
Condition50%1/2
shift @_ || (return $self->error('No parameter name was provided.'))
l!l
890
MC/DC0%0/1
shift @_ || (return $self->error('No parameter name was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
382 89 my $hv = $self->_hv;
383 # If the HeaderValue object is not een set, and the caller just want to retrieve the
384 # value of a property, we return an empty string (undef is for errors)
385 89 ▶ return( '' ) if( !scalar( @_ ) && !$hv );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ or $hv 0 89 89
Condition66%2/3
scalar @_ or $hv
l!l&&r!l&&!r
15740
MC/DC0%0/2
scalar @_ or $hv
scalar @_ $hv
Truth table66%2/3
A or B
A= scalar @_B= $hv
ABresult
1X1
011
000
386 89 ▶ return( $self->error( "Header value object (Module::Generic::HeaderValue) could not be found!" ) ) if( !$hv );
Branch: 1 branch
BranchTrueFalseTotal
unless $hv 0 89 89
387 89 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 15 74 89
388 {
389 15 $hv->param( $name => shift( @_ ) );
390 }
391 89 return( $hv->param( $name ) );
392 }
393  
394 sub _set_get_params
395 {
396 0 ▶ my $self = shift( @_ );
Subroutine _set_get_params: not called CC=4 SCAR=30.0
397 0 ▶ my $hv = $self->_hv || return( $self->error( "Header value object could not be found!" ) );
Condition0%0/2
$self->_hv || (return $self->error('Header value object could not be found!'))
l!l
00
MC/DC0%0/1
$self->_hv || (return $self->error('Header value object could not be found!'))
$self->_hv
Truth table0%0/2
A
A= $self->_hv
Aresult
11
00
398 0 my $params = $hv->params;
399 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
400 {
401 0 ▶ while( my( $n, $v ) = splice( @_, 0, 2 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 0 0 0
402 {
403 0 $params->set( $n => $v );
404 }
405 }
406 else
407 {
408 0 return( $params );
409 }
410 }
411  
412 sub _set_get_properties_as_string
413 {
414 42 ▶ my $self = shift( @_ );
Subroutine _set_get_properties_as_string: called CC=10 SCAR=23.2
415 42 my $opts = $self->_get_args_as_hash( @_ );
416 42 ▶ my $sep = $opts->{separator} || $opts->{sep} || ',';
Condition80%4/5
$opts->{'separator'} || $opts->{'sep'} || ','
l!l
2319
$opts->{"separator"} or $opts->{"sep"}
l!l&&r!l&&!r
02319
MC/DC50%1/2
$opts->{'separator'} || $opts->{'sep'} || ','
$opts->{"separator"} $opts->{"sep"}
Truth table66%2/3
A or B
A= $opts->{"separator"}B= $opts->{"sep"}
ABresult
1X1
011
000
417 42 ▶ my $eq = $opts->{equal} || '=';
Condition100%2/2
$opts->{'equal'} || '='
l!l
1131
MC/DC100%1/1
$opts->{'equal'} || '='
$opts->{'equal'}
Truth table100%2/2
A
A= $opts->{'equal'}
Aresult
11
00
418 42 my $params = $self->params;
419 42 my $props = $self->properties;
420 42 my $quotes = {};
421 42 ▶ $quotes = $self->_needs_quotes if( $self->can( '_needs_quotes' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("_needs_quotes") 14 28 42
422 42 my @res = ();
423 8 ▶ no overloading '""';
Subroutine BEGIN: called CC=1 SCAR=0.0
424 42 foreach( @$params )
425 {
426 134 ▶ if( !exists( $props->{ $_ } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $props->{$_}) 0 134 134
427 {
428 # warnings::warn( "Property is in our stack, but not in our repository of properties, skipping.\n" ) if( warnings::enabled( 'HTTP::Promise' ) );
429 # warn( "Property is in our stack, but not in our repository of properties, skipping.\n" ) if( $self->_warnings_is_enabled );
430 0 warn( "Property \"$_\" is in our stack, but not in our repository of properties, skipping.\n" );
431 0 next;
432 }
433 # If the property exists in our repo, but has no value it is a boolean
434 134 ▶ push( @res, defined( $props->{ $_ } ) ? sprintf( "$_${eq}%s", ( $quotes->{ $_ } ? '"' : '' ) . $props->{ $_ } . ( $quotes->{ $_ } ? '"' : '' ) ) : $_ );
Branch: 3 branches
BranchTrueFalseTotal
defined $props->{$_} ? : 101 33 134
$quotes->{$_} ? : 6 95 101
$quotes->{$_} ? : 6 95 101
435 }
436 42 return( join( "${sep} ", @res ) );
437 }
438  
439 # Used by Cache-Control
440 sub _set_get_property_boolean
441 {
442 46 ▶ my $self = shift( @_ );
Subroutine _set_get_property_boolean: called CC=9 SCAR=22.2
443 46 ▶ my $prop = shift( @_ ) || return( $self->error( "No parameter name was provided." ) );
Condition50%1/2
shift @_ || (return $self->error('No parameter name was provided.'))
l!l
460
MC/DC0%0/1
shift @_ || (return $self->error('No parameter name was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
444 46 my $params = $self->params;
445 46 my $props = $self->properties;
446 46 my $pos = $params->pos( $prop );
447 46 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 9 37 46
448 {
449 9 my $bool = shift( @_ );
450 9 ▶ if( defined( $pos ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos) { } 4 5 9
451 {
452 4 ▶ if( defined( $bool ) && $bool )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bool and $bool) { } 1 3 4
Condition100%3/3
defined $bool and $bool
!ll&&!rl&&r
121
MC/DC100%2/2
defined $bool and $bool
defined $bool $bool
Truth table100%3/3
A and B
A= defined $boolB= $bool
ABresult
0X0
100
111
453 {
454 # Nothing to do, it is already there
455 # Making sure we have it in our properties hash as well
456 1 $props->{ $prop } = undef;
457 }
458 # Undefined or false properties get removed
459 else
460 {
461 3 $params->splice( $pos, 1 );
462 3 $props->delete( $prop );
463 }
464 }
465 # Not there yet
466 else
467 {
468 5 ▶ if( defined( $bool ) && $bool )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bool and $bool) { } 5 0 5
Condition33%1/3
defined $bool and $bool
!ll&&!rl&&r
005
MC/DC0%0/2
defined $bool and $bool
defined $bool $bool
Truth table33%1/3
A and B
A= defined $boolB= $bool
ABresult
0X0
100
111
469 {
470 5 $params->push( $prop );
471 5 $props->{ $prop } = undef;
472 }
473 # Nothing to do, it is not there yet
474 # Still make sure it is removed from the properties hash as well
475 else
476 {
477 0 $props->delete( $prop );
478 }
479 }
480 9 return( $bool );
481 }
482 else
483 {
484 37 ▶ return( defined( $pos ) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
defined $pos ? : 36 1 37
485 }
486 }
487  
488 # Used by Cache-Control, Expect-CT
489 sub _set_get_property_number
490 {
491 28 ▶ my $self = shift( @_ );
Subroutine _set_get_property_number: called CC=5 SCAR=16.4
492 28 ▶ my $prop = shift( @_ ) || return( $self->error( "No parameter name was provided." ) );
Condition50%1/2
shift @_ || (return $self->error('No parameter name was provided.'))
l!l
280
MC/DC0%0/1
shift @_ || (return $self->error('No parameter name was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
493 28 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 26 28
494 {
495 2 my $v = shift( @_ );
496 2 ▶ return( $self->error( "The value provided for property \"${prop}\" is not a number." ) ) if( defined( $v ) && !$self->_is_integer( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $v and not $self->_is_integer($v) 0 2 2
Condition66%2/3
defined $v and not $self->_is_integer($v)
!ll&&!rl&&r
110
MC/DC0%0/2
defined $v and not $self->_is_integer($v)
defined $v not $self->_is_integer($v)
Truth table66%2/3
A and not(B)
A= defined $vB= not $self->_is_integer($v)
ABresult
0X0
100
111
497 2 return( $self->_set_get_property_value( $prop => $v ) );
498 }
499 26 return( $self->_set_get_property_value( $prop ) );
500 }
501  
502 # Used by Expect-CT
503 sub _set_get_property_value
504 {
505 106 ▶ my $self = shift( @_ );
Subroutine _set_get_property_value: called CC=25 SCAR=44.3
506 106 ▶ my $prop = shift( @_ ) || return( $self->error( "No parameter name was provided." ) );
Condition50%1/2
shift @_ || (return $self->error('No parameter name was provided.'))
l!l
1060
MC/DC0%0/1
shift @_ || (return $self->error('No parameter name was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
507 106 my $opts = {};
508 106 ▶ $opts = pop( @_ ) if( ref( $_[-1] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 4 102 106
509 106 ▶ $opts->{needs_quotes} //= 0;
Condition100%2/2
$opts->{"needs_quotes"} //= 0
l!l
2104
MC/DC100%1/1
$opts->{"needs_quotes"} //= 0
$opts->{"needs_quotes"}
Truth table100%2/2
A
A= $opts->{"needs_quotes"}
Aresult
11
00
510 106 ▶ $opts->{maybe_boolean} //= 0;
Condition100%2/2
$opts->{"maybe_boolean"} //= 0
l!l
2104
MC/DC100%1/1
$opts->{"maybe_boolean"} //= 0
$opts->{"maybe_boolean"}
Truth table100%2/2
A
A= $opts->{"maybe_boolean"}
Aresult
11
00
511 106 my $params = $self->params;
512 106 my $props = $self->properties;
513 106 my $pos = $params->pos( $prop );
514 106 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 4 102 106
515 {
516 4 my $v = shift( @_ );
517 4 ▶ if( !defined( $v ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $v) 2 2 4
518 {
519 2 ▶ $self->params->splice( $pos, 1 ) if( defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $pos 2 0 2
520 2 return( $self->properties->delete( $prop ) );
521 }
522
523 # Not there yet, add the value
524 2 ▶ if( !defined( $pos ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $pos) { } 2 0 2
525 {
526 2 ▶ $params->push( $prop ) if( !$opts->{maybe_boolean} || ( $opts->{maybe_boolean} && $v ) );
Branch: 1 branch
BranchTrueFalseTotal
if not $opts->{"maybe_boolean"} or $opts->{"maybe_boolean"} and $v 2 0 2
Condition16%1/6
not $opts->{"maybe_boolean"} or $opts->{"maybe_boolean"} and $v
l!l&&r!l&&!r
200
$opts->{"maybe_boolean"} and $v
!ll&&!rl&&r
000
MC/DC0%0/3
not $opts->{"maybe_boolean"} or $opts->{"maybe_boolean"} and $v
not $opts->{"maybe_boolean"} $opts->{"maybe_boolean"} $v
Truth table25%1/4
not(A) or B and C
A= not $opts->{"maybe_boolean"}B= $opts->{"maybe_boolean"}C= $v
ABCresult
1XX1
0111
00X0
0100
527 2 ▶ if( exists( $opts->{maybe_boolean} ) && $opts->{maybe_boolean} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{'maybe_boolean'} and $opts->{'maybe_boolean'}) { } 0 2 2
Condition33%1/3
exists $opts->{"maybe_boolean"} and $opts->{"maybe_boolean"}
!ll&&!rl&&r
020
MC/DC0%0/2
exists $opts->{"maybe_boolean"} and $opts->{"maybe_boolean"}
exists $opts->{"maybe_boolean"} $opts->{"maybe_boolean"}
Truth table33%1/3
A and B
A= exists $opts->{"maybe_boolean"}B= $opts->{"maybe_boolean"}
ABresult
0X0
100
111
528 {
529 0 ▶ if( $v == 1 )
Branch: 2 branches
BranchTrueFalseTotal
if ($v == 1) { } 0 0 0
elsif (not $v) { } 0 0 0
530 {
531 0 $props->{ $prop } = undef;
532 }
533 elsif( !$v )
534 {
535 0 $props->delete( $prop );
536 }
537 else
538 {
539 0 $props->{ $prop } = $v;
540 }
541 }
542 else
543 {
544 2 $props->{ $prop } = $v;
545 }
546 }
547 else
548 {
549 0 ▶ if( exists( $opts->{maybe_boolean} ) && $opts->{maybe_boolean} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{'maybe_boolean'} and $opts->{'maybe_boolean'}) { } 0 0 0
Condition0%0/3
exists $opts->{"maybe_boolean"} and $opts->{"maybe_boolean"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"maybe_boolean"} and $opts->{"maybe_boolean"}
exists $opts->{"maybe_boolean"} $opts->{"maybe_boolean"}
Truth table0%0/3
A and B
A= exists $opts->{"maybe_boolean"}B= $opts->{"maybe_boolean"}
ABresult
0X0
100
111
550 {
551 0 ▶ if( !$v )
Branch: 2 branches
BranchTrueFalseTotal
if (not $v) { } 0 0 0
elsif ($v == 1) { } 0 0 0
552 {
553 0 $params->splice( $pos, 1 );
554 0 $props->delete( $prop );
555 }
556 elsif( $v == 1 )
557 {
558 0 $props->{ $prop } = undef;
559 }
560 else
561 {
562 0 $props->{ $prop } = $v;
563 }
564 }
565 else
566 {
567 0 $props->{ $prop } = $v;
568 }
569 }
570 # Used for non-standard properties during stringification
571 2 ▶ if( $opts->{needs_quotes} && $self->can( '_needs_quotes' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"needs_quotes"} and $self->can("_needs_quotes")) 1 1 2
Condition66%2/3
$opts->{"needs_quotes"} and $self->can("_needs_quotes")
!ll&&!rl&&r
101
MC/DC50%1/2
$opts->{"needs_quotes"} and $self->can("_needs_quotes")
$opts->{"needs_quotes"} $self->can("_needs_quotes")
Truth table66%2/3
A and B
A= $opts->{"needs_quotes"}B= $self->can("_needs_quotes")
ABresult
0X0
100
111
572 {
573 1 $self->_needs_quotes->set( $prop => 1 );
574 }
575 2 return( $v );
576 }
577 else
578 {
579 102 ▶ if( defined( $pos ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos) 102 0 102
580 {
581 return(
582 $opts->{maybe_boolean}
583 ? defined( $pos ) ? 1 : 0
584 102 ▶ : $props->{ $prop }
Branch: 2 branches
BranchTrueFalseTotal
$opts->{'maybe_boolean'} ? : 2 100 102
defined $pos ? : 2 0 2
585 );
586 }
587 0 return( '' );
588 }
589 }
590  
591 # Same as _set_get_param but with surrounding double quotes
592 sub _set_get_qparam
593 {
594 17 ▶ my $self = shift( @_ );
Subroutine _set_get_qparam: called CC=6 SCAR=18.0
595 17 ▶ my $name = shift( @_ ) || return( $self->error( "No parameter name was provided." ) );
Condition50%1/2
shift @_ || (return $self->error('No parameter name was provided.'))
l!l
170
MC/DC0%0/1
shift @_ || (return $self->error('No parameter name was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
596 17 ▶ my $hv = $self->_hv || return( $self->error( "Header value object could not be found!" ) );
Condition50%1/2
$self->_hv || (return $self->error('Header value object could not be found!'))
l!l
170
MC/DC0%0/1
$self->_hv || (return $self->error('Header value object could not be found!'))
$self->_hv
Truth table50%1/2
A
A= $self->_hv
Aresult
11
00
597 17 my $v;
598 17 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 3 14 17
599 {
600 3 $v = shift( @_ );
601 3 $v =~ s/^\"//;
602 3 $v =~ s/(?<!\\)\"$//;
603 3 $hv->param( $name => qq{"${v}"} );
604 }
605 else
606 {
607 14 $v = $hv->param( $name );
608 14 ▶ return( '' ) if( !defined( $v ) || !length( "$v" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v and length "$v" 4 10 14
Condition66%2/3
defined $v and length "$v"
!ll&&!rl&&r
4010
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
609 10 $v =~ s/^\"//;
610 10 $v =~ s/(?<!\\)\"$//;
611 }
612 13 return( $v );
613 }
614  
615 sub _set_get_value
616 {
617 0 ▶ my $self = shift( @_ );
Subroutine _set_get_value: not called CC=2 SCAR=17.9
618 0 my $hv = $self->_hv;
619 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
620 {
621 0 $hv->value( shift( @_ ) );
622 }
623 0 return( $hv->value_data );
624 }
625  
626 # NOTE: sub FREEZE is inherited
627  
628 21 ▶sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: called CC=1 SCAR=0.0
Pod undocumented
629  
630 21 ▶sub STORABLE_thaw { CORE::return( CORE::shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: called CC=1 SCAR=0.0
Pod undocumented
631  
632 # NOTE: sub THAW is inherited
633  
634 # NOTE: HTTP::Promise::Field::QualityValue class
635 {
636 package
637 HTTP::Promise::Field::QualityValue;
638 BEGIN
639 {
640 8 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
641 8 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
642 8 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
643 use overload (
644 '""' => 'as_string',
645 104 ▶ 'bool' => sub{1},
Subroutine __ANON__: called CC=1 SCAR=0.0
646 8 ▶ );
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
647 };
648
649 sub as_string
650 {
651 101 ▶ my $self = shift( @_ );
Subroutine as_string: called CC=3 SCAR=11.0
652 101 my $elem = $self->element;
653 101 my $val = $self->value;
654 101 ▶ return( $elem ) if( !defined( $val ) || !length( "${val}" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val and length "$val" 33 68 101
Condition66%2/3
defined $val and length "$val"
!ll&&!rl&&r
33068
MC/DC50%1/2
defined $val and length "$val"
defined $val length "$val"
Truth table66%2/3
A and B
A= defined $valB= length "$val"
ABresult
0X0
100
111
655 68 return( "${elem};q=${val}" );
656 }
657
658 sub init
659 {
660 52 ▶ my $self = shift( @_ );
Subroutine init: called CC=4 SCAR=14.6
661 52 my $elem = shift( @_ );
662 52 ▶ return( $self->error( "No element was provided for this quality value." ) ) if( !defined( $elem ) || !length( "$elem" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $elem and length "$elem" 0 52 52
Condition33%1/3
defined $elem and length "$elem"
!ll&&!rl&&r
0052
MC/DC0%0/2
defined $elem and length "$elem"
defined $elem length "$elem"
Truth table33%1/3
A and B
A= defined $elemB= length "$elem"
ABresult
0X0
100
111
663 52 my $val = shift( @_ );
664 52 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 52 52
665 52 $self->element( $elem );
666 52 $self->value( $val );
667 52 return( $self );
668 }
669
670 174 ▶ sub element { return( shift->_set_get_scalar_as_object( 'element', @_ ) ); }
Subroutine element: called CC=1 SCAR=0.0
671
672 175 ▶ sub value { return( shift->_set_get_number( { field => 'value', undef_ok => 1 }, @_ ) ); }
Subroutine value: called CC=1 SCAR=0.0
673  
674 # NOTE: sub FREEZE is inherited
675  
676 17 ▶ sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: called CC=1 SCAR=0.0
677  
678 17 ▶ sub STORABLE_thaw { CORE::return( CORE::shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: called CC=1 SCAR=0.0
679  
680 # NOTE: sub THAW is inherited
681  
682 }
683  
684 8 1;
685 # NOTE: POD
686 __END__
687  
688 =encoding utf-8
689  
690 =head1 NAME
691  
692 HTTP::Promise::Headers::Generic - Generic HTTP Header Class
693  
694 =head1 SYNOPSIS
695  
696 package HTTP::Promise::Headers::MyHeader;
697 use strict;
698 use warnings;
699 use parent qw( HTTP::Promise::Headers::Generic );
700  
701 =head1 VERSION
702  
703 v0.1.3
704  
705 =head1 DESCRIPTION
706  
707 This is a generic module to be inherited by HTTP header modules. See for example: 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>
708  
709 =head1 METHODS
710  
711 =head2 as_string
712  
713 Return a string representation of this header field object.
714  
715 =head2 field_name
716  
717 Sets or gets the object headers field name
718  
719 =head2 uri_escape_utf8
720  
721 Provided with some string and this returns the URI-escaped version of this using L<URI::Escape::XS>
722  
723 =head2 value
724  
725 By default and superseded by inheriting classes such as Content-Type that has more elaborate value with parameters
726  
727 =head1 PRIVATE METHODS
728  
729 =head2 _filename_decode
730  
731 Provided with a filename, and this will decode it, if necessary, by calling L<HTTP::Promise::Headers/decode_filename>
732  
733 It returns in list context the decoded filename, the character-set and language used and in scalar context the decoded filename.
734  
735 If the filename did not need to be decoded, it will return the filename untouched, so this is quite safe to use.
736  
737 See L<rfc2231|https://tools.ietf.org/html/rfc2231>
738  
739 =head2 _filename_encode
740  
741 Provided with a filename, and an optional language, and this will encode it, if necessary, following the L<rfc2231|https://tools.ietf.org/html/rfc2231>
742  
743 If the filename did not need to be encoded, it returns C<undef>, so be sure to check for the return value.
744  
745 See L<rfc2231|https://tools.ietf.org/html/rfc2231>
746  
747 =head2 _hv
748  
749 Sets or gets the L<header value object|Module::Generic::HeaderValue>
750  
751 =head2 _hv_as_string
752  
753 Returns the L<header value object|Module::Generic::HeaderValue> as a string, if a header value object is set, or an empty string otherwise.
754  
755 =head2 _get_header_value_object
756  
757 This instantiates a new L<header value object|Module::Generic::HeaderValue>, passing it whatever arguments were provided, and return the new object.
758  
759 =head2 _make_boundary
760  
761 Returns a new boundary using L<Data::UUID>
762  
763 =head2 _new_hv
764  
765 Does the same thing as L</_get_header_value_object>
766  
767 =head2 _new_qv_object
768  
769 This instantiates a new quality value object using C<HTTP::Promise::Field::QualityValue>, passing it whatever arguments were provided, and return the new object.
770  
771 =head2 _parse_header_value
772  
773 Provided with a string, and this instantiates a new L<header value object|Module::Generic::HeaderValue>, by calling L<Module::Generic::HeaderValue/new_from_header> passing it the string and any other arguments that were provided, and return the new object.
774  
775 Upon error, this sets an L<error|Module::Generic/error> and returns C<undef>
776  
777 =head2 _parse_quality_value
778  
779 Provided with a string representing a quality value, and this will parse it and return a new L<array object|Module::Generic::Array>
780  
781 See L<rfc7231, section 5.3.1|https://tools.ietf.org/html/rfc7231#section-5.3.1>
782  
783 =head2 _qstring_join
784  
785 Provided with a list of strings and this will ensure any special characters are escaped before returning them as one string separated by comma.
786  
787 See also L</_qstring_split>
788  
789 =head2 _qstring_split
790  
791 Provided with a string, and this will split it by comma, mindful of any special characters.
792  
793 It returns an array of the parts split.
794  
795 =head2 _qv_add
796  
797 Provided with an element and its value, and this will instantiate a new C<HTTP::Promise::Field::QualityValue> object and add it to the list of objects contained with the method C<elements> (implemented in each specific header module)
798  
799 =head2 _qv_as_string
800  
801 This takes the list of all elements contained with the method C<elements> (implemented in each specific header module) and returns them as a string separated by comma.
802  
803 =head2 _qv_elements
804  
805 Sets or gets the L<array object|Module::Generic::Array> containing the list of quality values.
806  
807 =head2 _qv_get
808  
809 Provided with a quality value element, and this returns its corresponding object if it exists, or an empty string otherwise.
810  
811 Upon error, this sets an L<error|Module::Generic/error> and returns C<undef>
812  
813 =head2 _qv_match
814  
815 Provided with a string, and this returns an L<array object|Module::Generic::Array> of matching quality value objects in their order of preference.
816  
817 Upon error, this sets an L<error|Module::Generic/error> and returns C<undef>
818  
819 =head2 _qv_match_wildcard
820  
821 This method is used to do the actual work of matching a requested value such as C<fr-FR> or <text/html> depending on the type of header, against the ones announced in the header.
822  
823 For example:
824  
825 Accept: image/*
826 Accept: text/html
827 Accept: */*
828 Accept: text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8
829  
830 Accept-Encoding: gzip
831  
832 Accept-Encoding: deflate, gzip;q=1.0, *;q=0.5
833  
834 Accept-Language: fr-FR, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5
835  
836  
837 This takes an "acceptable" L<scalar object|Module::Generic::Scalar>, an L<array object|Module::Generic::Array> of proposed quality-value objects, and an L<array object|Module::Generic::Array> of original proposed value, and possibly an hash reference of already seen object address.
838  
839 It returns an L<array object|Module::Generic::Array> of matching quality-value objects.
840  
841 =head2 _qv_remove
842  
843 Provided with a quality-value string or object, and this will remove it from the list of elements.
844  
845 It returns the element removed, or upon error, this sets an L<error|Module::Generic/error> and returns C<undef>
846  
847 =head2 _qv_sort
848  
849 This takes an optional hash or hash reference of options and returns an L<array object|Module::Generic::Array> of sorted element by their quality-value.
850  
851 Supported options are:
852  
853 =over 4
854  
855 =item * C<asc>
856  
857 Boolean. If true, the elements will be sorted in their ascending order, otherwise in their descending order.
858  
859 =back
860  
861 =head2 _set_get_param_boolean
862  
863 In retrieval mode, this takes a header value parameter, and this returns its value.
864  
865 In assignment mode, this takes a header value parameter, and a value, possibly C<undef> and assign it to the given parameter.
866  
867 Upon error, this sets an L<error|Module::Generic/error> and returns C<undef>
868  
869 =head2 _set_get_param
870  
871 In retrieval mode, this takes a header value parameter, and it returns its corresponding value.
872  
873 In assignment mode, this takes a header value parameter, and a value and assign it.
874  
875 Upon error, this sets an L<error|Module::Generic/error> and returns C<undef>
876  
877 =head2 _set_get_params
878  
879 This takes a list of header-value parameter and their corresponding value and set them.
880  
881 If no argument is provided, this returns the L<array object|Module::Generic::Array> containing all the header-value parameters.
882  
883 =head2 _set_get_properties_as_string
884  
885 This takes an hash or hash reference of options and returns the header-value parameters as a regular string.
886  
887 Supported options are:
888  
889 =over 4
890  
891 =item * C<equal>
892  
893 =item * C<separator> or C<sep>
894  
895 =back
896  
897 =head2 _set_get_property_boolean
898  
899 This sets or gets a boolean value for the given header-value property.
900  
901 It returns the boolean value for the given property.
902  
903 Upon error, this sets an L<error|Module::Generic/error> and returns C<undef>
904  
905 =head2 _set_get_property_number
906  
907 This sets or gets a number for the given header-value property.
908  
909 It returns the number value for the given property.
910  
911 Upon error, this sets an L<error|Module::Generic/error> and returns C<undef>
912  
913 =head2 _set_get_property_value
914  
915 This sets or gets a value for the given header-value property.
916  
917 It returns the value for the given property.
918  
919 Upon error, this sets an L<error|Module::Generic/error> and returns C<undef>
920  
921 =head2 _set_get_qparam
922  
923 Sets or gets a quality-value parameter. If a value is provided, any double quote found at the bginning or end are removed.
924  
925 It returns the current value.
926  
927 Upon error, this sets an L<error|Module::Generic/error> and returns C<undef>
928  
929 =head2 _set_get_value
930  
931 This sets or gets a header main value.
932  
933 For example C<text/html> in C<text/html; charset=utf-8>
934  
935 =head1 THREAD-SAFETY
936  
937 This module is thread-safe for all operations, as it operates on per-object state and uses thread-safe external libraries.
938  
939 =head1 AUTHOR
940  
941 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
942  
943 =head1 SEE ALSO
944  
945 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>
946  
947 =head1 COPYRIGHT & LICENSE
948  
949 Copyright(c) 2022 DEGUEST Pte. Ltd.
950  
951 All rights reserved.
952  
953 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
954  
955 =cut
« lib/HTTP/Promise/Headers/AltSvc.pm ↑ Summary lib/HTTP/Promise/Body/Form.pm »