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