Fix/pica_set.pm

filter: Statementstmt 100% 39 / 39 Branchbran 100% 6 / 6 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 93.2% 55 / 59 CC 8 SCAR 12.2
CC
8
Cov
96%
__ANON__
6.0
_build_fixer
3.0
BEGIN
1.0
CRAP 3.4
« Fix/pica_map.pm ↑ Summary Fix/Bind/pica_diff.pm »
1 package Catmandu::Fix::pica_set;
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 3 ▶ coerce => sub { PICA::Path->new( $_[0] ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
16 2 );
17 2 has record => ( fix_opt => 1 );
18
19 2 with 'Catmandu::Fix::Builder';
20
21 3 ▶sub _build_fixer {
Subroutine _build_fixer: called CC=3 SCAR=11.0
22 3 my ($self) = @_;
23
24 3 my $value_getter = as_path( $self->path )->getter;
25 3 ▶ my $record_getter = as_path( $self->record // 'record' )->getter;
Condition50%1/2
$self->record // "record"
l!l
03
MC/DC0%0/1
$self->record // "record"
$self->record
Truth table50%1/2
A
A= $self->record
Aresult
11
00
26 3 my $pica_path = $self->pica_path;
27 3 ▶ my $subfields = '[' . ( $pica_path->subfields // '_A-Za-z0-9' ) . ']';
Condition50%1/2
$pica_path->subfields // "_A-Za-z0-9"
l!l
30
MC/DC0%0/1
$pica_path->subfields // "_A-Za-z0-9"
$pica_path->subfields
Truth table50%1/2
A
A= $pica_path->subfields
Aresult
11
00
28 3 $subfields = qr{$subfields};
29
30 3 ▶ sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
31 3 my ($data) = @_;
32 3 my $value = $value_getter->($data)->[0];
33 3 for my $record ( @{ $record_getter->($data) } ) {
34 3 for my $field (@$record) {
35 41 ▶ next unless $pica_path->match_field($field);
Branch: 1 branch
BranchTrueFalseTotal
unless $pica_path->match_field($field) 38 3 41
36 3 ▶ for ( my $i = 3 ; $i < @$field ; $i += 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$field) 4 3 7
37 4 ▶ next unless $field->[ $i - 1 ] =~ $subfields;
Branch: 1 branch
BranchTrueFalseTotal
unless $$field[$i - 1] =~ /$subfields/ 1 3 4
38 3 $field->[$i] = $value;
39 }
40 }
41 }
42 3 $data;
43 }
44 3 }
45
46 2 1;
47 __END__
« Fix/pica_map.pm ↑ Summary Fix/Bind/pica_diff.pm »