Catmandu/Fix/lookup_in_store.pm

filter: Statementstmt 100% 58 / 58 Branchbran 91.6% 11 / 12 Conditioncond 66.6% 6 / 9 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 13 / 13 Podpod n/a totaltotal 92.8% 91 / 98 CC 10 SCAR 7.9
CC
10
Cov
95%
__ANON__
3.0
__ANON__
3.0
__ANON__
3.0
CRAP 2.2
« Catmandu/Store/Multi.pm ↑ Summary Catmandu/Fix/retain.pm »
1 package Catmandu::Fix::lookup_in_store;
2  
3 1 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '1.2025';
6  
7 1 ▶use Catmandu;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Catmandu::Util::Path qw(as_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Catmandu::Util qw(is_value);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Catmandu::Fix::Has;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 with 'Catmandu::Fix::Builder';
15  
16 1 has path => (fix_arg => 1);
17 1 has store_name => (fix_arg => 1);
18 1 has bag_name => (fix_opt => 1, init_arg => 'bag');
19 1 has default => (fix_opt => 1, predicate => 1);
20 1 has delete => (fix_opt => 1);
21 1 has store_args => (fix_opt => 'collect');
22 1 has store => (is => 'lazy', init_arg => undef);
23 1 has bag => (is => 'lazy', init_arg => undef);
24  
25 6 ▶sub _build_store {
Subroutine _build_store: called CC=1 SCAR=0.0
26 6 my ($self) = @_;
27 6 Catmandu->store($self->store_name, %{$self->store_args});
28 }
29  
30 6 ▶sub _build_bag {
Subroutine _build_bag: called CC=2 SCAR=7.2
31 6 my ($self) = @_;
32 6 ▶ defined $self->bag_name
Branch: 1 branch
BranchTrueFalseTotal
defined $self->bag_name ? : 0 6 6
33 ? $self->store->bag($self->bag_name)
34 : $self->store->bag;
35 }
36  
37 6 ▶sub _build_fixer {
Subroutine _build_fixer: called CC=3 SCAR=11.0
38 6 my ($self) = @_;
39  
40 6 my $bag = $self->bag;
41 6 my $cb;
42  
43 6 ▶ if ($self->delete) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->delete) { } 2 4 6
elsif ($self->has_default) { } 2 2 4
44 3 ▶ $cb = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
45 3 my $val = $_[0];
46 3 ▶ if (is_value($val) && defined($val = $bag->get($val))) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_value($val) and defined($val = $bag->get($val))) 1 2 3
Condition66%2/3
is_value($val) and defined($val = $bag->get($val))
!ll&&!rl&&r
021
MC/DC50%1/2
is_value($val) and defined($val = $bag->get($val))
is_value($val) defined($val = $bag->get($val))
Truth table66%2/3
A and B
A= is_value($val)B= defined($val = $bag->get($val))
ABresult
0X0
100
111
47 1 return $val;
48 }
49 2 return undef, 1, 1;
50 2 };
51 }
52 elsif ($self->has_default) {
53 2 my $default = $self->default;
54 3 ▶ $cb = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
55 3 my $val = $_[0];
56 3 ▶ if (is_value($val) && defined($val = $bag->get($val))) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_value($val) and defined($val = $bag->get($val))) 1 2 3
Condition66%2/3
is_value($val) and defined($val = $bag->get($val))
!ll&&!rl&&r
021
MC/DC50%1/2
is_value($val) and defined($val = $bag->get($val))
is_value($val) defined($val = $bag->get($val))
Truth table66%2/3
A and B
A= is_value($val)B= defined($val = $bag->get($val))
ABresult
0X0
100
111
57 1 return $val;
58 }
59 2 $default;
60 2 };
61 }
62 else {
63 2 ▶ $cb = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
64 2 my $val = $_[0];
65 2 ▶ if (is_value($val) && defined($val = $bag->get($val))) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_value($val) and defined($val = $bag->get($val))) 1 1 2
Condition66%2/3
is_value($val) and defined($val = $bag->get($val))
!ll&&!rl&&r
011
MC/DC50%1/2
is_value($val) and defined($val = $bag->get($val))
is_value($val) defined($val = $bag->get($val))
Truth table66%2/3
A and B
A= is_value($val)B= defined($val = $bag->get($val))
ABresult
0X0
100
111
66 1 return $val;
67 }
68 1 return undef, 1, 0;
69 2 };
70 }
71  
72 6 as_path($self->path)->updater($cb);
73 }
74  
75 1 1;
76  
77 __END__
« Catmandu/Store/Multi.pm ↑ Summary Catmandu/Fix/retain.pm »