Fix/Condition/marc_any_match.pm

filter: Statementstmt 100% 39 / 39 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 97.9% 47 / 48 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Fix/Condition/marc_all_match.pm ↑ Summary Fix/Condition/marc_match.pm »
1 package Catmandu::Fix::Condition::marc_any_match;
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::any_match;
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 1 has value => (fix_arg => 1);
16  
17 3 ▶sub emit {
Subroutine emit: called CC=1 SCAR=0.0
Pod undocumented
18 3 my ($self,$fixer,$label) = @_;
19  
20 3 my $perl;
21  
22 3 my $tmp_var = '_tmp_' . int(rand(9999));
23 3 my $marc_map = Catmandu::Fix::marc_map->new($self->marc_path , "$tmp_var.\$append");
24 3 $perl .= $marc_map->emit($fixer,$label);
25  
26 3 my $any_match = Catmandu::Fix::Condition::any_match->new("$tmp_var.*",$self->value);
27 3 my $remove_field = Catmandu::Fix::remove_field->new($tmp_var);
28  
29 3 my $pass_fixes = $self->pass_fixes;
30 3 my $fail_fixes = $self->fail_fixes;
31  
32 3 $any_match->pass_fixes([ $remove_field , @$pass_fixes ]);
33 3 $any_match->fail_fixes([ $remove_field , @$fail_fixes ]);
34  
35 3 $perl .= $any_match->emit($fixer,$label);
36  
37 3 $perl;
38 }
39  
40 =head1 NAME
41  
42 Catmandu::Fix::Condition::marc_any_match - Test if a MARC (sub)field matches a value
43  
44 =head1 SYNOPSIS
45  
46 # marc_any_match(MARC_PATH,REGEX)
47  
48 # Match when 245 contains the value "My funny title"
49 if marc_any_match('245','My funny title')
50 add_field('my.funny.title','true')
51 end
52  
53 # Match when 245a contains the value "My funny title"
54 if marc_any_match('245a','My funny title')
55 add_field('my.funny.title','true')
56 end
57  
58 # Match when at least one 650 field contains digits
59 if marc_any_match('650','[0-9]')
60 add_field('has_digits','true')
61 end
62  
63 =head1 DESCRIPTION
64  
65 Evaluate the enclosing fixes only if the MARC (sub)field matches a
66 regular expression. When the MARC field is a repeated fiels, then at
67 least one MARC fields should match the regular expression.
68  
69 =head1 METHODS
70  
71 =head2 marc_any_match(MARC_PATH, REGEX)
72  
73 Evaluates to true when at least one MARC_PATH values matches the REGEX, false otherwise.
74  
75 =head1 SEE ALSO
76  
77 L<Catmandu::Fix::Condition::marc_all_match>
78  
79 =cut
80  
81 1 1;
« Fix/Condition/marc_all_match.pm ↑ Summary Fix/Condition/marc_match.pm »