Any/Impl/Helper.pm

filter: Statementstmt 81.3% 48 / 59 Branchbran 37.5% 3 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 71.4% 10 / 14 Podpod 0.0% 0 / 4 totaltotal 67.7% 61 / 90 CC 8 SCAR 16.8
CC
8
Cov
73%
get_call_args
20.0
params_to_hash
4.2
generate_methods
2.0
CRAP 5.4
« Any.pm ↑ Summary Any/Impl/MojoUserAgent.pm »
1 package UserAgent::Any::Impl::Helper;
2  
3 8 ▶use 5.036;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use List::Util 'pairs';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use UserAgent::Any::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 8 Readonly our @EXPORT_OK => qw(get_call_args generate_methods new_response params_to_hash);
12 8 Readonly our %EXPORT_TAGS => ('all' => \@EXPORT_OK);
13  
14 8 Readonly our $VERSION => 0.01;
15  
16 8 Readonly our @METHODS => qw(delete get head patch post put);
17 8 Readonly our @METHODS_WITH_DATA => qw(patch post put);
18 8 Readonly our %METHODS_WITH_DATA => map { $_ => 1 } @METHODS_WITH_DATA;
19 8 Readonly our @METHODS_WITHOUT_DATA => grep { !$METHODS_WITH_DATA{$_} } @METHODS;
20  
21 0 ▶sub get_call_args { ## no critic (RequireArgUnpacking)
Subroutine get_call_args: not called CC=4 SCAR=30.0
Pod undocumented
22 0 my ($self, $method, $url) = (shift, shift, shift);
23 0 my $content;
24 0 ▶ $content = pop if @_ % 2 && $METHODS_WITH_DATA{$method};
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 and $UserAgent::Any::Impl::Helper::METHODS_WITH_DATA{$method} 0 0 0
Condition0%0/3
@_ % 2 and $UserAgent::Any::Impl::Helper::METHODS_WITH_DATA{$method}
!ll&&!rl&&r
000
MC/DC0%0/2
@_ % 2 and $UserAgent::Any::Impl::Helper::METHODS_WITH_DATA{$method}
@_ % 2 $UserAgent::Any::Impl::Helper::METHODS_WITH_DATA{$method}
Truth table0%0/3
A and B
A= @_ % 2B= $UserAgent::Any::Impl::Helper::METHODS_WITH_DATA{$method}
ABresult
0X0
100
111
25 # Here, we can’t be in the $METHODS_WITH_DATA{$method} case.
26 0 ▶ croak 'Invalid number of arguments, expected an even sized list after the url' if @_ % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 0 0
27 0 return ($self, $method, $url, \@_, \$content,);
28 }
29  
30 3 ▶sub generate_methods {
Subroutine generate_methods: called CC=2 SCAR=7.0
Pod undocumented
31 3 my $dest_pkg = caller(0);
32  
33 3 for my $m (@METHODS) {
34 8 ▶ no strict 'refs'; ## no critic (ProhibitNoStrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
35 18 ▶ *{"${dest_pkg}::${m}"} = sub ($self, @args) { $self->call($m, @args) };
Subroutine __ANON__: called CC=1 SCAR=0.0
36 0 ▶ *{"${dest_pkg}::${m}_cb"} = sub ($self, @args) { $self->call_cb($m, @args) };
Subroutine __ANON__: not called CC=1 SCAR=0.4
37 0 ▶ *{"${dest_pkg}::${m}_p"} = sub ($self, @args) { $self->call_p($m, @args) };
Subroutine __ANON__: not called CC=1 SCAR=0.4
38 }
39 3 return;
40 }
41  
42 0 ▶sub new_response {
Subroutine new_response: not called CC=1 SCAR=6.9
Pod undocumented
43 0 my ($r) = @_; # The undef is $self that we are not using.
44 0 return UserAgent::Any::Response->new($r);
45 }
46  
47 3 ▶sub params_to_hash (@params) {
Subroutine params_to_hash: called CC=4 SCAR=14.2
Pod undocumented
48 3 my %hash;
49 3 for my $kv (pairs @params) {
50 7 my $v = $hash{$kv->key};
51 7 ▶ if (defined $v) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v) { } 2 5 7
52 2 ▶ if (ref($v)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v) { } 0 2 2
53 0 push @{$v}, $kv->value;
54 } else {
55 2 $hash{$kv->key} = [$v, $kv->value];
56 }
57 } else {
58 5 $hash{$kv->key} = $kv->value;
59 }
60 }
61 3 return \%hash;
62 }
63  
64 8 1;
« Any.pm ↑ Summary Any/Impl/MojoUserAgent.pm »