Fix/Condition/marc_has_many.pm

filter: Statementstmt 100% 38 / 38 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 97.9% 48 / 49 CC 2 SCAR 2.0
CC
2
Cov
100%
emit
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« Importer/MARC/ISO.pm ↑ Summary Exporter/MARC/MiJ.pm »
1 package Catmandu::Fix::Condition::marc_has_many;
2 2 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use Catmandu::Fix::marc_map;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Catmandu::Fix::Condition::exists;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Catmandu::Fix::set_field;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Catmandu::Fix::remove_field;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Catmandu::Fix::Has;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $VERSION = '1.33';
11  
12 2 with 'Catmandu::Fix::Condition';
13  
14 2 has marc_path => (fix_arg => 1);
15  
16 8 ▶sub emit {
Subroutine emit: called CC=2 SCAR=6.9
Pod undocumented
17 8 my ($self,$fixer,$label) = @_;
18  
19 8 my $perl;
20  
21 8 my $tmp_var = '_tmp_' . int(rand(9999));
22 8 my $marc_map = Catmandu::Fix::marc_map->new(
23 $self->marc_path ,
24 "$tmp_var" ,
25 -split=>1 ,
26 -nested_arrays=>1
27 );
28 8 $perl .= $marc_map->emit($fixer,$label);
29  
30 8 ▶ my $all_match =
Branch: 1 branch
BranchTrueFalseTotal
$self->marc_path =~ m[^...(\/[0-9]+-[0-9]+)?$] ? : 4 4 8
31 $self->marc_path =~ m{^...(\/[0-9]+-[0-9]+)?$} ?
32 Catmandu::Fix::Condition::exists->new("$tmp_var.1") :
33 Catmandu::Fix::Condition::exists->new("$tmp_var.0.1");
34  
35 8 my $remove_field = Catmandu::Fix::remove_field->new($tmp_var);
36  
37 8 my $pass_fixes = $self->pass_fixes;
38 8 my $fail_fixes = $self->fail_fixes;
39  
40 8 $all_match->pass_fixes([ @$pass_fixes ]);
41 8 $all_match->fail_fixes([ @$fail_fixes ]);
42  
43 8 $perl .= $all_match->emit($fixer,$label);
44  
45 8 $perl;
46 }
47  
48 =head1 NAME
49  
50 Catmandu::Fix::Condition::marc_has_many - Test if a MARC has more than one (sub)field
51  
52 =head1 SYNOPSIS
53  
54 # marc_has_many(MARC_PATH)
55  
56 if marc_has_many('245')
57 add_field('error.$append','more than one 245!')
58 end
59  
60 =head1 DESCRIPTION
61  
62 Evaluate the enclosing fixes only if the MARC has more than one (sub)field.
63  
64 =head1 METHODS
65  
66 =head2 marc_has_many(MARC_PATH)
67  
68 Evaluates to true when the MARC has more than one (sub)field, false otherwise.
69  
70 =head1 SEE ALSO
71  
72 L<Catmandu::Fix::marc_has>
73  
74 =cut
75  
76 2 1;
« Importer/MARC/ISO.pm ↑ Summary Exporter/MARC/MiJ.pm »