| 1 | package HTTP::API::Core::Form; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | our @EXPORT_OK = qw(form_urlencode); | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 12 | ▶ | sub form_urlencode { | ||||||||||||||||||||||||||
|
Subroutine
form_urlencode: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 10 | 12 | my ($params) = @_; | |||||||||||||||||||||||||||
| 11 | 12 | ▶ | die "form parameters must be a hash reference\n" if ref($params) ne 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | return join '&', map { | ||||||||||||||||||||||||||||
| 14 | 11 | my $key = $_; | |||||||||||||||||||||||||||
| 15 | 12 | my $value = $params->{$key}; | |||||||||||||||||||||||||||
| 16 | 12 | ▶ | die "form parameter values must be scalars, array references, or undef\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $value ne "" and ref $value ne "ARRAY"
MC/DC100%2/2
ref $value ne "" and ref $value ne "ARRAY"
ref $value ne ""
ref $value ne "ARRAY"
Truth table100%3/3
A and B
A= ref $value ne ""B= ref $value ne "ARRAY"
| |||||||||||||||||||||||||||||
| 17 | if ref($value) ne '' && ref($value) ne 'ARRAY'; | ||||||||||||||||||||||||||||
| 18 | 11 | ▶ | my @values = ref($value) eq 'ARRAY' ? @$value : ($value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | die "form parameter array values must contain only scalars or undef\n" | ||||||||||||||||||||||||||||
| 20 | 11 | ▶ | if grep { defined($_) && ref($_) ne '' } @values; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $_ && ref $_ ne ''
MC/DC100%2/2
defined $_ && ref $_ ne ''
defined $_
ref $_ ne ''
Truth table100%3/3
A && B
A= defined $_B= ref $_ ne ''
| |||||||||||||||||||||||||||||
| 21 | 10 | map { _escape($key) . '=' . _escape($_) } @values; | |||||||||||||||||||||||||||
| 22 | } sort keys %$params; | ||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 26 | ▶ | sub _escape { | ||||||||||||||||||||||||||
|
Subroutine
_escape: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 26 | 26 | my ($value) = @_; | |||||||||||||||||||||||||||
| 27 | 26 | ▶ | $value = '' if !defined $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 26 | my $bytes = "$value"; | |||||||||||||||||||||||||||
| 29 | 26 | ▶ | utf8::encode($bytes) if utf8::is_utf8($bytes); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 26 | $bytes =~ s/([^A-Za-z0-9*_. -])/sprintf('%%%02X', ord($1))/ge; | |||||||||||||||||||||||||||
| 31 | 26 | $bytes =~ tr/ /+/; | |||||||||||||||||||||||||||
| 32 | 26 | return $bytes; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 3 | 1; | |||||||||||||||||||||||||||