Fix/Condition/marc_has.pm

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