| 1 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 2 | # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de> | ||||||||||||||||||||||||||||
| 3 | # File: GX/HTTP/Parameters.pm | ||||||||||||||||||||||||||||
| 4 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | package GX::HTTP::Parameters; | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 38 | ▶ | use GX::Exception; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 38 | ▶ | use GX::HTTP::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 38 | ▶ | use Encode (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 38 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 16 | # Class setup | ||||||||||||||||||||||||||||
| 17 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 38 | ▶ | use GX::Class::Object; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 38 | has 'data' => ( | |||||||||||||||||||||||||||
| 22 | isa => 'Hash::Ordered', | ||||||||||||||||||||||||||||
| 23 | accessors => { | ||||||||||||||||||||||||||||
| 24 | '_get_data' => { type => 'get_reference' } | ||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 38 | has 'encoding' => ( | |||||||||||||||||||||||||||
| 29 | isa => 'Scalar' | ||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 38 | build; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 36 | # Overloading | ||||||||||||||||||||||||||||
| 37 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | use overload | ||||||||||||||||||||||||||||
| 40 | 668 | ▶ | 'bool' => sub { 1 }, | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | '0+' => sub { $_[0] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | '""' => sub { $_[0]->as_string }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 43 | 38 | 'fallback' => 1; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 47 | # Public methods | ||||||||||||||||||||||||||||
| 48 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1070 | ▶ | sub add { | ||||||||||||||||||||||||||
|
Subroutine
add: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 1070 | my $self = shift; | |||||||||||||||||||||||||||
| 53 | 1070 | my $key = shift; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 1070 | ▶ | if ( ! defined $key || ! length $key ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $key and length $key
MC/DC0%0/2
defined $key and length $key
defined $key
length $key
Truth table33%1/3
A and B
A= defined $keyB= length $key
| |||||||||||||||||||||||||||||
| 56 | 0 | complain "Invalid parameter name"; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1070 | ▶ | push @{$self->_get_data->{$key}}, map { defined $_ ? "$_" : undef } @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 1070 | return; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 4 | ▶ | sub as_string { | ||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 4 | my $data = $self->_get_data; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 4 | my @pairs; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 4 | ▶ | if ( defined( my $encoding = $self->encoding ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 1 | my $encoder = Encode::find_encoding( $encoding ); | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 1 | ▶ | if ( ! $encoder ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 0 | complain "Cannot encode parameters (unsupported encoding)"; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 1 | eval { | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 1 | ▶ | while ( my ( $key, $values ) = each %$data ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 4 | my $encoded_key = GX::HTTP::Util::url_encode( $encoder->encode( $key, Encode::FB_CROAK ) ); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 4 | for ( @$values ) { | |||||||||||||||||||||||||||
| 88 | 7 | ▶ | push @pairs, $encoded_key . '=' . ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | defined $_ | ||||||||||||||||||||||||||||
| 90 | ? GX::HTTP::Util::url_encode( $encoder->encode( $_, Encode::FB_CROAK ) ) | ||||||||||||||||||||||||||||
| 91 | : '' | ||||||||||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | }; | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | else { | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 3 | eval { | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 3 | ▶ | while ( my ( $key, $values ) = each %$data ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 6 | my $encoded_key = GX::HTTP::Util::url_encode( $key ); | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 5 | for ( @$values ) { | |||||||||||||||||||||||||||
| 109 | 8 | ▶ | push @pairs, $encoded_key . '=' . ( defined $_ ? GX::HTTP::Util::url_encode( $_ ) : '' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | }; | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 4 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 1 | GX::Exception->complain( | |||||||||||||||||||||||||||
| 120 | message => "Cannot encode parameters", | ||||||||||||||||||||||||||||
| 121 | subexception => $@ | ||||||||||||||||||||||||||||
| 122 | ); | ||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 3 | return join( '&', @pairs ); | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 4 | ▶ | sub count { | ||||||||||||||||||||||||||
|
Subroutine
count: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 4 | return scalar keys %{$_[0]->_get_data}; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 4 | ▶ | sub decode { | ||||||||||||||||||||||||||
|
Subroutine
decode: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 138 | 4 | my $encoding = shift; | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 4 | ▶ | $encoding //= $self->encoding // 'utf8'; | ||||||||||||||||||||||||||
|
Condition100%4/4
$encoding //= $self->encoding // "utf8"
$self->encoding // "utf8"
MC/DC100%1/1
$encoding //= $self->encoding // "utf8"
$encoding
Truth table100%2/2
A
A= $encoding
| |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 4 | my $decoder = Encode::find_encoding( $encoding ); | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 4 | ▶ | if ( ! $decoder ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 0 | complain "Cannot decode parameters (unsupported encoding)"; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 4 | my $data = $self->_get_data; | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 4 | my @data; | |||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 4 | eval { | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 4 | ▶ | while ( my ( $key, $values ) = each %$data ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | push @data, [ | ||||||||||||||||||||||||||||
| 157 | $decoder->decode( $key, Encode::FB_CROAK ), | ||||||||||||||||||||||||||||
| 158 | 13 | ▶ | [ map { defined $_ ? $decoder->decode( $_, Encode::FB_CROAK ) : undef } @$values ] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | ]; | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | }; | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 4 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 1 | GX::Exception->complain( | |||||||||||||||||||||||||||
| 167 | message => "Cannot decode parameters", | ||||||||||||||||||||||||||||
| 168 | subexception => $@ | ||||||||||||||||||||||||||||
| 169 | ); | ||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 3 | %$data = map { $_->[0] => $_->[1] } @data; | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 3 | return; | |||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 5 | ▶ | sub exists { | ||||||||||||||||||||||||||
|
Subroutine
exists: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 181 | 5 | my $key = shift; | |||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 5 | ▶ | return defined $key && exists $self->_get_data->{$key}; | ||||||||||||||||||||||||||
|
Condition66%2/3
defined $key && exists $self->_get_data->{$key}
MC/DC50%1/2
defined $key && exists $self->_get_data->{$key}
defined $key
exists $self->_get_data->{$key}
Truth table66%2/3
A && B
A= defined $keyB= exists $self->_get_data->{$key}
| |||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 840 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 840 | my $self = shift; | |||||||||||||||||||||||||||
| 190 | 840 | my $key = shift; | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 840 | ▶ | defined $key or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 840 | ▶ | my $values = $self->_get_data->{$key} or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 815 | ▶ | return wantarray ? @$values : $values->[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 403 | ▶ | sub keys { | ||||||||||||||||||||||||||
|
Subroutine
keys: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 403 | return keys %{$_[0]->_get_data}; | |||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 9 | ▶ | sub merge { | ||||||||||||||||||||||||||
|
Subroutine
merge: called CC=6 SCAR=18.6
Pod
documented
| |||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 9 | my $invocant = shift; | |||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 9 | ▶ | my $self = ref $invocant ? $invocant : $invocant->new; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | 9 | my $class = ref $self; | |||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 9 | my $data = $self->_get_data; | |||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 9 | for my $container ( @_ ) { | |||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 29 | ▶ | if ( ! blessed $container || ! $container->isa( $class ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($container) and $container->isa($class)
MC/DC0%0/2
builtin::blessed($container) and $container->isa($class)
builtin::blessed($container)
$container->isa($class)
Truth table33%1/3
A and B
A= builtin::blessed($container)B= $container->isa($class)
| |||||||||||||||||||||||||||||
| 218 | 0 | complain "Invalid argument (arguments must be $class objects)"; | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 29 | for my $key ( $container->keys ) { | |||||||||||||||||||||||||||
| 222 | 39 | push @{$data->{$key}}, $container->get( $key ); | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 9 | return $self; | |||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 18 | ▶ | sub parse { | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=13 SCAR=26.0
Pod
documented
| |||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 18 | ▶ | my $self = ref $_[0] ? shift : shift->new; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | 18 | my $string = shift; | |||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 18 | ▶ | return $self unless defined $string && length $string; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $string and length $string
MC/DC100%2/2
defined $string and length $string
defined $string
length $string
Truth table100%3/3
A and B
A= defined $stringB= length $string
| |||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 13 | ▶ | if ( utf8::is_utf8( $string ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | 0 | complain "Invalid argument (argument must be a byte string)"; | |||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 13 | my @pairs; | |||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 13 | for my $pair ( split( /&/, $string ) ) { | |||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 75 | my ( $key, $value ) = split( /=/, $pair, 2 ); | |||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | 75 | ▶ | length $key or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 75 | $key =~ tr/+/ /; | |||||||||||||||||||||||||||
| 251 | 75 | $key =~ s/%([0-9a-fA-F]{2})/chr( hex( $1 ) )/eg; | |||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 75 | ▶ | if ( defined $value ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | 63 | $value =~ tr/+/ /; | |||||||||||||||||||||||||||
| 255 | 63 | $value =~ s/%([0-9a-fA-F]{2})/chr( hex( $1 ) )/eg; | |||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | else { | ||||||||||||||||||||||||||||
| 258 | 12 | $value = ''; | |||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 75 | push @pairs, [ $key, $value ]; | |||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | 13 | ▶ | if ( defined( my $encoding = $self->encoding ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 1 | my $decoder = Encode::find_encoding( $encoding ); | |||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | 1 | ▶ | if ( ! $decoder ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 270 | 0 | complain "Cannot decode parameters (unsupported encoding)"; | |||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 1 | eval { | |||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | 1 | for ( @pairs ) { | |||||||||||||||||||||||||||
| 276 | 7 | $_->[0] = $decoder->decode( $_->[0], Encode::FB_CROAK ); | |||||||||||||||||||||||||||
| 277 | 7 | $_->[1] = $decoder->decode( $_->[1], Encode::FB_CROAK ); | |||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | }; | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 1 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 283 | 0 | GX::Exception->complain( | |||||||||||||||||||||||||||
| 284 | message => "Cannot decode parameters", | ||||||||||||||||||||||||||||
| 285 | subexception => $@ | ||||||||||||||||||||||||||||
| 286 | ); | ||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 13 | my $data = $self->_get_data; | |||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | 13 | for ( @pairs ) { | |||||||||||||||||||||||||||
| 294 | 75 | push @{$data->{$_->[0]}}, $_->[1]; | |||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | 13 | return $self; | |||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | 3 | ▶ | sub remove { | ||||||||||||||||||||||||||
|
Subroutine
remove: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 304 | 3 | my $key = shift; | |||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | 3 | ▶ | defined $key or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | 3 | ▶ | return delete $self->_get_data->{$key} ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | 5 | ▶ | sub set { | ||||||||||||||||||||||||||
|
Subroutine
set: called CC=5 SCAR=16.6
Pod
documented
| |||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 315 | 5 | my $key = shift; | |||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | 5 | ▶ | if ( ! defined $key || ! length $key ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $key and length $key
MC/DC0%0/2
defined $key and length $key
defined $key
length $key
Truth table33%1/3
A and B
A= defined $keyB= length $key
| |||||||||||||||||||||||||||||
| 318 | 0 | complain "Invalid parameter name"; | |||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | 5 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 322 | 4 | ▶ | $self->_get_data->{$key} = [ map { defined $_ ? "$_" : undef } @_ ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||
| 324 | else { | ||||||||||||||||||||||||||||
| 325 | 1 | delete $self->_get_data->{$key}; | |||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | 5 | return; | |||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | 38 | 1; | |||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | __END__ | ||||||||||||||||||||||||||||