| 1 | package WWW::Form::UrlEncoded::PP; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use base qw/Exporter/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 7 | our @EXPORT_OK = qw/parse_urlencoded parse_urlencoded_arrayref build_urlencoded build_urlencoded_utf8/; | |||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 7 | our $DECODE = qr/%([0-9a-fA-F]{2})/; | |||||||||||||||||||||||||||||||
| 10 | 7 | our %DecodeMap; | |||||||||||||||||||||||||||||||
| 11 | 7 | our %EncodeMap; | |||||||||||||||||||||||||||||||
| 12 | 7 | for my $num ( 0 .. 255 ) { | |||||||||||||||||||||||||||||||
| 13 | 1792 | my $h = sprintf "%02X", $num; | |||||||||||||||||||||||||||||||
| 14 | 1792 | my $chr = chr $num; | |||||||||||||||||||||||||||||||
| 15 | 1792 | $DecodeMap{ lc $h } = $chr; #%aa | |||||||||||||||||||||||||||||||
| 16 | 1792 | $DecodeMap{ uc $h } = $chr; #%AA | |||||||||||||||||||||||||||||||
| 17 | 1792 | $DecodeMap{ ucfirst lc $h } = $chr; #%Aa | |||||||||||||||||||||||||||||||
| 18 | 1792 | $DecodeMap{ lcfirst uc $h } = $chr; #%aA | |||||||||||||||||||||||||||||||
| 19 | 1792 | $EncodeMap{$chr} = '%'. uc $h; | |||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||
| 21 | 7 | $EncodeMap{" "} = '+'; | |||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | sub parse_urlencoded { | ||||||||||||||||||||||||||||||||
| 24 | 124 | ▶ | my @params; | ||||||||||||||||||||||||||||||
|
Subroutine
parse_urlencoded: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 25 | 124 | ▶ | return @params unless defined $_[0]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 26 | 120 | for my $pair ( split( /[&;] ?/, $_[0], -1 ) ) { | |||||||||||||||||||||||||||||||
| 27 | 228 | $pair =~ y/\+/\x20/; | |||||||||||||||||||||||||||||||
| 28 | 228 | my ($key, $val) = split /=/, $pair, 2; | |||||||||||||||||||||||||||||||
| 29 | 228 | for ($key, $val) { | |||||||||||||||||||||||||||||||
| 30 | 456 | ▶ | if ( ! defined $_ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 31 | 30 | push @params, ''; | |||||||||||||||||||||||||||||||
| 32 | 30 | next; | |||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||
| 34 | 426 | s/$DECODE/$DecodeMap{$1}/gs; | |||||||||||||||||||||||||||||||
| 35 | 426 | push @params, $_; | |||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 120 | return @params; | |||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | sub parse_urlencoded_arrayref { | ||||||||||||||||||||||||||||||||
| 43 | 82 | ▶ | [parse_urlencoded(@_)]; | ||||||||||||||||||||||||||||||
|
Subroutine
parse_urlencoded_arrayref: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 7 | our $NEED_UPGRADE = 0; | |||||||||||||||||||||||||||||||
| 47 | sub build_urlencoded { | ||||||||||||||||||||||||||||||||
| 48 | 66 | ▶ | return "" unless @_; | ||||||||||||||||||||||||||||||
|
Subroutine
build_urlencoded: called CC=25 SCAR=32.2
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 49 | 64 | my $uri = ''; | |||||||||||||||||||||||||||||||
| 50 | 64 | my $delim = '&'; | |||||||||||||||||||||||||||||||
| 51 | 64 | ▶ | if ( ref $_[0] && ref $_[0] eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
ref $_[0] and ref $_[0] eq "ARRAY"
MC/DC100%2/2
ref $_[0] and ref $_[0] eq "ARRAY"
ref $_[0]
ref $_[0] eq "ARRAY"
Truth table100%3/3
A and B
A= ref $_[0]B= ref $_[0] eq "ARRAY"
| |||||||||||||||||||||||||||||||||
| 52 | 16 | my @args = @{$_[0]}; | |||||||||||||||||||||||||||||||
| 53 | 16 | ▶ | $delim = $_[1] if defined $_[1]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 54 | 16 | ▶ | utf8::encode($delim) if $NEED_UPGRADE; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 55 | 16 | ▶ | while ( @args ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 56 | 24 | my $k = shift @args; | |||||||||||||||||||||||||||||||
| 57 | 24 | my $v = shift @args; | |||||||||||||||||||||||||||||||
| 58 | 24 | ▶ | if ( ref $v && ref $v eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $v and ref $v eq "ARRAY"
MC/DC50%1/2
ref $v and ref $v eq "ARRAY"
ref $v
ref $v eq "ARRAY"
Truth table66%2/3
A and B
A= ref $vB= ref $v eq "ARRAY"
| |||||||||||||||||||||||||||||||||
| 59 | 6 | $uri .= url_encode($k) . '='. url_encode($_) . $delim for @$v; | |||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||
| 61 | else { | ||||||||||||||||||||||||||||||||
| 62 | 18 | $uri .= url_encode($k) . '='. url_encode($v) . $delim | |||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||
| 66 | ▶ | elsif ( ref $_[0] && ref $_[0] eq 'HASH') { | |||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $_[0] and ref $_[0] eq "HASH"
MC/DC50%1/2
ref $_[0] and ref $_[0] eq "HASH"
ref $_[0]
ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= ref $_[0]B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||
| 67 | 28 | ▶ | $delim = $_[1] if defined $_[1]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 68 | 28 | ▶ | utf8::encode($delim) if $NEED_UPGRADE; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 69 | 28 | ▶ | while ( my ($k,$v) = each %{$_[0]} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 70 | 48 | ▶ | if ( ref $v && ref $v eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $v and ref $v eq "ARRAY"
MC/DC50%1/2
ref $v and ref $v eq "ARRAY"
ref $v
ref $v eq "ARRAY"
Truth table66%2/3
A and B
A= ref $vB= ref $v eq "ARRAY"
| |||||||||||||||||||||||||||||||||
| 71 | 46 | $uri .= url_encode($k) . '='. url_encode($_) . $delim for @$v; | |||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||
| 73 | else { | ||||||||||||||||||||||||||||||||
| 74 | 2 | $uri .= url_encode($k) . '='. url_encode($v) . $delim | |||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | else { | ||||||||||||||||||||||||||||||||
| 79 | 20 | ▶ | if ( @_ > 2 && @_ % 2 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ > 2 and @_ % 2
MC/DC100%2/2
@_ > 2 and @_ % 2
@_ > 2
@_ % 2
Truth table100%3/3
A and B
A= @_ > 2B= @_ % 2
| |||||||||||||||||||||||||||||||||
| 80 | 6 | $delim = pop @_; | |||||||||||||||||||||||||||||||
| 81 | 6 | ▶ | utf8::encode($delim) if $NEED_UPGRADE; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||
| 83 | 20 | ▶ | while ( @_ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 84 | 28 | my $k = shift @_; | |||||||||||||||||||||||||||||||
| 85 | 28 | my $v = shift @_; | |||||||||||||||||||||||||||||||
| 86 | 28 | ▶ | if ( ref $v && ref $v eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $v and ref $v eq "ARRAY"
MC/DC50%1/2
ref $v and ref $v eq "ARRAY"
ref $v
ref $v eq "ARRAY"
Truth table66%2/3
A and B
A= ref $vB= ref $v eq "ARRAY"
| |||||||||||||||||||||||||||||||||
| 87 | 2 | $uri .= url_encode($k) . '='. url_encode($_) . $delim for @$v; | |||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||
| 89 | else { | ||||||||||||||||||||||||||||||||
| 90 | 26 | $uri .= url_encode($k) . '='. url_encode($v) . $delim | |||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||
| 94 | 64 | substr($uri,-1*length($delim),length($delim),""); | |||||||||||||||||||||||||||||||
| 95 | 64 | $uri; | |||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | sub build_urlencoded_utf8 { | ||||||||||||||||||||||||||||||||
| 99 | 16 | ▶ | local $NEED_UPGRADE = 1; | ||||||||||||||||||||||||||||||
|
Subroutine
build_urlencoded_utf8: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 100 | 16 | my $uri = build_urlencoded(@_); | |||||||||||||||||||||||||||||||
| 101 | 16 | $uri; | |||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | sub url_encode { | ||||||||||||||||||||||||||||||||
| 105 | 388 | ▶ | return '' unless defined $_[0]; | ||||||||||||||||||||||||||||||
|
Subroutine
url_encode: called CC=4 SCAR=13.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 106 | 358 | my $t = shift; | |||||||||||||||||||||||||||||||
| 107 | 358 | ▶ | utf8::encode($t) if $NEED_UPGRADE; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 108 | { | ||||||||||||||||||||||||||||||||
| 109 | 7 | ▶ | use bytes; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 110 | 358 | $t =~ s!([^A-Za-z0-9\-\._~])! | |||||||||||||||||||||||||||||||
| 111 | 48 | ▶ | join '',@EncodeMap{exists $EncodeMap{$1} ? ($1) : (split //,$1)} | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 112 | !gsxe; | ||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||
| 114 | 358 | return $t; | |||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | 7 | 1; | |||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | __END__ | ||||||||||||||||||||||||||||||||