| 1 | package Catmandu::Fix::pica_add; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Catmandu::Sane; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | 2 | our $VERSION = '1.18'; | |||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Catmandu::Util::Path qw(as_path); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Catmandu::Fix::Has; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use PICA::Path; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 2 | has path => ( fix_arg => 1 ); | |||||||||||||||||||||||||||||||
| 13 | has pica_path => ( | ||||||||||||||||||||||||||||||||
| 14 | fix_arg => 1, | ||||||||||||||||||||||||||||||||
| 15 | 8 | ▶ | coerce => sub { PICA::Path->new( $_[0] ) } | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 2 | ); | |||||||||||||||||||||||||||||||
| 17 | 2 | has record => ( fix_opt => 1 ); | |||||||||||||||||||||||||||||||
| 18 | 2 | has force_new => ( fix_opt => 1 ); | |||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 2 | with 'Catmandu::Fix::Builder'; | |||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 8 | ▶ | sub _build_fixer { | ||||||||||||||||||||||||||||||
|
Subroutine
_build_fixer: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||
| 23 | 8 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 8 | my $value_getter = as_path( $self->path )->getter; | |||||||||||||||||||||||||||||||
| 26 | 8 | ▶ | my $record_path = as_path( $self->record // 'record' ); | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->record // "record"
MC/DC0%0/1
$self->record // "record"
$self->record
Truth table50%1/2
A
A= $self->record
| |||||||||||||||||||||||||||||||||
| 27 | 8 | my $record_getter = $record_path->getter; | |||||||||||||||||||||||||||||||
| 28 | 8 | my $pica_path = $self->pica_path; | |||||||||||||||||||||||||||||||
| 29 | 8 | my $force_new = $self->force_new; | |||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | return sub { } | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 32 | 8 | ▶ | unless defined $pica_path->fields && defined $pica_path->subfields; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $pica_path->fields and defined $pica_path->subfields
MC/DC0%0/2
defined $pica_path->fields and defined $pica_path->subfields
defined $pica_path->fields
defined $pica_path->subfields
Truth table33%1/3
A and B
A= defined $pica_path->fieldsB= defined $pica_path->subfields
| |||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | 8 | my @fixed_field; | |||||||||||||||||||||||||||||||
| 35 | 8 | ▶ | @fixed_field = ( $pica_path->fields, $pica_path->occurrences ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
$pica_path->fields =~ qr/^[0-9A-Z\@]{4}$/ and ($pica_path->occurrences // "") =~ qr/^[0-9]*$/
$pica_path->occurrences // ""
MC/DC50%1/2
$pica_path->fields =~ qr/^[0-9A-Z\@]{4}$/ and ($pica_path->occurrences // "") =~ qr/^[0-9]*$/
$pica_path->fields =~ qr/^[0-9A-Z\@]{4}$/
$pica_path->occurrences
Truth table66%2/3
A and B
A= $pica_path->fields =~ qr/^[0-9A-Z\@]{4}$/B= $pica_path->occurrences
| |||||||||||||||||||||||||||||||||
| 36 | if ( $pica_path->fields =~ qr{^[0-9A-Z@]{4}$} | ||||||||||||||||||||||||||||||||
| 37 | && ( $pica_path->occurrences // '' ) =~ qr{^[0-9]*$} ); | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 8 | my $subfields = $pica_path->subfields; | |||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | 8 | ▶ | sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=15 SCAR=27.2
| |||||||||||||||||||||||||||||||||
| 42 | 8 | my ($data) = @_; | |||||||||||||||||||||||||||||||
| 43 | my @values = | ||||||||||||||||||||||||||||||||
| 44 | 8 | ▶ | map { ref $_ eq 'ARRAY' ? @$_ : $_ } @{ $value_getter->($data) }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 45 | 8 | ▶ | return $data unless @values; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | 8 | my $records = $record_getter->($data); | |||||||||||||||||||||||||||||||
| 48 | 8 | ▶ | if ( !@$records ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 49 | 1 | my $record = []; | |||||||||||||||||||||||||||||||
| 50 | 1 | $records = [$record]; | |||||||||||||||||||||||||||||||
| 51 | 1 | $record_path->creator($record)->($data); | |||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | 8 | for my $record (@$records) { | |||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | my $fields = | ||||||||||||||||||||||||||||||||
| 57 | 8 | ▶ | [ $force_new ? () : grep { $pica_path->match_field($_) } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 58 | @$record ]; | ||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 8 | ▶ | if (@$fields) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 61 | 1 | my @sf_codes = split '', $subfields; | |||||||||||||||||||||||||||||||
| 62 | 1 | my @sf_values = @values; | |||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 1 | foreach my $f (@$fields) { | |||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | my $annotation = @$f % 2 ? pop @$f : undef; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | for ( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$i < @sf_codes and $i < @sf_values
MC/DC50%1/2
$i < @sf_codes and $i < @sf_values
$i < @sf_codes
$i < @sf_values
Truth table66%2/3
A and B
A= $i < @sf_codesB= $i < @sf_values
| |||||||||||||||||||||||||||||||||
| 68 | my $i = 0 ; | ||||||||||||||||||||||||||||||||
| 69 | $i < @sf_codes && $i < @sf_values ; | ||||||||||||||||||||||||||||||||
| 70 | $i++ | ||||||||||||||||||||||||||||||||
| 71 | ) | ||||||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||||||
| 73 | 1 | push @$f, $sf_codes[$i], $sf_values[$i]; | |||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | 1 | ▶ | push @$f, $annotation if defined $annotation; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||
| 79 | elsif (@fixed_field) { | ||||||||||||||||||||||||||||||||
| 80 | 7 | my $field = [@fixed_field]; | |||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 7 | my $i = 0; | |||||||||||||||||||||||||||||||
| 83 | 7 | foreach ( split '', $subfields ) { | |||||||||||||||||||||||||||||||
| 84 | 8 | push @$field, $_, $values[ $i++ ]; | |||||||||||||||||||||||||||||||
| 85 | 8 | ▶ | last if $i >= @values; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | 7 | push @$record, $field; | |||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 8 | $data; | |||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||
| 94 | 8 | } | |||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | 2 | 1; | |||||||||||||||||||||||||||||||
| 97 | __END__ | ||||||||||||||||||||||||||||||||