Fix/marc_cut.pm

filter: Statementstmt 100% 36 / 36 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 97.6% 42 / 43 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Fix/marc_replace_all.pm ↑ Summary Fix/marc_copy.pm »
1 package Catmandu::Fix::marc_cut;
2  
3 1 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Catmandu::MARC;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Catmandu::Fix::Has;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 with 'Catmandu::Fix::Base';
9  
10 1 our $VERSION = '1.13';
11  
12 1 has marc_path => (fix_arg => 1);
13 1 has path => (fix_arg => 1);
14 1 has equals => (fix_opt => 1);
15  
16 7 ▶sub emit {
Subroutine emit: called CC=1 SCAR=0.0
Pod undocumented
17 7 my ($self,$fixer) = @_;
18 7 my $path = $fixer->split_path($self->path);
19 7 my $marc_obj = Catmandu::MARC->instance;
20  
21 # Precompile the marc_path to gain some speed
22 7 my $marc_context = $marc_obj->compile_marc_path($self->marc_path, subfield_wildcard => 0);
23 7 my $marc = $fixer->capture($marc_obj);
24 7 my $marc_path = $fixer->capture($marc_context);
25 7 my $equals = $fixer->capture($self->equals);
26  
27 7 my $var = $fixer->var;
28 7 my $result = $fixer->generate_var;
29 7 my $current_value = $fixer->generate_var;
30  
31 7 my $perl = "";
32 7 $perl .= $fixer->emit_declare_vars($current_value, "[]");
33 7 $perl .=<<EOF;
34 if (my ${result} = ${marc}->marc_copy(
35 ${var},
36 ${marc_path},
37 ${equals},1) ) {
38 ${result} = ref(${result}) ? ${result} : [${result}];
39 for ${current_value} (\@{${result}}) {
40 EOF
41  
42 $perl .= $fixer->emit_create_path(
43 $var,
44 $path,
45 7 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
46 7 my $var2 = shift;
47 7 "${var2} = ${current_value}"
48 }
49 7 );
50  
51 7 $perl .=<<EOF;
52 }
53 }
54 EOF
55 7 $perl;
56 }
57  
58 1 1;
59  
60 __END__
« Fix/marc_replace_all.pm ↑ Summary Fix/marc_copy.pm »