Catmandu/Fix/lookup.pm

filter: Statementstmt 100% 49 / 49 Branchbran 100% 6 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 97.1% 69 / 71 CC 5 SCAR 8.5
CC
5
Cov
98%
__ANON__
5.0
_build_fixer
1.0
BEGIN
1.0
CRAP 2.3
« Catmandu/Fix/eval.pm ↑ Summary Catmandu/Fix/Condition.pm »
1 package Catmandu::Fix::lookup;
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::Importer::CSV;
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 file => (fix_arg => 1);
18 1 has default => (fix_opt => 1, predicate => 1);
19 1 has delete => (fix_opt => 1);
20 1 has csv_args => (fix_opt => 'collect');
21 1 has dictionary => (is => 'lazy', init_arg => undef);
22  
23 7 ▶sub _build_dictionary {
Subroutine _build_dictionary: called CC=1 SCAR=0.0
24 7 my ($self) = @_;
25 Catmandu::Importer::CSV->new(
26 7 %{$self->csv_args},
27 file => $self->file,
28 header => 0,
29 fields => ['key', 'val'],
30 )->reduce(
31 {},
32 36 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
33 36 my ($dict, $pair) = @_;
34 36 $dict->{$pair->{key}} = $pair->{val};
35 36 $dict;
36 }
37 7 );
38 }
39  
40 7 ▶sub _build_fixer {
Subroutine _build_fixer: called CC=1 SCAR=0.0
41 7 my ($self) = @_;
42 7 my $path = as_path($self->path);
43 7 my $dict = $self->dictionary;
44 7 my $has_default = $self->has_default;
45 7 my $default = $self->default;
46 7 my $delete = $self->delete;
47 $path->updater(
48 9 ▶ sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
49 9 my $val = $_[0];
50 9 ▶ if (is_value($val) && defined(my $new_val = $dict->{$val})) {
Branch: 3 branches
BranchTrueFalseTotal
if (is_value($val) and defined(my $new_val = $dict->{$val})) { } 4 5 9
elsif ($delete) { } 2 3 5
elsif ($has_default) { } 2 1 3
Condition66%2/3
is_value($val) and defined(my $new_val = $dict->{$val})
!ll&&!rl&&r
054
MC/DC50%1/2
is_value($val) and defined(my $new_val = $dict->{$val})
is_value($val) defined(my $new_val = $dict->{$val})
Truth table66%2/3
A and B
A= is_value($val)B= defined(my $new_val = $dict->{$val})
ABresult
0X0
100
111
51 4 return $new_val;
52 }
53 elsif ($delete) {
54 2 return undef, 1, 1;
55 }
56 elsif ($has_default) {
57 2 return $default;
58 }
59 1 return undef, 1, 0;
60 }
61 7 );
62 }
63  
64 1 1;
65  
66 __END__
« Catmandu/Fix/eval.pm ↑ Summary Catmandu/Fix/Condition.pm »