| 1 |
#!perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Test::More; |
| 6 |
use Test::Exception; |
| 7 |
use Catmandu::Exporter::MARC; |
| 8 |
use Catmandu::Importer::MARC; |
| 9 |
|
| 10 |
my $pkg; |
| 11 |
|
| 12 |
BEGIN { |
| 13 |
$pkg = 'Catmandu::Exporter::MARC::MARCMaker'; |
| 14 |
use_ok $pkg; |
| 15 |
} |
| 16 |
|
| 17 |
require_ok $pkg; |
| 18 |
|
| 19 |
my $marcmaker = undef; |
| 20 |
|
| 21 |
note("Exporting to MARCMaker"); |
| 22 |
{ |
| 23 |
my $exporter = Catmandu::Exporter::MARC->new(file => \$marcmaker, type=> 'MARCMaker'); |
| 24 |
|
| 25 |
ok $exporter , 'got an MARC/MARCMaker exporter'; |
| 26 |
|
| 27 |
ok $exporter->add({ |
| 28 |
_id => '1' , |
| 29 |
record => [ |
| 30 |
['FMT', undef, undef, '_', 'BK'], |
| 31 |
['001', undef, undef, '_', 'rec001'], |
| 32 |
['100', ' ', ' ', 'a', 'Davis, Miles' , 'c' , 'Test'], |
| 33 |
['245', ' ', ' ', |
| 34 |
'a', 'Sketches in Blue' , |
| 35 |
], |
| 36 |
['500', ' ', ' ', 'a', undef], |
| 37 |
['501', ' ', ' ' ], |
| 38 |
['502', ' ', ' ', 'a', undef, 'b' , 'ok'], |
| 39 |
['503', ' ', ' ', 'a', ''], |
| 40 |
['CAT', ' ', ' ', 'a', 'test'], |
| 41 |
] |
| 42 |
}) , 'add'; |
| 43 |
|
| 44 |
ok $exporter->commit , 'commit'; |
| 45 |
} |
| 46 |
|
| 47 |
note("Roundtripping"); |
| 48 |
{ |
| 49 |
my $importer = Catmandu::Importer::MARC->new(file => 't/oschrift_me.mrc', type=> 'ISO'); |
| 50 |
|
| 51 |
ok $importer , 'got an MARC/MARCMaker importer'; |
| 52 |
|
| 53 |
my $records = $importer->to_array; |
| 54 |
|
| 55 |
ok @$records == 1; |
| 56 |
|
| 57 |
my $marcmaker; |
| 58 |
|
| 59 |
my $exporter = Catmandu::Exporter::MARC->new(file => \$marcmaker, type=> 'MARCMaker'); |
| 60 |
|
| 61 |
ok $exporter->add($records->[0]) , 'commit'; |
| 62 |
|
| 63 |
ok $exporter->commit , 'commit'; |
| 64 |
|
| 65 |
my $importer2 = Catmandu::Importer::MARC->new(file => \$marcmaker, type=> 'MARCMaker'); |
| 66 |
|
| 67 |
ok $importer2 , 'got an MARC/MARCMaker importer'; |
| 68 |
|
| 69 |
my $records2 = $importer2->to_array; |
| 70 |
|
| 71 |
ok @$records2 == 1; |
| 72 |
|
| 73 |
is_deeply $records->[0] , $records2->[0]; |
| 74 |
} |
| 75 |
|
| 76 |
done_testing; |