| 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
Condition66%2/3
is_value($val) and defined(my $new_val = $dict->{$val})
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})
| |||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||