Fix/pica_map.pm

filter: Statementstmt 100% 40 / 40 Branchbran 100% 10 / 10 Conditioncond 100% 14 / 14 MC/DCmcdc 100% 7 / 7 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 100% 78 / 78 CC 12 SCAR 16.1
CC
12
Cov
100%
_build_fixer
7.0
__ANON__
6.0
BEGIN
1.0
CRAP 5.0
« Fix/Bind/pica_each.pm ↑ Summary Fix/pica_set.pm »
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
BranchTrueFalseTotal
$key =~ /^(\$.*|[0-9]+)$/ ? : 17 33 50
Condition100%8/8
$self->join // ""
l!l
149
$self->split // 0
l!l
1832
$self->pluck // 0
l!l
446
$self->nested_arrays // 0
l!l
842
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
Aresult
11
00
Truth table100%2/2
A
A= $self->split
Aresult
11
00
Truth table100%2/2
A
A= $self->pluck
Aresult
11
00
Truth table100%2/2
A
A= $self->nested_arrays
Aresult
11
00
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
BranchTrueFalseTotal
if $pica_path =~ /^\$/ 1 49 50
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
BranchTrueFalseTotal
if (defined $matches) 70 85 155
45 $matches = [$matches]
46 70 ▶ if !ref($matches) || ( $opt{split} && !$opt{force_array} );
Branch: 1 branch
BranchTrueFalseTotal
if not ref $matches or $opt{"split"} and not $opt{"force_array"} 54 16 70
Condition100%6/6
not ref $matches or $opt{"split"} and not $opt{"force_array"}
l!l&&r!l&&!r
45916
$opt{"split"} and not $opt{"force_array"}
!ll&&!rl&&r
889
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"}
ABCresult
1XX1
0111
00X0
0100
47 70 ▶ while (@$matches) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$matches) 71 70 141
48 71 $data = $creator->( $data, shift @$matches );
49 }
50  
51 }
52 155 return $data;
53 }
54 50 }
55  
56 6 1;
57  
58 __END__
« Fix/Bind/pica_each.pm ↑ Summary Fix/pica_set.pm »