| 1 | package Catmandu::Fix::Condition::marc_spec_has; | ||
| 2 | 1 | ▶ | use Catmandu::Sane; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | ▶ | use Catmandu::Fix::marc_spec; |
|
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.12'; | |
| 11 | |||
| 12 | 1 | with 'Catmandu::Fix::Condition'; | |
| 13 | |||
| 14 | 1 | has marc_spec => (fix_arg => 1); | |
| 15 | |||
| 16 | 2 | ▶ | sub emit { |
|
Subroutine
emit: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 17 | 2 | my ($self,$fixer,$label) = @_; | |
| 18 | |||
| 19 | 2 | my $perl; | |
| 20 | |||
| 21 | 2 | my $tmp_var = '_tmp_' . int(rand(9999)); | |
| 22 | 2 | my $marc_spec = Catmandu::Fix::marc_spec->new($self->marc_spec , "$tmp_var.\$append"); | |
| 23 | 2 | $perl .= $marc_spec->emit($fixer,$label); | |
| 24 | |||
| 25 | 2 | my $all_match = Catmandu::Fix::Condition::exists->new("$tmp_var"); | |
| 26 | 2 | my $remove_field = Catmandu::Fix::remove_field->new($tmp_var); | |
| 27 | |||
| 28 | 2 | my $pass_fixes = $self->pass_fixes; | |
| 29 | 2 | my $fail_fixes = $self->fail_fixes; | |
| 30 | |||
| 31 | 2 | $all_match->pass_fixes([ $remove_field , @$pass_fixes ]); | |
| 32 | 2 | $all_match->fail_fixes([ $remove_field , @$fail_fixes ]); | |
| 33 | |||
| 34 | 2 | $perl .= $all_match->emit($fixer,$label); | |
| 35 | |||
| 36 | 2 | $perl; | |
| 37 | } | ||
| 38 | |||
| 39 | =head1 NAME | ||
| 40 | |||
| 41 | Catmandu::Fix::Condition::marc_spec_has - Test if a MARCspec references data | ||
| 42 | |||
| 43 | =head1 SYNOPSIS | ||
| 44 | |||
| 45 | # marc_spec_has(MARCspec) | ||
| 46 | |||
| 47 | unless marc_spec_has('LDR{/6=\a}{/7=\a|/7=\c|/7=\d|/7=\m}') | ||
| 48 | set_field('type','Book') | ||
| 49 | end | ||
| 50 | |||
| 51 | =head1 DESCRIPTION | ||
| 52 | |||
| 53 | Evaluate the enclosing fixes only if the MARCspec does reference data. | ||
| 54 | |||
| 55 | Does the same like L<marc_has|Catmandu::Fix::Condition::marc_has> but uses | ||
| 56 | MARCspec - A common MARC record path language. | ||
| 57 | |||
| 58 | See L<MARCspec - A common MARC record path language|http://marcspec.github.io/MARCspec/> | ||
| 59 | for documentation on the path syntax. | ||
| 60 | |||
| 61 | =head1 METHODS | ||
| 62 | |||
| 63 | =head2 marc_spec_has(MARCspec) | ||
| 64 | |||
| 65 | Evaluates to true when the MARCspec references data, false otherwise. | ||
| 66 | |||
| 67 | =head1 SEE ALSO | ||
| 68 | |||
| 69 | =over | ||
| 70 | |||
| 71 | =item * L<Catmandu::Fix::marc_has> | ||
| 72 | |||
| 73 | =item * L<Catmandu::Fix::marc_match> | ||
| 74 | |||
| 75 | =item * L<Catmandu::Fix::marc_has_many> | ||
| 76 | |||
| 77 | =back | ||
| 78 | |||
| 79 | =cut | ||
| 80 | |||
| 81 | 1 | 1; | |