Catmandu/Fix/Has.pm

filter: Statementstmt 100% 54 / 54 Branchbran 95.4% 21 / 22 Conditioncond 69.2% 9 / 13 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 89.3% 92 / 103 CC 19 SCAR 21.4
CC
19
Cov
94%
__ANON__
10.1
__ANON__
10.0
import
1.0
CRAP 8.5
« Catmandu/Path/simple.pm ↑ Summary Catmandu/Fix/sort_field.pm »
1 package Catmandu::Fix::Has;
2  
3 107 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 107 our $VERSION = '1.2025';
6  
7 107 ▶use Class::Method::Modifiers qw(install_modifier);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 175 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
10 175 my $target = caller;
11  
12 107 ▶ my $around = do {no strict 'refs'; \&{"${target}::around"}};
Subroutine BEGIN: called CC=1 SCAR=0.0
13 175 my $fix_args = [];
14 175 my $fix_opts = [];
15  
16 install_modifier(
17 $target, 'around', 'has',
18 343 ▶ sub {
Subroutine __ANON__: called CC=10 SCAR=23.1
19 343 my ($orig, $attr, %opts) = @_;
20  
21 return $orig->($attr, %opts)
22 343 ▶ unless exists $opts{fix_arg} || exists $opts{fix_opt};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts{"fix_arg"} or exists $opts{"fix_opt"} 20 323 343
Condition100%3/3
exists $opts{"fix_arg"} or exists $opts{"fix_opt"}
l!l&&r!l&&!r
2685520
MC/DC100%2/2
exists $opts{"fix_arg"} or exists $opts{"fix_opt"}
exists $opts{"fix_arg"} exists $opts{"fix_opt"}
Truth table100%3/3
A or B
A= exists $opts{"fix_arg"}B= exists $opts{"fix_opt"}
ABresult
1X1
011
000
23  
24 323 ▶ $opts{is} //= 'ro';
Condition50%1/2
$opts{"is"} //= "ro"
l!l
0323
MC/DC0%0/1
$opts{"is"} //= "ro"
$opts{"is"}
Truth table50%1/2
A
A= $opts{"is"}
Aresult
11
00
25 323 ▶ $opts{init_arg} //= $attr;
Condition66%2/3
$opts{"init_arg"} //= $attr
l!l&&r!l&&!r
43190
MC/DC0%0/2
$opts{"init_arg"} //= $attr
$opts{"init_arg"} $attr
Truth table66%2/3
A //= B
A= $opts{"init_arg"}B= $attr
ABresult
1X1
011
000
26  
27 323 my $arg = {key => $opts{init_arg}};
28  
29 323 ▶ if ($opts{fix_arg}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"fix_arg"}) 268 55 323
30 268 ▶ $opts{required} //= 1;
Condition50%1/2
$opts{"required"} //= 1
l!l
0268
MC/DC0%0/1
$opts{"required"} //= 1
$opts{"required"}
Truth table50%1/2
A
A= $opts{"required"}
Aresult
11
00
31 268 ▶ $arg->{collect} = 1 if $opts{fix_arg} eq 'collect';
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"fix_arg"} eq "collect" 5 263 268
32 268 push @$fix_args, $arg;
33 268 delete $opts{fix_arg};
34 }
35  
36 323 ▶ if ($opts{fix_opt}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"fix_opt"}) 55 268 323
37 55 ▶ $arg->{collect} = 1 if $opts{fix_opt} eq 'collect';
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"fix_opt"} eq "collect" 14 41 55
38 55 push @$fix_opts, $arg;
39 55 delete $opts{fix_opt};
40 }
41  
42 323 $orig->($attr, %opts);
43 }
44 175 );
45  
46 $around->(
47 'BUILDARGS',
48 678 ▶ sub {
Subroutine __ANON__: called CC=10 SCAR=23.0
49 678 my $orig = shift;
50 678 my $self = shift;
51  
52 678 ▶ return $orig->($self, @_) unless @$fix_args || @$fix_opts;
Branch: 1 branch
BranchTrueFalseTotal
unless @$fix_args or @$fix_opts 0 678 678
Condition66%2/3
@$fix_args or @$fix_opts
l!l&&r!l&&!r
622560
MC/DC0%0/2
@$fix_args or @$fix_opts
@$fix_args @$fix_opts
Truth table66%2/3
A or B
A= @$fix_argsB= @$fix_opts
ABresult
1X1
011
000
53  
54 678 my $args = {};
55  
56 678 for my $arg (@$fix_args) {
57 987 ▶ last unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 15 972 987
58 972 my $key = $arg->{key};
59 972 ▶ if ($arg->{collect}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->{"collect"}) 13 959 972
60 13 $args->{$key} = [splice @_, 0, @_];
61 13 last;
62 }
63 959 $args->{$key} = shift;
64 }
65  
66 678 my $orig_args = $self->$orig(@_);
67  
68 678 for my $arg (@$fix_opts) {
69 319 my $key = $arg->{key};
70 319 ▶ if ($arg->{collect}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($arg->{'collect'}) { } 59 260 319
elsif (exists $$orig_args{"-$key"}) { } 1 259 260
elsif (exists $orig_args->{$key}) { } 77 182 259
71 59 $args->{$key} = $orig_args;
72 59 last;
73 }
74 elsif (exists $orig_args->{"-$key"}) {
75 1 $args->{$key} = delete $orig_args->{"-$key"};
76 }
77 elsif (exists $orig_args->{$key}) {
78 77 $args->{$key} = delete $orig_args->{$key};
79 }
80 }
81  
82 678 $args;
83 }
84 175 );
85 }
86  
87 107 1;
88  
89 __END__
« Catmandu/Path/simple.pm ↑ Summary Catmandu/Fix/sort_field.pm »