Promise/Headers/Generic.pm

filter: Statementstmt 72.9% 251 / 344 Branchbran 43.6% 75 / 172 Conditioncond 42.2% 41 / 97 MC/DCmcdc 20.0% 11 / 55 Subroutinesub 80.0% 52 / 65 Podpod 66.6% 4 / 6 totaltotal 58.7% 434 / 739 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.6
« Promise/Headers/AltSvc.pm ↑ Summary 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 9 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
17 9 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 9 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 9 warnings::register_categories( 'HTTP::Promise' );
20 9 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 9 ▶ use vars qw( $VERSION $QV_ELEMENT $QV_VALUE );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 9 ▶ use Crypt::Misc ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 9 ▶ use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 9 ▶ use URI::Escape::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
25 9 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 9 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
27 '""' => 'as_string',
28 281 ▶ 'bool' => sub{1},
Subroutine __ANON__: called CC=1 SCAR=0.0
29 # No fallback on purpose
30 9 );
31 # Accept: audio/*; q=0.2, audio/basic
32 9 our $QV_ELEMENT = qr/(?:[^\;\,]+)/;
33 9 our $QV_VALUE = qr/(?:0(?:\.[0-9]{0,3})?|1(?:\.0{0,3})?)/;
34 9 our $VERSION = 'v0.1.3';
35 };
36  
37 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 0 ▶sub as_string { return( shift->value ); }
Subroutine as_string: not called CC=1 SCAR=6.9
Pod documented
41  
42 0 ▶sub field_name { return( shift->_set_get_scalar( '_name', @_ ) ); }
Subroutine field_name: not called CC=1 SCAR=6.9
Pod documented
43  
44 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
45  
46 # By default and superseded by inheriting classes such as Content-Type that has more
47 # elaborate value with parameters
48 0 ▶sub value { return( shift->_set_get_scalar( '_value', @_ ) ); }
Subroutine value: not called CC=1 SCAR=6.9
Pod documented
49  
50 176 ▶sub _field_name { return( shift->_set_get_scalar( '_name', @_ ) ); }
Subroutine _field_name: called CC=1 SCAR=0.0
51  
52 # rfc2231 <https://tools.ietf.org/html/rfc2231>
53 sub _filename_decode
54 7 ▶{
Subroutine _filename_decode: called CC=4 SCAR=14.3
55 7 my $self = shift( @_ );
56 7 my $fname = shift( @_ );
57 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 7 0 7
58 7 my( $new_fname, $charset, $lang ) = HTTP::Promise::Headers->decode_filename( $fname );
59 7 ▶ if( defined( $new_fname ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new_fname) 7 0 7
60 {
61 7 $fname = $new_fname;
62 }
63 7 ▶ return( wantarray() ? ( $fname, $charset, $lang ) : $fname );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 7 0 7
64 }
65  
66 # rfc2231 <https://tools.ietf.org/html/rfc2231>
67 sub _filename_encode
68 5 ▶{
Subroutine _filename_encode: called CC=3 SCAR=11.0
69 5 my $self = shift( @_ );
70 5 my $fname = shift( @_ );
71 5 my $lang = shift( @_ );
72 5 ▶ if( $fname =~ /[^\x00-\x7f]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($fname =~ /[^\x00-\x7f]/) 2 3 5
73 {
74 2 ▶ $lang = '' if( !defined( $lang ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lang 0 2 2
75 2 return( sprintf( "UTF-8'${lang}'%s", $self->uri_escape_utf8( $fname ) ) );
76 }
77 # Nothing to be done. We return undef on purpose to indicate nothing was done
78 3 return;
79 }
80  
81 288 ▶sub _hv { return( shift->_set_get_object_without_init( '_hv', 'Module::Generic::HeaderValue', @_ ) ); }
Subroutine _hv: called CC=1 SCAR=0.0
82  
83 sub _hv_as_string
84 44 ▶{
Subroutine _hv_as_string: called CC=2 SCAR=7.0
85 44 my $self = shift( @_ );
86 44 my $hv = $self->_hv;
87 44 ▶ return( '' ) if( !$hv );
Branch: 1 branch
BranchTrueFalseTotal
unless $hv 0 44 44
88 44 return( $hv->as_string( @_ ) );
89 }
90  
91 sub _get_header_value_object
92 0 ▶{
Subroutine _get_header_value_object: not called CC=3 SCAR=24.8
93 0 my $self = shift( @_ );
94 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
95 return( $self->pass_error );
96 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
97 return( $self->pass_error( Module::Generic::HeaderValue->error ) );
98 0 return( $hv );
99 }
100  
101 0 ▶sub _make_boundary { return( Crypt::Misc::random_v4uuid() ); }
Subroutine _make_boundary: not called CC=1 SCAR=6.9
102  
103 sub _new_hv
104 11 ▶{
Subroutine _new_hv: called CC=2 SCAR=7.1
105 11 my $self = shift( @_ );
106 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 11 0 11
107 11 return( Module::Generic::HeaderValue->new( @_ ) );
108 }
109  
110 sub _new_qv_object
111 52 ▶{
Subroutine _new_qv_object: called CC=2 SCAR=7.0
112 52 my $self = shift( @_ );
113 52 my $o = HTTP::Promise::Field::QualityValue->new( @_ );
114 52 ▶ return( $self->pass_error( HTTP::Promise::Field::QualityValue->error ) ) if( !defined( $o ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o 0 52 52
115 52 return( $o );
116 }
117  
118 sub _parse_header_value
119 68 ▶{
Subroutine _parse_header_value: called CC=5 SCAR=17.8
120 68 my $self = shift( @_ );
121 68 my $this = shift( @_ );
122 68 ▶ 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 68 68
Condition33%1/3
defined $this and length "$this"
!ll&&!rl&&r
0068
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
123 68 ▶ $self->_load_class( 'Module::Generic::HeaderValue' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::HeaderValue") or return $self->pass_error 68 0 68
124 return( $self->pass_error );
125 68 ▶ 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
680
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
126 return( $self->pass_error( Module::Generic::HeaderValue->error ) );
127 68 return( $hv );
128 }
129  
130 # rfc7231, section 5.3.1
131 # <https://tools.ietf.org/html/rfc7231#section-5.3.1>
132 sub _parse_quality_value
133 15 ▶{
Subroutine _parse_quality_value: called CC=5 SCAR=16.6
134 15 my $self = shift( @_ );
135 15 my $str = shift( @_ );
136 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
137 # No blank
138 15 $str =~ s/[[:blank:]\h]]+//g;
139 15 my $choices = $self->new_array;
140 # Credits: HTTP::AcceptLanguage from Kazuhiro Osawa
141 15 for my $def ( split( /,[[:blank:]\h]*/, $str ) )
142 {
143 52 my( $element, $quality ) = $def =~ /\A($QV_ELEMENT)(?:;[[:blank:]\h]*[qQ]=($QV_VALUE))?\z/;
144 # rfc7231, section 5.3.1:
145 # "If no "q" parameter is present, the default weight is 1."
146 # rfc7231, section 5.3.5
147 # "no value is the same as q=1"
148 # $quality = 1 unless( defined( $quality ) );
149 # next unless( $element && $quality > 0 );
150 52 ▶ next unless( $element );
Branch: 1 branch
BranchTrueFalseTotal
unless $element 0 52 52
151 52 my $qv = $self->_new_qv_object( $element => $quality );
152 52 $choices->push( $qv );
153 }
154 15 return( $choices );
155 }
156  
157 sub _qstring_join
158 8 ▶{
Subroutine _qstring_join: called CC=2 SCAR=6.9
159 8 my $self = shift( @_ );
160 8 my @parts = ();
161 8 foreach my $s ( @_ )
162 {
163 34 $s =~ s/^"//;
164 34 $s =~ s/(?!\\)"$//;
165 34 $s =~ s/(?!\\)\"/\\"/g;
166 34 push( @parts, qq{"${s}"} );
167 }
168 8 return( join( ', ', @parts ) );
169 }
170  
171 # Returns an array of tokens that were initially surrounded by double quotes, and
172 # separated by comma even if they contained double quotes inside.
173 # Example for Clear-Site-Data header field:
174 # "cache", "cookies", "storage", "executionContexts"
175 # "cache\"", "oh "la" la", "storage\", \"", "executionContexts"
176 sub _qstring_split
177 3 ▶{
Subroutine _qstring_split: called CC=2 SCAR=6.9
178 3 my $self = shift( @_ );
179 3 my $str = shift( @_ );
180 3 my @parts = split( /(?<=(?<!\\)\")[[:blank:]\h]*,[[:blank:]\h]*(?=\")/, $str );
181 3 for( @parts )
182 {
183 #substr( $_, 0, 1, '' );
184 #substr( $_, -1, 1, '' );
185 # s/^"|"$//g;
186 12 s/^"//;
187 12 s/"$//;
188 }
189 3 return( @parts );
190 }
191  
192 sub _qv_add
193 0 ▶{
Subroutine _qv_add: not called CC=2 SCAR=17.9
194 0 my $self = shift( @_ );
195 0 my( $elem, $val ) = @_;
196 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
197 return( $self->pass_error( HTTP::Promise::Field::QualityValue->error ) );
198 0 $self->elements->push( $qv );
199 0 return( $qv );
200 }
201  
202 sub _qv_as_string
203 25 ▶{
Subroutine _qv_as_string: called CC=2 SCAR=7.0
204 25 my $self = shift( @_ );
205 25 my $all = $self->elements;
206 25 ▶ return( '' ) if( $all->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $all->is_empty 0 25 25
207 25 ▶ my $res = $all->map(sub{ $_->as_string });
Subroutine __ANON__: called CC=1 SCAR=0.0
208 25 return( $res->join( ', ' )->scalar );
209 }
210  
211 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
212  
213 sub _qv_get
214 5 ▶{
Subroutine _qv_get: called CC=7 SCAR=20.4
215 5 my $self = shift( @_ );
216 5 my $this = shift( @_ );
217 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
218 5 my $all = $self->elements;
219 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
220 {
221 1 my $pos = $all->pos( $this );
222 1 ▶ return( $all->[$pos] ) if( defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $pos 1 0 1
223 }
224 else
225 {
226 4 foreach( @$all )
227 {
228 7 ▶ return( $_ ) if( $_->element eq $this );
Branch: 1 branch
BranchTrueFalseTotal
if $_->element eq $this 4 3 7
229 }
230 }
231 0 return( '' );
232 }
233  
234 sub _qv_match
235 0 ▶{
Subroutine _qv_match: not called CC=15 SCAR=54.8
236 0 my $self = shift( @_ );
237 0 my $this = shift( @_ );
238 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
239 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
240 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
241 0 my $ordered = [map( lc( $_ ), @$this )];
242 0 ▶ return( '' ) if( !scalar( @$ordered ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$ordered 0 0 0
243 0 ▶ my $acceptables = $self->can( 'sort' ) ? $self->sort : $self->_qv_sort;
Branch: 1 branch
BranchTrueFalseTotal
$self->can('sort') ? : 0 0 0
244 0 my $ok = $self->new_array;
245 0 my $seen = {};
246 0 foreach my $e ( @$acceptables )
247 {
248 0 my $e_lc = $e->element->lc;
249 0 ▶ if( $e->element->index( '*' ) != -1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($e->element->index('*') != -1) { } 0 0 0
250 {
251 0 my $wildcard_ok = $self->_qv_match_wildcard( $e_lc => $ordered, $this );
252 0 ▶ return( $self->pass_error ) if( !defined( $wildcard_ok ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $wildcard_ok 0 0 0
253 0 ▶ $ok->push( $wildcard_ok->list ) if( !$wildcard_ok->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
unless $wildcard_ok->is_empty 0 0 0
254 }
255 else
256 {
257 0 ▶ for( my $i = 0; $i < scalar( @$ordered ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$ordered) 0 0 0
258 {
259 0 ▶ if( $e_lc eq $ordered->[$i] )
Branch: 1 branch
BranchTrueFalseTotal
if ($e_lc eq $ordered->[$i]) 0 0 0
260 {
261 # We'll return the caller's original value, not the lowercase one we use for comparison
262 0 $ok->push( $this->[$i] );
263 }
264 }
265 }
266 }
267 0 return( $ok->unique );
268 }
269  
270 # Works for language and content-type and content-encoding
271 sub _qv_match_wildcard
272 0 ▶{
Subroutine _qv_match_wildcard: not called CC=13 SCAR=52.0
273 0 my $self = shift( @_ );
274 # $proposals contain the value offered in lower case, whereas $original contains
275 # the original value and we return our value from there. Both $proposals and $original
276 # are of the same size.
277 0 my( $acceptable, $proposals, $original, $seen ) = @_;
278 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
279 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
280 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
281 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
282 0 my $ok = $self->new_array;
283 0 ▶ if( $acceptable->index( '/' ) != -1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($acceptable->index('/') != -1) { } 0 0 0
284 {
285 0 my( $main, $sub ) = $acceptable->element->split( qr/\// );
286 0 ▶ for( my $i = 0; $i < scalar( @$proposals ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$proposals) 0 0 0
287 {
288 0 my $supported = $proposals->[$i];
289 0 my( $this_main, $this_sub ) = split( /\//, "$supported", 2 );
290 0 ▶ if( $main eq '*' )
Branch: 2 branches
BranchTrueFalseTotal
if ($main eq '*') { } 0 0 0
elsif ($main eq $this_main) { } 0 0 0
291 {
292 0 ▶ if( $sub eq '*' )
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq '*') { } 0 0 0
293 {
294 0 $ok->push( $original->[$i] );
295 }
296 else
297 {
298 0 ▶ $ok->push( $original->[$i] ) if( $this_sub eq $sub );
Branch: 1 branch
BranchTrueFalseTotal
if $this_sub eq $sub 0 0 0
299 }
300 }
301 elsif( $main eq $this_main )
302 {
303 0 ▶ if( $sub eq '*' )
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq '*') { } 0 0 0
304 {
305 0 $ok->push( $original->[$i] );
306 }
307 else
308 {
309 0 ▶ $ok->push( $original->[$i] ) if( $this_sub eq $sub );
Branch: 1 branch
BranchTrueFalseTotal
if $this_sub eq $sub 0 0 0
310 }
311 }
312 }
313 }
314 # simply return the proposal value since anything goes
315 else
316 {
317 0 $ok->push( $original->[0] );
318 }
319 0 return( $ok );
320 }
321  
322 sub _qv_remove
323 1 ▶{
Subroutine _qv_remove: called CC=4 SCAR=14.1
324 1 my $self = shift( @_ );
325 1 my $this = shift( @_ );
326 1 my $all = $self->elements;
327 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
328 {
329 0 return( $all->delete( $this ) );
330 }
331 else
332 {
333 1 my $e;
334 1 ▶ for( my $i = 0; $i < scalar( @$all ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$all) 2 0 2
335 {
336 2 ▶ if( $all->[$i]->element eq "$this" )
Branch: 1 branch
BranchTrueFalseTotal
if ($all->[$i]->element eq "$this") 1 1 2
337 {
338 1 $e = $all->splice( $i, 1 );
339 1 last;
340 }
341 }
342 1 return( $e );
343 }
344 }
345  
346 sub _qv_sort
347 1 ▶{
Subroutine _qv_sort: called CC=3 SCAR=12.0
348 1 my $self = shift( @_ );
349 1 my $opts = $self->_get_args_as_hash( @_ );
350 1 ▶ $opts->{asc} = 0 if( !exists( $opts->{asc} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"asc"} 1 0 1
351 1 my $all = $self->elements;
352 my $sorted = $opts->{asc}
353 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
354 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
355 1 $self->elements( $sorted );
356 1 return( $sorted );
357 }
358  
359 sub _set_get_param_boolean
360 0 ▶{
Subroutine _set_get_param_boolean: not called CC=5 SCAR=34.0
361 0 my $self = shift( @_ );
362 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
363 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
364 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
365 {
366 0 my $v = shift( @_ );
367 0 ▶ if( $v )
Branch: 1 branch
BranchTrueFalseTotal
if ($v) { } 0 0 0
368 {
369 0 $hv->param( $name => undef );
370 }
371 else
372 {
373 0 $hv->params->delete( $name );
374 }
375 }
376 0 return( $hv->param( $name ) );
377 }
378  
379 sub _set_get_param
380 93 ▶{
Subroutine _set_get_param: called CC=6 SCAR=18.5
381 93 my $self = shift( @_ );
382 93 ▶ 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
930
MC/DC0%0/1
shift @_ || (return $self->error('No parameter name was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
383 93 my $hv = $self->_hv;
384 # If the HeaderValue object is not een set, and the caller just want to retrieve the
385 # value of a property, we return an empty string (undef is for errors)
386 93 ▶ return( '' ) if( !scalar( @_ ) && !$hv );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ or $hv 0 93 93
Condition66%2/3
scalar @_ or $hv
l!l&&r!l&&!r
15780
MC/DC0%0/2
scalar @_ or $hv
scalar @_ $hv
Truth table66%2/3
A or B
A= scalar @_B= $hv
ABresult
1X1
011
000
387 93 ▶ return( $self->error( "Header value object (Module::Generic::HeaderValue) could not be found!" ) ) if( !$hv );
Branch: 1 branch
BranchTrueFalseTotal
unless $hv 0 93 93
388 93 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 15 78 93
389 {
390 15 $hv->param( $name => shift( @_ ) );
391 }
392 93 return( $hv->param( $name ) );
393 }
394  
395 sub _set_get_params
396 0 ▶{
Subroutine _set_get_params: not called CC=4 SCAR=30.0
397 0 my $self = shift( @_ );
398 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
399 0 my $params = $hv->params;
400 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
401 {
402 0 ▶ while( my( $n, $v ) = splice( @_, 0, 2 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 0 0 0
403 {
404 0 $params->set( $n => $v );
405 }
406 }
407 else
408 {
409 0 return( $params );
410 }
411 }
412  
413 sub _set_get_properties_as_string
414 42 ▶{
Subroutine _set_get_properties_as_string: called CC=10 SCAR=23.2
415 42 my $self = shift( @_ );
416 42 my $opts = $self->_get_args_as_hash( @_ );
417 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
418 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
419 42 my $params = $self->params;
420 42 my $props = $self->properties;
421 42 my $quotes = {};
422 42 ▶ $quotes = $self->_needs_quotes if( $self->can( '_needs_quotes' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("_needs_quotes") 14 28 42
423 42 my @res = ();
424 9 ▶ no overloading '""';
Subroutine BEGIN: called CC=1 SCAR=0.0
425 42 foreach( @$params )
426 {
427 134 ▶ if( !exists( $props->{ $_ } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $props->{$_}) 0 134 134
428 {
429 # warnings::warn( "Property is in our stack, but not in our repository of properties, skipping.\n" ) if( warnings::enabled( 'HTTP::Promise' ) );
430 # warn( "Property is in our stack, but not in our repository of properties, skipping.\n" ) if( $self->_warnings_is_enabled );
431 0 warn( "Property \"$_\" is in our stack, but not in our repository of properties, skipping.\n" );
432 0 next;
433 }
434 # If the property exists in our repo, but has no value it is a boolean
435 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
436 }
437 42 return( join( "${sep} ", @res ) );
438 }
439  
440 # Used by Cache-Control
441 sub _set_get_property_boolean
442 46 ▶{
Subroutine _set_get_property_boolean: called CC=9 SCAR=22.2
443 46 my $self = shift( @_ );
444 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
445 46 my $params = $self->params;
446 46 my $props = $self->properties;
447 46 my $pos = $params->pos( $prop );
448 46 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 9 37 46
449 {
450 9 my $bool = shift( @_ );
451 9 ▶ if( defined( $pos ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos) { } 4 5 9
452 {
453 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
454 {
455 # Nothing to do, it is already there
456 # Making sure we have it in our properties hash as well
457 1 $props->{ $prop } = undef;
458 }
459 # Undefined or false properties get removed
460 else
461 {
462 3 $params->splice( $pos, 1 );
463 3 $props->delete( $prop );
464 }
465 }
466 # Not there yet
467 else
468 {
469 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
470 {
471 5 $params->push( $prop );
472 5 $props->{ $prop } = undef;
473 }
474 # Nothing to do, it is not there yet
475 # Still make sure it is removed from the properties hash as well
476 else
477 {
478 0 $props->delete( $prop );
479 }
480 }
481 9 return( $bool );
482 }
483 else
484 {
485 37 ▶ return( defined( $pos ) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
defined $pos ? : 36 1 37
486 }
487 }
488  
489 # Used by Cache-Control, Expect-CT
490 sub _set_get_property_number
491 28 ▶{
Subroutine _set_get_property_number: called CC=5 SCAR=16.4
492 28 my $self = shift( @_ );
493 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
494 28 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 26 28
495 {
496 2 my $v = shift( @_ );
497 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
498 2 return( $self->_set_get_property_value( $prop => $v ) );
499 }
500 26 return( $self->_set_get_property_value( $prop ) );
501 }
502  
503 # Used by Expect-CT
504 sub _set_get_property_value
505 106 ▶{
Subroutine _set_get_property_value: called CC=25 SCAR=44.3
506 106 my $self = shift( @_ );
507 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
508 106 my $opts = {};
509 106 ▶ $opts = pop( @_ ) if( ref( $_[-1] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 4 102 106
510 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
511 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
512 106 my $params = $self->params;
513 106 my $props = $self->properties;
514 106 my $pos = $params->pos( $prop );
515 106 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 4 102 106
516 {
517 4 my $v = shift( @_ );
518 4 ▶ if( !defined( $v ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $v) 2 2 4
519 {
520 2 ▶ $self->params->splice( $pos, 1 ) if( defined( $pos ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $pos 2 0 2
521 2 return( $self->properties->delete( $prop ) );
522 }
523
524 # Not there yet, add the value
525 2 ▶ if( !defined( $pos ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $pos) { } 2 0 2
526 {
527 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
528 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
529 {
530 0 ▶ if( $v == 1 )
Branch: 2 branches
BranchTrueFalseTotal
if ($v == 1) { } 0 0 0
elsif (not $v) { } 0 0 0
531 {
532 0 $props->{ $prop } = undef;
533 }
534 elsif( !$v )
535 {
536 0 $props->delete( $prop );
537 }
538 else
539 {
540 0 $props->{ $prop } = $v;
541 }
542 }
543 else
544 {
545 2 $props->{ $prop } = $v;
546 }
547 }
548 else
549 {
550 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
551 {
552 0 ▶ if( !$v )
Branch: 2 branches
BranchTrueFalseTotal
if (not $v) { } 0 0 0
elsif ($v == 1) { } 0 0 0
553 {
554 0 $params->splice( $pos, 1 );
555 0 $props->delete( $prop );
556 }
557 elsif( $v == 1 )
558 {
559 0 $props->{ $prop } = undef;
560 }
561 else
562 {
563 0 $props->{ $prop } = $v;
564 }
565 }
566 else
567 {
568 0 $props->{ $prop } = $v;
569 }
570 }
571 # Used for non-standard properties during stringification
572 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
573 {
574 1 $self->_needs_quotes->set( $prop => 1 );
575 }
576 2 return( $v );
577 }
578 else
579 {
580 102 ▶ if( defined( $pos ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos) 102 0 102
581 {
582 return(
583 $opts->{maybe_boolean}
584 ? defined( $pos ) ? 1 : 0
585 102 ▶ : $props->{ $prop }
Branch: 2 branches
BranchTrueFalseTotal
$opts->{'maybe_boolean'} ? : 2 100 102
defined $pos ? : 2 0 2
586 );
587 }
588 0 return( '' );
589 }
590 }
591  
592 # Same as _set_get_param but with surrounding double quotes
593 sub _set_get_qparam
594 17 ▶{
Subroutine _set_get_qparam: called CC=6 SCAR=18.0
595 17 my $self = shift( @_ );
596 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
597 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
598 17 my $v;
599 17 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 3 14 17
600 {
601 3 $v = shift( @_ );
602 3 $v =~ s/^\"//;
603 3 $v =~ s/(?<!\\)\"$//;
604 3 $hv->param( $name => qq{"${v}"} );
605 }
606 else
607 {
608 14 $v = $hv->param( $name );
609 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
610 10 $v =~ s/^\"//;
611 10 $v =~ s/(?<!\\)\"$//;
612 }
613 13 return( $v );
614 }
615  
616 sub _set_get_value
617 0 ▶{
Subroutine _set_get_value: not called CC=2 SCAR=17.9
618 0 my $self = shift( @_ );
619 0 my $hv = $self->_hv;
620 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
621 {
622 0 $hv->value( shift( @_ ) );
623 }
624 0 return( $hv->value_data );
625 }
626  
627 # NOTE: sub FREEZE is inherited
628  
629 21 ▶sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: called CC=1 SCAR=0.0
Pod undocumented
630  
631 21 ▶sub STORABLE_thaw { CORE::return( CORE::shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: called CC=1 SCAR=0.0
Pod undocumented
632  
633 # NOTE: sub THAW is inherited
634  
635 # NOTE: HTTP::Promise::Field::QualityValue class
636 {
637 package
638 HTTP::Promise::Field::QualityValue;
639 BEGIN
640 {
641 9 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
642 9 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
643 9 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
644 9 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
645 '""' => 'as_string',
646 52 ▶ 'bool' => sub{1},
Subroutine __ANON__: called CC=1 SCAR=0.0
647 9 ▶ );
Subroutine BEGIN: not called CC=1 SCAR=0.0
648 };
649
650 sub as_string
651 101 ▶ {
Subroutine as_string: called CC=3 SCAR=11.0
652 101 my $self = shift( @_ );
653 101 my $elem = $self->element;
654 101 my $val = $self->value;
655 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
656 68 return( "${elem};q=${val}" );
657 }
658
659 sub init
660 52 ▶ {
Subroutine init: called CC=4 SCAR=14.6
661 52 my $self = shift( @_ );
662 52 my $elem = shift( @_ );
663 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
664 52 my $val = shift( @_ );
665 52 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 52 0 52
666 52 $self->element( $elem );
667 52 $self->value( $val );
668 52 return( $self );
669 }
670
671 174 ▶ sub element { return( shift->_set_get_scalar_as_object( 'element', @_ ) ); }
Subroutine element: called CC=1 SCAR=0.0
672
673 175 ▶ sub value { return( shift->_set_get_number( { field => 'value', undef_ok => 1 }, @_ ) ); }
Subroutine value: called CC=1 SCAR=0.0
674  
675 # NOTE: sub FREEZE is inherited
676  
677 17 ▶ sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: called CC=1 SCAR=0.0
678  
679 17 ▶ sub STORABLE_thaw { CORE::return( CORE::shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: called CC=1 SCAR=0.0
680  
681 # NOTE: sub THAW is inherited
682  
683 }
684  
685 9 1;
686 # NOTE: POD
687 __END__
« Promise/Headers/AltSvc.pm ↑ Summary Promise/Body/Form.pm »