| 1 | package Catmandu::Fix::pica_map; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | our $VERSION = '1.18'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use Catmandu::Sane; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Catmandu::Util::Path qw(as_path); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use Catmandu::Fix::Has; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use PICA::Data qw(pica_match); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | with 'Catmandu::Fix::Builder'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | has pica_path => ( fix_arg => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | has path => ( fix_arg => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 6 | has split => ( fix_opt => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 6 | has join => ( fix_opt => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 6 | has value => ( fix_opt => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 6 | has pluck => ( fix_opt => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 6 | has nested_arrays => ( fix_opt => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 50 | ▶ | sub _build_fixer { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_fixer: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 50 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 50 | my $path = as_path( $self->path ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 50 | my $key = $path->split_path->[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 50 | my $creator = $path->creator; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 50 | ▶ | my %opt = ( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%8/8
$self->join // ""
$self->split // 0
$self->pluck // 0
$self->nested_arrays // 0
MC/DC100%1/1
$self->join // ""
$self->join
MC/DC100%1/1
$self->split // 0
$self->split
MC/DC100%1/1
$self->pluck // 0
$self->pluck
MC/DC100%1/1
$self->nested_arrays // 0
$self->nested_arrays
Truth table100%2/2
A
A= $self->join
Truth table100%2/2
A
A= $self->split
Truth table100%2/2
A
A= $self->pluck
Truth table100%2/2
A
A= $self->nested_arrays
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 'join' => $self->join // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 'split' => $self->split // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 'pluck' => $self->pluck // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 'nested_arrays' => $self->nested_arrays // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 'value' => $self->value, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 'force_array' => ( $key =~ /^(\$.*|[0-9]+)$/ ) ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 50 | my $pica_path = $self->pica_path; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 50 | ▶ | $pica_path = "..../*$pica_path" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | if $pica_path =~ /^\$/; # TODO: migrate into PICA::Data | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 155 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 155 | my $data = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 155 | my $matches = pica_match( $data, $pica_path, %opt ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 155 | ▶ | if ( defined $matches ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | $matches = [$matches] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 70 | ▶ | if !ref($matches) || ( $opt{split} && !$opt{force_array} ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not ref $matches or $opt{"split"} and not $opt{"force_array"}
$opt{"split"} and not $opt{"force_array"}
MC/DC100%3/3
not ref $matches or $opt{"split"} and not $opt{"force_array"}
not ref $matches
$opt{"split"}
not $opt{"force_array"}
Truth table100%4/4
not(A) or B and not(C)
A= not ref $matchesB= $opt{"split"}C= not $opt{"force_array"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 70 | ▶ | while (@$matches) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 71 | $data = $creator->( $data, shift @$matches ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 155 | return $data; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 50 | } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||