| 1 |
#!perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Test::More; |
| 6 |
use Test::Exception; |
| 7 |
use Catmandu::Importer::MARC; |
| 8 |
use Catmandu::Fix; |
| 9 |
use utf8; |
| 10 |
|
| 11 |
my $pkg; |
| 12 |
|
| 13 |
BEGIN { |
| 14 |
$pkg = 'Catmandu::Fix::Bind::marc_each'; |
| 15 |
use_ok $pkg; |
| 16 |
} |
| 17 |
|
| 18 |
require_ok $pkg; |
| 19 |
|
| 20 |
my $fixer = Catmandu::Fix->new(fixes => [q| |
| 21 |
do marc_each() |
| 22 |
if marc_match("***a",'Perl') |
| 23 |
add_field(has_perl,true) |
| 24 |
end |
| 25 |
if marc_match("100",'.*') |
| 26 |
reject() |
| 27 |
end |
| 28 |
if marc_match(245a,'.*') |
| 29 |
marc_remove(245) |
| 30 |
end |
| 31 |
end |
| 32 |
marc_map("100",mainentry) |
| 33 |
marc_map("245",title) |
| 34 |
|]); |
| 35 |
|
| 36 |
my $importer = Catmandu::Importer::MARC->new( file => 't/camel.mrc', type => "ISO" ); |
| 37 |
|
| 38 |
$fixer->fix($importer)->each(sub { |
| 39 |
my $record = $_[0]; |
| 40 |
my $id = $record->{_id}; |
| 41 |
|
| 42 |
ok exists $record->{record}, "created a marc record $id"; |
| 43 |
is $record->{has_perl}, 'true', "created has_dlc tag $id"; |
| 44 |
ok ! exists $record->{mainentry} , "field 100 deleted $id"; |
| 45 |
ok ! exists $record->{title} , "field 245 deleted $id"; |
| 46 |
}); |
| 47 |
|
| 48 |
done_testing; |