Utils/URI.pm

filter: Statementstmt 100% 40 / 40 Branchbran 66.6% 8 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 87.6% 57 / 65 CC 10 SCAR 19.2
CC
10
Cov
91%
to_uri
10.3
BEGIN
1.0
BEGIN
1.0
CRAP 6.8
« Client/Request.pm ↑ Summary Client/Request/Role/HasData.pm »
1 # ABSTRACT: URI utils
2 package PONAPI::Utils::URI;
3  
4 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use URI::QueryParam;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use URI::Escape qw( uri_escape_utf8 );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 7 ▶use parent qw< Exporter >;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 our @EXPORT_OK = qw< to_uri >;
13  
14 sub to_uri {
15 4 ▶ my ( $data ) = @_;
Subroutine to_uri: called CC=10 SCAR=23.3
Pod undocumented
16 4 ▶ die "[__PACKAGE__] to_uri: input must be a hash"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "HASH" 0 4 4
17 unless ref $data eq 'HASH';
18  
19 4 my $u = URI->new("", "http");
20  
21 4 for my $d_k ( sort keys %{ $data } ) {
22 10 my $d_v = $data->{$d_k};
23 10 ▶ defined($d_v) or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $d_v or next 0 10 10
24  
25 10 ▶ if ( ref $d_v ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $d_v ne "HASH") 3 7 10
26 $u->query_param( $d_k =>
27 3 ▶ join ',' => map { uri_escape_utf8($_) } ( ref $d_v eq 'ARRAY' ? @{$d_v} : $d_v ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $d_v eq 'ARRAY' ? : 3 0 3
28 3 next;
29 }
30  
31 # HASH
32 7 for my $k ( sort keys %{$d_v} ) {
33 7 my $v = $d_v->{$k};
34  
35 7 ▶ die "[__PACKAGE__] to_uri: nested value can be scalar/arrayref only"
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $v or ref $v eq "ARRAY" 0 7 7
Condition66%2/3
not ref $v or ref $v eq "ARRAY"
l!l&&r!l&&!r
250
MC/DC0%0/2
not ref $v or ref $v eq "ARRAY"
not ref $v ref $v eq "ARRAY"
Truth table66%2/3
not(A) or B
A= not ref $vB= ref $v eq "ARRAY"
ABresult
1X1
011
000
36 unless !ref $v or ref $v eq 'ARRAY';
37  
38 $u->query_param( $d_k . '[' . $k . ']' =>
39 7 ▶ join ',' => map { uri_escape_utf8($_) } ( ref $v eq 'ARRAY' ? @{$v} : $v ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 5 2 7
40 }
41 }
42  
43 4 return $u->query;
44 }
45  
46 7 1;
47  
48 __END__
49  
50 =pod
51  
52 =encoding UTF-8
53  
54 =head1 NAME
55  
56 PONAPI::Utils::URI - URI utils
57  
58 =head1 VERSION
59  
60 version 0.002003
61  
62 =head1 AUTHORS
63  
64 =over 4
65  
66 =item *
67  
68 Mickey Nasriachi <mickey@cpan.org>
69  
70 =item *
71  
72 Stevan Little <stevan@cpan.org>
73  
74 =item *
75  
76 Brian Fraser <hugmeir@cpan.org>
77  
78 =back
79  
80 =head1 COPYRIGHT AND LICENSE
81  
82 This software is copyright (c) 2016 by Mickey Nasriachi, Stevan Little, Brian Fraser.
83  
84 This is free software; you can redistribute it and/or modify it under
85 the same terms as the Perl 5 programming language system itself.
86  
87 =cut
« Client/Request.pm ↑ Summary Client/Request/Role/HasData.pm »