blib/lib/HTTP/API/Core/Form.pm

filter: Statementstmt 100% 30 / 30 Branchbran 100% 12 / 12 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 98.2% 57 / 58 CC 9 SCAR 15.5
CC
9
Cov
100%
form_urlencode
7.0
_escape
3.0
BEGIN
1.0
CRAP 4.7
« blib/lib/HTTP/API/Core/Auth.pm ↑ Summary examples/HTTP/API/Core/Example/Slack.pm »
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
BranchTrueFalseTotal
if ref $params ne "HASH" 1 11 12
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
BranchTrueFalseTotal
if ref $value ne "" and ref $value ne "ARRAY" 1 11 12
Condition100%3/3
ref $value ne "" and ref $value ne "ARRAY"
!ll&&!rl&&r
831
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"
ABresult
0X0
100
111
17 if ref($value) ne '' && ref($value) ne 'ARRAY';
18 11 ▶ my @values = ref($value) eq 'ARRAY' ? @$value : ($value);
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 3 8 11
19 die "form parameter array values must contain only scalars or undef\n"
20 11 ▶ if grep { defined($_) && ref($_) ne '' } @values;
Branch: 1 branch
BranchTrueFalseTotal
if grep {defined $_ and ref $_ ne "";} @values 1 10 11
Condition100%3/3
defined $_ && ref $_ ne ''
!ll&&!rl&&r
2121
MC/DC100%2/2
defined $_ && ref $_ ne ''
defined $_ ref $_ ne ''
Truth table100%3/3
A && B
A= defined $_B= ref $_ ne ''
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless defined $value 2 24 26
28 26 my $bytes = "$value";
29 26 ▶ utf8::encode($bytes) if utf8::is_utf8($bytes);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($bytes) 2 24 26
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;
« blib/lib/HTTP/API/Core/Auth.pm ↑ Summary examples/HTTP/API/Core/Example/Slack.pm »