Fix/marc_spec.pm

filter: Statementstmt 100% 42 / 42 Branchbran 100% 2 / 2 Conditioncond 100% 10 / 10 MC/DCmcdc 100% 5 / 5 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 98.4% 65 / 66 CC 7 SCAR 15.0
CC
7
Cov
100%
emit
7.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.5
« Exporter/MARC/Base.pm ↑ Summary Validator/MARC.pm »
1 package Catmandu::Fix::marc_spec;
2  
3 5 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use Catmandu::MARC;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Catmandu::Fix::Has;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 with 'Catmandu::Fix::Base';
9  
10 5 our $VERSION = '1.33';
11  
12 5 has spec => ( fix_arg=> 1 );
13 5 has path => ( fix_arg=> 1 );
14 5 has split => ( fix_opt=> 1 );
15 5 has join => ( fix_opt=> 1 );
16 5 has value => ( fix_opt=> 1 );
17 5 has pluck => ( fix_opt=> 1 );
18 5 has invert => ( fix_opt=> 1 );
19 5 has nested_arrays => ( fix_opt=> 1 );
20  
21 128 ▶sub emit {
Subroutine emit: called CC=7 SCAR=19.5
Pod undocumented
22 128 my ( $self, $fixer ) = @_;
23 128 my $path = $fixer->split_path( $self->path );
24 128 my $key = $path->[-1];
25 128 my $marc_obj = Catmandu::MARC->instance;
26  
27 # Precompile the marc_path to gain some speed
28 128 my $spec = $marc_obj->parse_marc_spec( $self->spec );
29 128 my $marc = $fixer->capture($marc_obj);
30 128 my $marc_spec = $fixer->capture($spec);
31 128 ▶ my $marc_opt = $fixer->capture({
Branch: 1 branch
BranchTrueFalseTotal
$key =~ /^(\$.*|[0-9]+)$/ ? : 33 95 128
Condition100%10/10
$self->join // ""
l!l
4124
$self->split // 0
l!l
3395
$self->pluck // 0
l!l
1127
$self->nested_arrays // 0
l!l
12116
$self->invert // 0
l!l
11117
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
MC/DC100%1/1
$self->invert // 0
$self->invert
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
Truth table100%2/2
A
A= $self->invert
Aresult
11
00
32 '-join' => $self->join // '' ,
33 '-split' => $self->split // 0 ,
34 '-pluck' => $self->pluck // 0 ,
35 '-nested_arrays' => $self->nested_arrays // 0 ,
36 '-invert' => $self->invert // 0 ,
37 '-value' => $self->value ,
38 '-force_array' => ($key =~ /^(\$.*|[0-9]+)$/) ? 1 : 0
39 });
40  
41 128 my $var = $fixer->var;
42 128 my $result = $fixer->generate_var;
43 128 my $current_value = $fixer->generate_var;
44  
45 128 my $perl = "";
46 128 $perl .= $fixer->emit_declare_vars($current_value, "[]");
47 128 $perl .=<<EOF;
48 if (defined(my ${result} = ${marc}->marc_spec(
49 ${var},
50 ${marc_spec},
51 ${marc_opt})) ) {
52 ${result} = ref(${result}) ? ${result} : [${result}];
53 for ${current_value} (\@{${result}}) {
54 EOF
55  
56 $perl .= $fixer->emit_create_path(
57 $var,
58 $path,
59 128 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
60 128 my $var2 = shift;
61 128 "${var2} = ${current_value}"
62 }
63 128 );
64  
65 128 $perl .=<<EOF;
66 }
67 }
68 EOF
69 128 $perl;
70 }
71  
72 5 1;
73  
74 __END__
« Exporter/MARC/Base.pm ↑ Summary Validator/MARC.pm »