#!perl use strict; use warnings; use Test::More; use Test::Exception; use Catmandu; my $pkg; BEGIN { $pkg = 'Catmandu::Fix::marc_paste'; use_ok $pkg; } require_ok $pkg; my $mrc = <<'MRC'; 92005291 Title / Name X Y Z MRC note 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl)'; { my $importer = Catmandu->importer( 'MARC', file => \$mrc, type => 'XML', fix => 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl)' ); my $record = $importer->first; is_deeply $record->{record}->[-1], [ '002' , ' ' , ' ' , '_' , ' 92005291 ' ] , 'marc_copy(001,cntrl)'; } note 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl,at:245)'; { my $importer = Catmandu->importer( 'MARC', file => \$mrc, type => 'XML', fix => 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl,at:245)' ); my $record = $importer->first; is_deeply $record->{record}->[-3], [ '002' , ' ' , ' ' , '_' , ' 92005291 ' ] , 'marc_copy(001,cntrl)'; } note 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl,at:245c)'; { my $importer = Catmandu->importer( 'MARC', file => \$mrc, type => 'XML', fix => 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl,at:245c)' ); my $record = $importer->first; is_deeply $record->{record}->[-3], [ '002' , ' ' , ' ' , '_' , ' 92005291 ' ] , 'marc_copy(001,cntrl)'; } note 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl,at:245x)'; { my $importer = Catmandu->importer( 'MARC', file => \$mrc, type => 'XML', fix => 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl,at:245x)' ); my $record = $importer->first; is_deeply $record->{record}->[-3], [ '245' , '1' , '0' , 'a' , 'Title / ', 'c' , 'Name' ] , 'marc_copy(001,cntrl)'; } note 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl,at:245c,equals:Name)'; { my $importer = Catmandu->importer( 'MARC', file => \$mrc, type => 'XML', fix => 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl,at:245c,equals:Name)' ); my $record = $importer->first; is_deeply $record->{record}->[-3], [ '002' , ' ' , ' ' , '_' , ' 92005291 ' ] , 'marc_copy(001,cntrl)'; } note 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl,at:245,equals:"Title / Name")'; { my $importer = Catmandu->importer( 'MARC', file => \$mrc, type => 'XML', fix => 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl,at:245,equals:"Title / Name")' ); my $record = $importer->first; is_deeply $record->{record}->[-3], [ '002' , ' ' , ' ' , '_' , ' 92005291 ' ] , 'marc_copy(001,cntrl)'; } done_testing;