| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | ## Module Generic - ~/lib/Module/Generic/HeaderValue.pm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ## Version v0.4.4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | ## Copyright(c) 2026 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | ## Created 2021/11/03 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | ## Modified 2026/03/10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | ## All rights reserved | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | ## This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | ## under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | package Module::Generic::HeaderValue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | BEGIN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 4 | warnings::register_categories( 'Module::Generic' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 4 | ▶ | use parent qw( Module::Generic ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 4 | ▶ | use vars qw( $QUOTE_REGEXP $DELIMITER $DELIMITERS $VCHAR $VCHAR_WITHOUT_DELIM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 4 | $TOKEN_REGEXP $TEXT_REGEXP ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 4 | ▶ | use overload ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | '""' => 'as_string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | bool => sub{ return( $_[0] ) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 4 | fallback => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 4 | our $QUOTE_REGEXP = qr/([\\"])/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # RegExp to match type in rfc7231 section 3.1.1.1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # <https://datatracker.ietf.org/doc/html/rfc7231#page-8> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # rfc2616, section 2.2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # <https://datatracker.ietf.org/doc/html/rfc2616#section-2.2> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # media-type = type "/" subtype | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # type = token | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # subtype = token | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # e.g.: text/html; charset="utf-8" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # rfc6265 <https://datatracker.ietf.org/doc/html/rfc6265#page-8> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # token = cookie-octet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # token syntax | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # rfc2616 <https://datatracker.ietf.org/doc/html/rfc2616#section-2.2> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 4 | our $DELIMITER = qr/["\(\),\/:;<=>\?\@\[\]{}]/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 4 | our $DELIMITERS = qr/["\(\),\/:;<=>\?\@\[\]{}]+/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # Visible ASCII, i.e. 32 to 126 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 4 | our $VCHAR = qr/[\032-\126]+/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 4 | our $VCHAR_WITHOUT_DELIM = q/\!\#\$\%\&\'\*\+\-\.\^_\`\|\~A-Za-z0-9/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # rfc7230 <https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # TOKEN_REGEXP = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # "!" / "#" / "$" / "%" / "&" / "'" / "*" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # / DIGIT / ALPHA | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # ; any VCHAR, except delimiters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # our $TOKEN_REGEXP = qr/[^[:cntrl:]()<>\@,;:\\"\/\[\]\?\=\{\}[:blank:]\h]+/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # More explicit version from the previous and also based on rfc7230, section 3.2.6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 4 | our $TOKEN_REGEXP = qr/[${VCHAR_WITHOUT_DELIM}]+/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # "<any OCTET except CTLs, but including LWS>" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # <https://datatracker.ietf.org/doc/html/rfc2616#section-2.2> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | our $TEXT_REGEXP = qr/(?>[[:blank:]\h]|[^[:cntrl:]\"])*+/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # \x21\x23-\x2B\x2D-\x3A\x3C-\x5B\x5D-\x7E | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # our $COOKIE_DATA_RE = qr/[^[:cntrl][:blank:]\h\"\,\;\\]+/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # our $COOKIE_DATA_RE = qr/[^[:cntrl:]\"\;\\]+/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # our $TYPE_REGEXP = qr/(?:[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+)|$TOKEN_REGEXP/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # our $TOKEN_REGEXP = qr/[!#$%&'*+.^_`|~0-9A-Za-z-]+/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # our $TEXT_REGEXP = qr/[\u000b\u0020-\u007e\u0080-\u00ff]+|$COOKIE_DATA_RE/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 4 | our $VERSION = 'v0.4.4'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | sub init | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 14 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 14 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 14 | my $value = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 4 | ▶ | no overloading; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 14 | ▶ | return( $self->error( "No value provided." ) ) if( !defined( $value ) || !length( $value ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $value and length $value
MC/DC0%0/2
defined $value and length $value
defined $value
length $value
Truth table33%1/3
A and B
A= defined $valueB= length $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 14 | ▶ | $value = [split( /[[:blank:]\h]*\=[[:blank:]\h]*/, $value, 2 )] if( !$self->_is_array( $value ) && index( $value, '=' ) != -1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $self->_is_array($value) and index($value, "=") != -1
MC/DC100%2/2
not $self->_is_array($value) and index($value, "=") != -1
not $self->_is_array($value)
index($value, "=") != -1
Truth table100%3/3
not(A) and B
A= not $self->_is_array($value)B= index($value, "=") != -1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 14 | $self->{original} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 14 | ▶ | $self->{value} = $self->_is_array( $value ) ? $value : [ $value ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 14 | $self->{decode} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 14 | $self->{encode} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 14 | $self->{params} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 14 | $self->{token_max} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 14 | $self->{value_max} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 14 | $self->{_init_strict_use_sub} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 14 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 4 | ▶ | use overloading; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 14 | ▶ | if( scalar( @{$self->{value}} ) > 1 && $self->decode ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
scalar @{$self->{"value"};} > 1 and $self->decode
MC/DC100%2/2
scalar @{$self->{"value"};} > 1 and $self->decode
scalar @{$self->{"value"};} > 1
$self->decode
Truth table100%3/3
A and B
A= scalar @{$self->{"value"};} > 1B= $self->decode
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | $self->{value}->[1] = URI::Escape::uri_unescape( $self->{value}->[1] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 14 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | sub new_from_multi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 7 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_from_multi: called CC=11 SCAR=25.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 7 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 7 | my $s = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 7 | ▶ | return( $self->error( 'Header value is required' ) ) if( !defined( $s ) || !length( $s ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $s and length $s
MC/DC0%0/2
defined $s and length $s
defined $s
length $s
Truth table33%1/3
A and B
A= defined $sB= length $s
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 7 | my $opts = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 7 | ▶ | $opts->{debug} //= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts->{"debug"} //= 0
MC/DC0%0/1
$opts->{"debug"} //= 0
$opts->{"debug"}
Truth table50%1/2
A
A= $opts->{"debug"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 7 | ▶ | $opts->{decode} //= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts->{"decode"} //= 0
MC/DC0%0/1
$opts->{"decode"} //= 0
$opts->{"decode"}
Truth table50%1/2
A
A= $opts->{"decode"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 7 | ▶ | my $me = bless( $opts => ( ref( $self ) || $self ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 7 | my $parts = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 7 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 7 | ▶ | if( $self->_is_array( $s ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $parts = $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # split by comma, but avoid comma that would be part of an attribute value, such | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # as in cookie's expires value: foo=val; Expires=Mon, 01 Nov 2021 08:12:10 GMT, bar=baz; Max-Age=3600 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # would be 2 cookies: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # foo=val; Expires=Mon, 01 Nov 2021 08:12:10 GMT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # bar=baz; Max-Age=3600 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # Here, the regexp part (\\.) is on purpose so that the separator can be captured when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # it is undef, which signals to us this is a new part | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 7 | foreach( split( /(\\.)|\,[[:blank:]]*(?=(?:[^\s\;\=]+(?:\=|\;|\,|\z)))/, $s ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 9 | ▶ | defined( $_ ) ? do{ $parts->[$i] .= $_ } : do{ $i++ }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 7 | my $res = $self->new_array; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 7 | ▶ | for( my $j = 0; $j < scalar( @$parts ); $j++ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 8 | my $o = $me->new_from_header( $parts->[$j] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 8 | ▶ | return( $self->pass_error( $me->error ) ) if( !defined( $o ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 8 | $res->push( $o ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 7 | return( $res ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | sub new_from_header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 8 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_from_header: called CC=41 SCAR=49.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 8 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 8 | my $s = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 8 | ▶ | $s =~ s/\015?\012$//gs if( index( $s, "\012" ) != -1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 8 | ▶ | return( $self->error( 'Header value is required' ) ) if( !defined( $s ) || !length( $s ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $s and length $s
MC/DC0%0/2
defined $s and length $s
defined $s
length $s
Truth table33%1/3
A and B
A= defined $sB= length $s
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 8 | my $opts = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 8 | ▶ | $opts->{debug} //= $self->debug || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$opts->{"debug"} //= $self->debug || 0
$self->debug || 0
MC/DC0%0/1
$opts->{"debug"} //= $self->debug || 0
$opts->{"debug"}
Truth table50%1/2
A
A= $opts->{"debug"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 8 | ▶ | $opts->{decode} //= $self->decode || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$opts->{"decode"} //= $self->decode || 0
$self->decode || 0
MC/DC0%0/1
$opts->{"decode"} //= $self->decode || 0
$opts->{"decode"}
Truth table50%1/2
A
A= $opts->{"decode"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 8 | ▶ | $opts->{encode} //= $self->encode || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$opts->{"encode"} //= $self->encode || 0
$self->encode || 0
MC/DC0%0/1
$opts->{"encode"} //= $self->encode || 0
$opts->{"encode"}
Truth table50%1/2
A
A= $opts->{"encode"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 8 | ▶ | $opts->{token_max} //= $self->token_max; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts->{"token_max"} //= $self->token_max
MC/DC0%0/2
$opts->{"token_max"} //= $self->token_max
$opts->{"token_max"}
$self->token_max
Truth table33%1/3
A //= B
A= $opts->{"token_max"}B= $self->token_max
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 8 | ▶ | $opts->{value_max} //= $self->value_max; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts->{"value_max"} //= $self->value_max
MC/DC0%0/2
$opts->{"value_max"} //= $self->value_max
$opts->{"value_max"}
$self->value_max
Truth table33%1/3
A //= B
A= $opts->{"value_max"}B= $self->value_max
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 8 | ▶ | $opts->{separator} //= ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts->{"separator"} //= ""
MC/DC0%0/1
$opts->{"separator"} //= ""
$opts->{"separator"}
Truth table50%1/2
A
A= $opts->{"separator"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # If true, this will not assume the first part of the parameters passed is the main value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | # This is the case for the header field Strict-Transport-Security | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 8 | ▶ | $opts->{params_only} //= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts->{"params_only"} //= 0
MC/DC0%0/1
$opts->{"params_only"} //= 0
$opts->{"params_only"}
Truth table50%1/2
A
A= $opts->{"params_only"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 8 | ▶ | unless( $self->_is_object( $self ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | $self = bless( $opts => $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 8 | ▶ | my $sep = CORE::length( $opts->{separator} ) ? $opts->{separator} : ';'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 8 | my @parts = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 8 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 8 | foreach( split( /(\\.)|$sep/, $s ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 26 | ▶ | defined( $_ ) ? do{ $parts[$i] .= $_ } : do{ $i++ }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 8 | my $obj; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 8 | ▶ | if( $opts->{params_only} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | $obj = $self->new( [] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 8 | my $header_val = shift( @parts ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 8 | my( $n, $v ) = split( /[[:blank:]\h]*\=[[:blank:]\h]*/, $header_val, 2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 8 | ▶ | $v =~ s/^\"|(?<!\\)\"$//g if( CORE::defined( $v ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 8 | ▶ | if( $opts->{decode} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | $n = URI::Escape::uri_unescape( $n ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | $v = URI::Escape::uri_unescape( $v ) if( defined( $v ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 8 | ▶ | $obj = $self->new( defined( $v ) ? [$n, $v] : $n ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 8 | $obj->debug( $opts->{debug} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 8 | $obj->decode( $opts->{decode} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 8 | $obj->encode( $opts->{encode} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 8 | my $token_max_len = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 8 | my $value_max_len = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 8 | ▶ | $token_max_len = $opts->{token_max} if( defined( $opts->{token_max} ) && CORE::length( $opts->{token_max} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $opts->{"token_max"} and length $opts->{"token_max"}
MC/DC0%0/2
defined $opts->{"token_max"} and length $opts->{"token_max"}
defined $opts->{"token_max"}
length $opts->{"token_max"}
Truth table33%1/3
A and B
A= defined $opts->{"token_max"}B= length $opts->{"token_max"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 8 | ▶ | $value_max_len = $opts->{value_max} if( defined( $opts->{value_max} ) && CORE::length( $opts->{value_max} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $opts->{"value_max"} and length $opts->{"value_max"}
MC/DC0%0/2
defined $opts->{"value_max"} and length $opts->{"value_max"}
defined $opts->{"value_max"}
length $opts->{"value_max"}
Truth table33%1/3
A and B
A= defined $opts->{"value_max"}B= length $opts->{"value_max"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 8 | foreach my $frag ( @parts ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 9 | $frag =~ s/^[[:blank:]\h\v]+|[[:blank:]\h\v]+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # Values are forbidden from having "=" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # <https://datatracker.ietf.org/doc/html/rfc6265#section-5.2> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 9 | my( $attribute, $value ) = split( /[[:blank:]\h]*\=[[:blank:]\h]*/, $frag, 2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 9 | ▶ | if( !defined( $attribute ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | warn( ref( $self ), "::new_from_header(): Found undefined attribute while splitting fragment '", ( $frag // '' ), "' in header value '", ( $s // '' ), "'.\n" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/4
$frag // ""
$s // ""
MC/DC0%0/1
$frag // ""
$frag
MC/DC0%0/1
$s // ""
$s
Truth table0%0/2
A
A= $frag
Truth table0%0/2
A
A= $s
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 9 | ▶ | $value =~ s/^\"|\"$//g if( defined( $value ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # Check character string and length. Should not be more than 255 characters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # https://datatracker.ietf.org/doc/html/rfc1341 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # http://www.iana.org/assignments/media-types/media-types.xhtml | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # Won't complain if this does not meet our requirement, but will discard it silently | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 9 | ▶ | if( $attribute =~ /^$TOKEN_REGEXP$/ && ( $token_max_len <= 0 || CORE::length( $attribute ) <= $token_max_len ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$attribute =~ /^$Module::Generic::HeaderValue::TOKEN_REGEXP$/ and $token_max_len <= 0 || length $attribute <= $token_max_len
$token_max_len <= 0 or length $attribute <= $token_max_len
MC/DC0%0/3
$attribute =~ /^$Module::Generic::HeaderValue::TOKEN_REGEXP$/ and $token_max_len <= 0 || length $attribute <= $token_max_len
$attribute =~ /^$Module::Generic::HeaderValue::TOKEN_REGEXP$/
$token_max_len <= 0
length $attribute <= $token_max_len
Truth table25%1/4
A and B or C
A= $attribute =~ /^$Module::Generic::HeaderValue::TOKEN_REGEXP$/B= $token_max_len <= 0C= length $attribute <= $token_max_len
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 9 | ▶ | if( defined( $value ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 8 | ▶ | if( $value =~ /^$TEXT_REGEXP$/ && ( $value_max_len <= 0 || CORE::length( $value ) <= $value_max_len ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$value =~ /^$Module::Generic::HeaderValue::TEXT_REGEXP$/ and $value_max_len <= 0 || length $value <= $value_max_len
$value_max_len <= 0 or length $value <= $value_max_len
MC/DC0%0/3
$value =~ /^$Module::Generic::HeaderValue::TEXT_REGEXP$/ and $value_max_len <= 0 || length $value <= $value_max_len
$value =~ /^$Module::Generic::HeaderValue::TEXT_REGEXP$/
$value_max_len <= 0
length $value <= $value_max_len
Truth table25%1/4
A and B or C
A= $value =~ /^$Module::Generic::HeaderValue::TEXT_REGEXP$/B= $value_max_len <= 0C= length $value <= $value_max_len
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 8 | $obj->param( lc( $attribute ) => $value ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | warn( "Value for property \"$attribute\" contained some illegal characters or exceeded the maximum size of '$value_max_len'.\n" ) if( warnings::enabled( 'Module::Generic' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 1 | $obj->param( lc( $attribute ) => undef ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | warn( "Token \"$attribute\" contains illegal characters or exceeds the maximum size of '$token_max_len'.\n" ) if( warnings::enabled( 'Module::Generic' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 8 | return( $obj ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # This class does not convert to an HASH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | sub as_hash { return( $_[0] ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_hash: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | sub as_string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=23 SCAR=39.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 4 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 4 | ▶ | if( !$self->original->defined || !$self->original->length ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->original->defined and $self->original->length
MC/DC0%0/2
$self->original->defined and $self->original->length
$self->original->defined
$self->original->length
Truth table33%1/3
A and B
A= $self->original->definedB= $self->original->length
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 4 | ▶ | my $prime_params = $self->new_array( ( @_ && $self->_is_array( $_[0] ) ) ? shift( @_ ) : [] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and $self->_is_array($_[0])
MC/DC0%0/2
@_ and $self->_is_array($_[0])
@_
$self->_is_array($_[0])
Truth table33%1/3
A and B
A= @_B= $self->_is_array($_[0])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 4 | my $opts = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 4 | my $string = $self->value_as_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 4 | my $token_max_len = $self->token_max; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 4 | my $value_max_len = $self->value_max; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # Append parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 4 | ▶ | if( $self->params->length ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 4 | my $params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 4 | ▶ | if( !$prime_params->is_empty ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | $params = $self->new_array; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | foreach( @$prime_params ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | $params->push( $_ ) if( $self->params->exists( $_ ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | my $others = $self->params->keys->except( $params ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | $params->merge( $others ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 4 | $params = $self->params->keys->sort; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 4 | ▶ | for( my $i = 0; $i < $params->length; $i++ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 9 | ▶ | if( $params->[$i] !~ /^$TOKEN_REGEXP$/ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | return( $self->error( "Invalid parameter name: \"" . $params->[$i] . "\"" ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | ▶ | elsif( $token_max_len > 0 && CORE::length( $params->[$i] ) > $token_max_len ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$token_max_len > 0 and length $params->[$i] > $token_max_len
MC/DC50%1/2
$token_max_len > 0 and length $params->[$i] > $token_max_len
$token_max_len > 0
length $params->[$i] > $token_max_len
Truth table66%2/3
A and B
A= $token_max_len > 0B= length $params->[$i] > $token_max_len
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 1 | return( $self->error( "Parameter name \"", substr( $params->[$i], 0, $token_max_len ), "\" exceeds the maximum length of $token_max_len" ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 8 | ▶ | if( length( $string ) > 0 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 8 | $string .= '; '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | # No escaping of property values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # $string .= $params->[$i] . '=' . ( $self->encode ? URI::Escape::uri_escape( $self->params->get( $params->[$i] ) ) : $self->qstring( $self->params->get( $params->[$i] ) ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 8 | my $value = $self->params->get( $params->[$i] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 8 | ▶ | if( defined( $value ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 7 | ▶ | if( $value_max_len > 0 && CORE::length( $value ) > $value_max_len ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$value_max_len > 0 and length $value > $value_max_len
MC/DC50%1/2
$value_max_len > 0 and length $value > $value_max_len
$value_max_len > 0
length $value > $value_max_len
Truth table66%2/3
A and B
A= $value_max_len > 0B= length $value > $value_max_len
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 1 | return( $self->error( "Parameter \"", $params->[$i], "\" value exceeds the maximum length of $value_max_len" ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # If the caller has requested it, we can force the double quotes on this token name, otherwise, by default, it is automatic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | my $qstr = $self->qstring( $value, ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | ( ref( $opts->{quote} ) eq 'ARRAY' && scalar( grep( $params->[$i], @{$opts->{quote}} ) ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
not ref $opts->{"quote"} and ($opts->{"quote"} // "") eq $params->[$i]
$opts->{"quote"} // ""
MC/DC0%0/2
not ref $opts->{"quote"} and ($opts->{"quote"} // "") eq $params->[$i]
not ref $opts->{"quote"}
$opts->{"quote"}
Truth table33%1/3
not(A) and B
A= not ref $opts->{"quote"}B= $opts->{"quote"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 6 | ▶ | ( !ref( $opts->{quote} ) && ( $opts->{quote} // '' ) eq $params->[$i] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition40%2/5
ref $opts->{"quote"} eq "ARRAY" and scalar grep($params->[$i], @{$$opts{"quote"};}) or not ref $opts->{"quote"} and ($opts->{"quote"} // "") eq $params->[$i]
ref $opts->{"quote"} eq "ARRAY" and scalar grep($params->[$i], @{$$opts{"quote"};})
MC/DC0%0/2
ref $opts->{"quote"} eq "ARRAY" and scalar grep($params->[$i], @{$$opts{"quote"};}) or not ref $opts->{"quote"} and ($opts->{"quote"} // "") eq $params->[$i]
ref $opts->{"quote"} eq "ARRAY"
not ref $opts->{"quote"} and ($opts->{"quote"} // "") eq $params->[$i]
Truth table33%1/3
A or B
A= ref $opts->{"quote"} eq "ARRAY"B= not ref $opts->{"quote"} and ($opts->{"quote"} // "") eq $params->[$i]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | ) ? ( quote => 1 ) : () | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 6 | ▶ | if( !defined( $qstr ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | warn( $self->error ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 6 | $string .= $params->[$i] . '=' . $qstr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 1 | $string .= $params->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 2 | $self->original( $string ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 2 | return( $self->original->scalar ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 29 | ▶ | sub decode { return( shift->_set_get_boolean( 'decode', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 30 | ▶ | sub encode { return( shift->_set_get_boolean( 'encode', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 15 | ▶ | sub original { return( shift->_set_get_scalar_as_object( 'original', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
original: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | sub param | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 28 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
param: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 28 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 28 | my $k = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 28 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 14 | return( $self->params->set( $k => @_ ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 14 | return( $self->params->get( $k ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 47 | ▶ | sub params { return( shift->_set_get_hash_as_mix_object( 'params', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
params: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | sub qstring | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 8 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
qstring: called CC=6 SCAR=18.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 8 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 8 | my $str = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 8 | my $opts = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | # no need to quote tokens, unless caller explicitly requires it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 8 | ▶ | if( $str =~ /^$TOKEN_REGEXP$/ || $str =~ /^\"(.*?)\"$/ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$str =~ /^$Module::Generic::HeaderValue::TOKEN_REGEXP$/ or $str =~ /^\"(.*?)\"$/
MC/DC50%1/2
$str =~ /^$Module::Generic::HeaderValue::TOKEN_REGEXP$/ or $str =~ /^\"(.*?)\"$/
$str =~ /^$Module::Generic::HeaderValue::TOKEN_REGEXP$/
$str =~ /^\"(.*?)\"$/
Truth table66%2/3
A or B
A= $str =~ /^$Module::Generic::HeaderValue::TOKEN_REGEXP$/B= $str =~ /^\"(.*?)\"$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 2 | ▶ | if( $opts->{quote} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | $str =~ s/$QUOTE_REGEXP/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | return( '"' . $str . '"' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 2 | return( $str ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 6 | ▶ | if( length( $str ) > 0 && $str !~ /^$TEXT_REGEXP$/ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $str > 0 and not $str =~ /^$Module::Generic::HeaderValue::TEXT_REGEXP$/
MC/DC50%1/2
length $str > 0 and not $str =~ /^$Module::Generic::HeaderValue::TEXT_REGEXP$/
length $str > 0
not $str =~ /^$Module::Generic::HeaderValue::TEXT_REGEXP$/
Truth table66%2/3
A and not(B)
A= length $str > 0B= not $str =~ /^$Module::Generic::HeaderValue::TEXT_REGEXP$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 1 | return( $self->error( 'Invalid parameter value' ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # An empty string is valid as a quoted-string per RFC 2616 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 5 | $str =~ s/$QUOTE_REGEXP/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 5 | return( '"' . $str . '"' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | sub reset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 1 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 1 | $self->{original} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 1 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | sub token_escape | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
token_escape: called CC=3 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 1 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 1 | my $v = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 1 | ▶ | return( $v ) if( !defined( $v ) || !length( $v ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $v and length $v
MC/DC0%0/2
defined $v and length $v
defined $v
length $v
Truth table33%1/3
A and B
A= defined $vB= length $v
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 1 | $v =~ s/($DELIMITER)/sprintf("%%%02X", ord($1))/ge; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 1 | return( $v ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 16 | ▶ | sub token_max { return( shift->_set_get_number( 'token_max', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
token_max: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 33 | ▶ | sub value { return( shift->_set_get_array_as_object( 'value', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
value: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | sub value_as_string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 13 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
value_as_string: called CC=14 SCAR=29.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 13 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 13 | my $string = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 13 | ▶ | if( $self->value->length ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 13 | my( $n, $v ) = $self->value->list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 13 | ▶ | if( defined( $v ) && $n !~ /^$TOKEN_REGEXP$/ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $v and not $n =~ /^$Module::Generic::HeaderValue::TOKEN_REGEXP$/
MC/DC0%0/2
defined $v and not $n =~ /^$Module::Generic::HeaderValue::TOKEN_REGEXP$/
defined $v
not $n =~ /^$Module::Generic::HeaderValue::TOKEN_REGEXP$/
Truth table66%2/3
A and not(B)
A= defined $vB= not $n =~ /^$Module::Generic::HeaderValue::TOKEN_REGEXP$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | if( $self->encode ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | # $n = URI::Escape::uri_escape( $n ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | # We cannot simply use URI::Escape, because the scope of what we need to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | # escape and NOT escape is not aligned with what URI::Escape does | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | $n = $self->token_escape( $n ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | return( $self->error( "Invalid token \"$n\"" ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | ▶ | elsif( !defined( $v ) && $n !~ /^$TEXT_REGEXP$/ ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $v || $n =~ /^$Module::Generic::HeaderValue::TEXT_REGEXP$/
MC/DC0%0/2
defined $v || $n =~ /^$Module::Generic::HeaderValue::TEXT_REGEXP$/
defined $v
$n =~ /^$Module::Generic::HeaderValue::TEXT_REGEXP$/
Truth table66%2/3
A || B
A= defined $vB= $n =~ /^$Module::Generic::HeaderValue::TEXT_REGEXP$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | return( $self->error( "Invalid value \"$n\"" ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 13 | ▶ | if( defined( $v ) && $self->encode ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $v and $self->encode
MC/DC100%2/2
defined $v and $self->encode
defined $v
$self->encode
Truth table100%3/3
A and B
A= defined $vB= $self->encode
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 2 | ▶ | $v = URI::Escape::uri_escape( $v ) if( $v !~ /^$TEXT_REGEXP$/ || $v =~ /=/ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $v =~ /^$Module::Generic::HeaderValue::TEXT_REGEXP$/ or $v =~ /=/
MC/DC50%1/2
not $v =~ /^$Module::Generic::HeaderValue::TEXT_REGEXP$/ or $v =~ /=/
not $v =~ /^$Module::Generic::HeaderValue::TEXT_REGEXP$/
$v =~ /=/
Truth table66%2/3
not(A) or B
A= not $v =~ /^$Module::Generic::HeaderValue::TEXT_REGEXP$/B= $v =~ /=/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 13 | ▶ | $v = qq{"${v}"} if( CORE::defined( $v ) && $v =~ /$DELIMITERS/ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $v and $v =~ /$Module::Generic::HeaderValue::DELIMITERS/
MC/DC0%0/2
defined $v and $v =~ /$Module::Generic::HeaderValue::DELIMITERS/
defined $v
$v =~ /$Module::Generic::HeaderValue::DELIMITERS/
Truth table66%2/3
A and B
A= defined $vB= $v =~ /$Module::Generic::HeaderValue::DELIMITERS/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 13 | ▶ | $string = defined( $v ) ? join( '=', $n, $v ) : $n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 13 | return( $string ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | sub value_data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
value_data: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 1 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 1 | my $ref = $self->value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | # If this is only one-element array, this means the only element is the value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | # return( $ref->first ) if( $ref->length == 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | # otherwise, the first element is the name, and this is not what the caller wants | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | # we return an empty string, not undef, because undef is associated with errors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | # return( '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 1 | ▶ | if( $ref->length == 1 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | return( $ref->first ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | # Either empty (returns undef) or 2-element: [name, value] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 1 | return( $ref->second ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 16 | ▶ | sub value_max { return( shift->_set_get_number( 'value_max', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
value_max: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | sub value_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
value_name: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 5 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 5 | my $ref = $self->value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | # If this is only one-element array, this means the only element is the value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 5 | ▶ | return( '' ) if( $ref->length == 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | # otherwise, the first element is the name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 1 | return( $ref->first ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | sub FREEZE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FREEZE: called CC=6 SCAR=18.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 2 | my $self = CORE::shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 2 | ▶ | my $serialiser = CORE::shift( @_ ) // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift @_ // ""
MC/DC0%0/1
shift @_ // ""
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 2 | my $class = CORE::ref( $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 2 | my @props = qw( original value decode encode params token_max value_max ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 2 | my $hash = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 2 | foreach my $prop ( @props ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 14 | ▶ | if( exists( $self->{ $prop } ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 14 | $hash->{ $prop } = $self->{ $prop }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | # Return an array reference rather than a list so this works with Sereal and CBOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | # On or before Sereal version 4.023, Sereal did not support multiple values returned | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 2 | ▶ | if( $serialiser eq 'Sereal' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 1 | require Sereal::Encoder; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 1 | require version; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 1 | ▶ | if( version->parse( Sereal::Encoder->VERSION ) <= version->parse( '4.023' ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | CORE::return( [$class, $hash] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | # But Storable want a list with the first element being the serialised element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 2 | CORE::return( $class, $hash ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 1 | ▶ | sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
STORABLE_freeze: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 1 | ▶ | sub STORABLE_thaw { CORE::return( CORE::shift->THAW( @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
STORABLE_thaw: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | # NOTE: CBOR will call the THAW method with the stored classname as first argument, the constant string CBOR as second argument, and all values returned by FREEZE as remaining arguments. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | # NOTE: Storable calls it with a blessed object it created followed with $cloning and any other arguments initially provided by STORABLE_freeze | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | sub THAW | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
THAW: called CC=10 SCAR=27.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 2 | my( $self, undef, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 2 | ▶ | my $ref = ( CORE::scalar( @args ) == 1 && CORE::ref( $args[0] ) eq 'ARRAY' ) ? CORE::shift( @args ) : \@args; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
scalar @args == 1 and ref $args[0] eq "ARRAY"
MC/DC0%0/2
scalar @args == 1 and ref $args[0] eq "ARRAY"
scalar @args == 1
ref $args[0] eq "ARRAY"
Truth table33%1/3
A and B
A= scalar @args == 1B= ref $args[0] eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 2 | ▶ | my $class = ( CORE::defined( $ref ) && CORE::ref( $ref ) eq 'ARRAY' && CORE::scalar( @$ref ) > 1 ) ? CORE::shift( @$ref ) : ( CORE::ref( $self ) || $self ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition22%2/9
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
defined $ref and ref $ref eq "ARRAY"
ref $self or $self
MC/DC0%0/3
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
defined $ref
ref $ref eq "ARRAY"
scalar @$ref > 1
MC/DC0%0/2
ref $self or $self
ref $self
$self
Truth table25%1/4
A and B and C
A= defined $refB= ref $ref eq "ARRAY"C= scalar @$ref > 1
Truth table0%0/3
A or B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 2 | ▶ | my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 2 | my $new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | # Storable pattern requires to modify the object it created rather than returning a new one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 2 | ▶ | if( CORE::ref( $self ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 1 | foreach( CORE::keys( %$hash ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 7 | $self->{ $_ } = CORE::delete( $hash->{ $_ } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 1 | $new = $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 1 | $new = CORE::bless( $hash => $class ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 2 | CORE::return( $new ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | # NOTE: POD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||