| 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 Encode (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 9 | ▶ | use URI::Escape::XS (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 9 | ▶ | use Wanted; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 9 | ▶ | use overload ( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | '""' => 'as_string', | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 281 | ▶ | 'bool' => sub{1}, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | # No fallback on purpose | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 9 | ); | |||||||||||||||||||||||||||||||||||||||||
| 30 | # Accept: audio/*; q=0.2, audio/basic | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 9 | our $QV_ELEMENT = qr/(?:[^\;\,]+)/; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 9 | our $QV_VALUE = qr/(?:0(?:\.[0-9]{0,3})?|1(?:\.0{0,3})?)/; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 9 | our $VERSION = 'v0.1.3'; | |||||||||||||||||||||||||||||||||||||||||
| 34 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 9 | ▶ | 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 | 176 | ▶ | 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 | 7 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_filename_decode: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 7 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 55 | 7 | my $fname = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 56 | 7 | ▶ | $self->_load_class( 'HTTP::Promise::Headers' ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 7 | my( $new_fname, $charset, $lang ) = HTTP::Promise::Headers->decode_filename( $fname ); | |||||||||||||||||||||||||||||||||||||||||
| 58 | 7 | ▶ | if( defined( $new_fname ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | { | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 7 | $fname = $new_fname; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 7 | ▶ | return( wantarray() ? ( $fname, $charset, $lang ) : $fname ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | # rfc2231 <https://tools.ietf.org/html/rfc2231> | ||||||||||||||||||||||||||||||||||||||||||
| 66 | sub _filename_encode | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_filename_encode: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 5 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 69 | 5 | my $fname = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 70 | 5 | my $lang = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 71 | 5 | ▶ | if( $fname =~ /[^\x00-\x7f]/ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | ▶ | $lang = '' if( !defined( $lang ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 288 | ▶ | 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 | 44 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hv_as_string: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 44 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 85 | 44 | my $hv = $self->_hv; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 44 | ▶ | return( '' ) if( !$hv ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 44 | return( $hv->as_string( @_ ) ); | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | sub _get_header_value_object | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_header_value_object: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | $self->_load_class( 'Module::Generic::HeaderValue' ) || | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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))
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 @_)
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 11 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_hv: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 11 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 105 | 11 | ▶ | $self->_load_class( 'Module::Generic::HeaderValue' ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 11 | return( Module::Generic::HeaderValue->new( @_ ) ); | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | sub _new_qv_object | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 52 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_qv_object: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 52 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 52 | return( $o ); | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | sub _parse_header_value | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 68 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_header_value: called CC=5 SCAR=17.8
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 68 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 120 | 68 | my $this = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 121 | 68 | ▶ | return( $self->error( "No header value was provided to parse." ) ) if( !defined( $this ) || !length( "$this" ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $this and length "$this"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 68 | ▶ | $self->_load_class( 'Module::Generic::HeaderValue' ) || | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 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))
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, @_)
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | return( $self->pass_error( Module::Generic::HeaderValue->error ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 68 | 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 | 15 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_quality_value: called CC=5 SCAR=16.6
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 15 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $str and length "$str"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 8 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_qstring_join: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 8 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 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 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_qstring_split: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 3 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_qv_add: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 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))
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 25 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_qv_as_string: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 25 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 204 | 25 | my $all = $self->elements; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 25 | ▶ | return( '' ) if( $all->is_empty ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_qv_get: called CC=7 SCAR=20.4
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 5 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $this and length "$this"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 5 | my $all = $self->elements; | |||||||||||||||||||||||||||||||||||||||||
| 218 | 5 | ▶ | if( $self->_is_a( $this => 'HTTP::Promise::Field::QualityValue' ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | { | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | my $pos = $all->pos( $this ); | |||||||||||||||||||||||||||||||||||||||||
| 221 | 1 | ▶ | return( $all->[$pos] ) if( defined( $pos ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | else | ||||||||||||||||||||||||||||||||||||||||||
| 224 | { | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 4 | foreach( @$all ) | |||||||||||||||||||||||||||||||||||||||||
| 226 | { | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 7 | ▶ | return( $_ ) if( $_->element eq $this ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | return( '' ); | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | sub _qv_match | ||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_qv_match: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | my $this = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | return( '' ) if( !defined( $this ) || !length( "$this" ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $this and length "$this"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | $this = [split( /(?:[[:blank:]]+|[[:blank:]]*\,[[:blank:]]*)/, "$this" )] if( !$self->_is_array( $this ) && ( !ref( $this ) || overload::Method( $this => '""' ) ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not $self->_is_array($this) and !ref($this) || overload::Method($this, "\"\"")
not ref $this or overload::Method($this, "\"\"")
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, "\"\"")
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | my $ordered = [map( lc( $_ ), @$this )]; | |||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | return( '' ) if( !scalar( @$ordered ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | my $acceptables = $self->can( 'sort' ) ? $self->sort : $self->_qv_sort; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | $ok->push( $wildcard_ok->list ) if( !$wildcard_ok->is_empty ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | else | ||||||||||||||||||||||||||||||||||||||||||
| 255 | { | ||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | for( my $i = 0; $i < scalar( @$ordered ); $i++ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | { | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | if( $e_lc eq $ordered->[$i] ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_qv_match_wildcard: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | return( $self->error( "This is not a wildcard acceptable value." ) ) if( $acceptable->index( '*' ) == -1 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | return( $self->error( "Proposed values must be an array reference." ) ) unless( $self->_is_array( $proposals ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | return( $self->error( "Original array of proposed values must be an array reference." ) ) unless( $self->_is_array( $original ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | my $ok = $self->new_array; | |||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | if( $acceptable->index( '/' ) != -1 ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | { | ||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my( $main, $sub ) = $acceptable->element->split( qr/\// ); | |||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | for( my $i = 0; $i < scalar( @$proposals ); $i++ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | { | ||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | if( $sub eq '*' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | elsif( $main eq $this_main ) | ||||||||||||||||||||||||||||||||||||||||||
| 301 | { | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | if( $sub eq '*' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_qv_remove: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | 1 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | { | ||||||||||||||||||||||||||||||||||||||||||
| 335 | 2 | ▶ | if( $all->[$i]->element eq "$this" ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_qv_sort: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 1 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 348 | 1 | my $opts = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 349 | 1 | ▶ | $opts->{asc} = 0 if( !exists( $opts->{asc} ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
$_[1]->value // 1
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
Truth table0%0/2
A
A= $_[1]->value
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 1 | ▶ | : $all->sort(sub{ ( $_[1]->value // 1 ) <=> ( $_[0]->value // 1 ) }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
Condition100%4/4
$_[1]->value // 1
$_[0]->value // 1
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
Truth table100%2/2
A
A= $_[0]->value
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | 1 | $self->elements( $sorted ); | |||||||||||||||||||||||||||||||||||||||||
| 355 | 1 | return( $sorted ); | |||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | sub _set_get_param_boolean | ||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_get_param_boolean: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 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.'))
MC/DC0%0/1
shift @_ || (return $self->error('No parameter name was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||
| 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!'))
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
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | { | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | my $v = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | if( $v ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 93 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_get_param: called CC=6 SCAR=18.5
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 93 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 381 | 93 | ▶ | my $name = shift( @_ ) || return( $self->error( "No parameter name was provided." ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift @_ || (return $self->error('No parameter name was provided.'))
MC/DC0%0/1
shift @_ || (return $self->error('No parameter name was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 93 | 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 | 93 | ▶ | return( '' ) if( !scalar( @_ ) && !$hv ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
scalar @_ or $hv
MC/DC0%0/2
scalar @_ or $hv
scalar @_
$hv
Truth table66%2/3
A or B
A= scalar @_B= $hv
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | 93 | ▶ | return( $self->error( "Header value object (Module::Generic::HeaderValue) could not be found!" ) ) if( !$hv ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | 93 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | { | ||||||||||||||||||||||||||||||||||||||||||
| 389 | 15 | $hv->param( $name => shift( @_ ) ); | |||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||
| 391 | 93 | return( $hv->param( $name ) ); | |||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | sub _set_get_params | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_get_params: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 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!'))
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
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | my $params = $hv->params; | |||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | { | ||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | while( my( $n, $v ) = splice( @_, 0, 2 ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 42 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_get_properties_as_string: called CC=10 SCAR=23.2
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | 42 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 415 | 42 | my $opts = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 416 | 42 | ▶ | my $sep = $opts->{separator} || $opts->{sep} || ','; | ||||||||||||||||||||||||||||||||||||||||
|
Condition80%4/5
$opts->{'separator'} || $opts->{'sep'} || ','
$opts->{"separator"} or $opts->{"sep"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | 42 | ▶ | my $eq = $opts->{equal} || '='; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{'equal'} || '='
MC/DC100%1/1
$opts->{'equal'} || '='
$opts->{'equal'}
Truth table100%2/2
A
A= $opts->{'equal'}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 42 | my @res = (); | |||||||||||||||||||||||||||||||||||||||||
| 423 | 9 | ▶ | no overloading '""'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 42 | foreach( @$params ) | |||||||||||||||||||||||||||||||||||||||||
| 425 | { | ||||||||||||||||||||||||||||||||||||||||||
| 426 | 134 | ▶ | if( !exists( $props->{ $_ } ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||
| 436 | 42 | return( join( "${sep} ", @res ) ); | |||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | # Used by Cache-Control | ||||||||||||||||||||||||||||||||||||||||||
| 440 | sub _set_get_property_boolean | ||||||||||||||||||||||||||||||||||||||||||
| 441 | 46 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_get_property_boolean: called CC=9 SCAR=22.2
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | 46 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 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.'))
MC/DC0%0/1
shift @_ || (return $self->error('No parameter name was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | { | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 9 | my $bool = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 450 | 9 | ▶ | if( defined( $pos ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 451 | { | ||||||||||||||||||||||||||||||||||||||||||
| 452 | 4 | ▶ | if( defined( $bool ) && $bool ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $bool and $bool
MC/DC100%2/2
defined $bool and $bool
defined $bool
$bool
Truth table100%3/3
A and B
A= defined $boolB= $bool
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $bool and $bool
MC/DC0%0/2
defined $bool and $bool
defined $bool
$bool
Truth table33%1/3
A and B
A= defined $boolB= $bool
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | # Used by Cache-Control, Expect-CT | ||||||||||||||||||||||||||||||||||||||||||
| 489 | sub _set_get_property_number | ||||||||||||||||||||||||||||||||||||||||||
| 490 | 28 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_get_property_number: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | 28 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 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.'))
MC/DC0%0/1
shift @_ || (return $self->error('No parameter name was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | 28 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $v and not $self->_is_integer($v)
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 106 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_get_property_value: called CC=25 SCAR=44.3
| |||||||||||||||||||||||||||||||||||||||||||
| 505 | 106 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 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.'))
MC/DC0%0/1
shift @_ || (return $self->error('No parameter name was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||
| 507 | 106 | my $opts = {}; | |||||||||||||||||||||||||||||||||||||||||
| 508 | 106 | ▶ | $opts = pop( @_ ) if( ref( $_[-1] ) eq 'HASH' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | 106 | ▶ | $opts->{needs_quotes} //= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{"needs_quotes"} //= 0
MC/DC100%1/1
$opts->{"needs_quotes"} //= 0
$opts->{"needs_quotes"}
Truth table100%2/2
A
A= $opts->{"needs_quotes"}
| |||||||||||||||||||||||||||||||||||||||||||
| 510 | 106 | ▶ | $opts->{maybe_boolean} //= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{"maybe_boolean"} //= 0
MC/DC100%1/1
$opts->{"maybe_boolean"} //= 0
$opts->{"maybe_boolean"}
Truth table100%2/2
A
A= $opts->{"maybe_boolean"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 515 | { | ||||||||||||||||||||||||||||||||||||||||||
| 516 | 4 | my $v = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 517 | 4 | ▶ | if( !defined( $v ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | { | ||||||||||||||||||||||||||||||||||||||||||
| 519 | 2 | ▶ | $self->params->splice( $pos, 1 ) if( defined( $pos ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 520 | 2 | return( $self->properties->delete( $prop ) ); | |||||||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||
| 523 | # Not there yet, add the value | ||||||||||||||||||||||||||||||||||||||||||
| 524 | 2 | ▶ | if( !defined( $pos ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 525 | { | ||||||||||||||||||||||||||||||||||||||||||
| 526 | 2 | ▶ | $params->push( $prop ) if( !$opts->{maybe_boolean} || ( $opts->{maybe_boolean} && $v ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
not $opts->{"maybe_boolean"} or $opts->{"maybe_boolean"} and $v
$opts->{"maybe_boolean"} and $v
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
| |||||||||||||||||||||||||||||||||||||||||||
| 527 | 2 | ▶ | if( exists( $opts->{maybe_boolean} ) && $opts->{maybe_boolean} ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $opts->{"maybe_boolean"} and $opts->{"maybe_boolean"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 528 | { | ||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | ▶ | if( $v == 1 ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
exists $opts->{"maybe_boolean"} and $opts->{"maybe_boolean"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 550 | { | ||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | ▶ | if( !$v ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$opts->{"needs_quotes"} and $self->can("_needs_quotes")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 580 | { | ||||||||||||||||||||||||||||||||||||||||||
| 581 | return( | ||||||||||||||||||||||||||||||||||||||||||
| 582 | $opts->{maybe_boolean} | ||||||||||||||||||||||||||||||||||||||||||
| 583 | ? defined( $pos ) ? 1 : 0 | ||||||||||||||||||||||||||||||||||||||||||
| 584 | 102 | ▶ | : $props->{ $prop } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 17 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_get_qparam: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 594 | 17 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 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.'))
MC/DC0%0/1
shift @_ || (return $self->error('No parameter name was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||
| 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!'))
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
| |||||||||||||||||||||||||||||||||||||||||||
| 597 | 17 | my $v; | |||||||||||||||||||||||||||||||||||||||||
| 598 | 17 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $v and length "$v"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 609 | 10 | $v =~ s/^\"//; | |||||||||||||||||||||||||||||||||||||||||
| 610 | 10 | $v =~ s/(?<!\\)\"$//; | |||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||
| 612 | 13 | return( $v ); | |||||||||||||||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||
| 615 | sub _set_get_value | ||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_get_value: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 617 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | my $hv = $self->_hv; | |||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 641 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 642 | 9 | ▶ | use parent qw( Module::Generic ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 643 | 9 | ▶ | use overload ( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 644 | '""' => 'as_string', | ||||||||||||||||||||||||||||||||||||||||||
| 645 | 52 | ▶ | 'bool' => sub{1}, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 646 | 9 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 647 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||
| 649 | sub as_string | ||||||||||||||||||||||||||||||||||||||||||
| 650 | 101 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 651 | 101 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 652 | 101 | my $elem = $self->element; | |||||||||||||||||||||||||||||||||||||||||
| 653 | 101 | my $val = $self->value; | |||||||||||||||||||||||||||||||||||||||||
| 654 | 101 | ▶ | return( $elem ) if( !defined( $val ) || !length( "${val}" ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $val and length "$val"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 655 | 68 | return( "${elem};q=${val}" ); | |||||||||||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||
| 658 | sub init | ||||||||||||||||||||||||||||||||||||||||||
| 659 | 52 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||||||||||||||||
| 660 | 52 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $elem and length "$elem"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 663 | 52 | my $val = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 664 | 52 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 685 | # NOTE: POD | ||||||||||||||||||||||||||||||||||||||||||
| 686 | __END__ | ||||||||||||||||||||||||||||||||||||||||||