blib/lib/Perinci/Sub/Wrapper/Patch/HandlePHPArray.pm

filter: Statementstmt 100% 31 / 31 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 95.5% 43 / 45 CC 5 SCAR 10.4
CC
5
Cov
97%
__ANON__
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.8
↑ Summary
1 package Perinci::Sub::Wrapper::Patch::HandlePHPArray;
2  
3 2 our $DATE = '2017-07-10'; # DATE
4 2 our $VERSION = '0.04'; # VERSION
5  
6 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use parent qw(Module::Patch);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶my $code = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
14 2 my $ctx = shift;
15  
16 2 my ($self, %args) = @_;
17  
18 2 $ctx->{orig}->(@_);
19  
20 2 $self->select_section('before_call_before_arg_validation');
21  
22 2 my $args = $self->{_meta}{args};
23 2 for my $an (sort keys %$args) {
24 2 my $aspec = $args->{$an};
25 2 ▶ next unless $aspec->{schema};
Branch: 1 branch
BranchTrueFalseTotal
unless $aspec->{"schema"} 0 2 2
26 2 ▶ if ($aspec->{schema}[0] eq 'array') {
Branch: 1 branch
BranchTrueFalseTotal
if ($aspec->{"schema"}[0] eq "array") 1 1 2
27 1 $self->push_lines("if (ref(\$args{$an}) eq 'HASH' && !keys(\%{\$args{$an}})) { \$args{$an} = [] }");
28 }
29 2 ▶ if ($aspec->{schema}[0] eq 'hash') {
Branch: 1 branch
BranchTrueFalseTotal
if ($aspec->{"schema"}[0] eq "hash") 1 1 2
30 1 $self->push_lines("if (ref(\$args{$an}) eq 'ARRAY' && !\@{\$args{$an}}) { \$args{$an} = {} }");
31 }
32 }
33 2 };
34  
35 1 ▶sub patch_data {
Subroutine patch_data: called CC=1 SCAR=0.0
Pod undocumented
36 return {
37 1 v => 3,
38 patches => [
39 {
40 action => 'wrap',
41 sub_name => 'handle_args',
42 code => $code,
43 },
44 ],
45 };
46 }
47  
48 2 1;
49 # ABSTRACT: Convert {} to [] or vice versa to match functions' expectations
50  
51 __END__
↑ Summary