| 1 | =head1 NAME |
| 2 | |
| 3 | Catmandu::Importer::MARC::MiJ - Package that imports MARC-in-JSON records |
| 4 | |
| 5 | =head1 SYNOPSIS |
| 6 | |
| 7 | # From the command line |
| 8 | $ catmandu convert MARC --type MiJ --fix "marc_map('245a','title')" < /foo/bar.json |
| 9 | |
| 10 | # From perl |
| 11 | use Catmandu; |
| 12 | |
| 13 | # import records from file |
| 14 | my $importer = Catmandu->importer('MARC',file => '/foo/bar.json', type => 'MiJ'); |
| 15 | my $fixer = Catmandu->fixer("marc_map('245a','title')"); |
| 16 | |
| 17 | $importer->each(sub { |
| 18 | my $item = shift; |
| 19 | ... |
| 20 | }); |
| 21 | |
| 22 | # or using the fixer |
| 23 | |
| 24 | $fixer->fix($importer)->each(sub { |
| 25 | my $item = shift; |
| 26 | printf "title: %s\n" , $item->{title}; |
| 27 | }); |
| 28 | |
| 29 | =head1 METHODS |
| 30 | |
| 31 | =head2 new(file => $file , fh => $fh , id => $field) |
| 32 | |
| 33 | Parse a file or a filehandle into a L<Catmandu::Iterable>. Optionally provide an |
| 34 | id attribute specifying the source of the system identifer '_id' field (e.g. '001'). |
| 35 | |
| 36 | =head1 INHERTED METHODS |
| 37 | |
| 38 | =head2 count |
| 39 | |
| 40 | =head2 each(&callback) |
| 41 | |
| 42 | =head2 ... |
| 43 | |
| 44 | Every Catmandu::Importer is a Catmandu::Iterable all its methods are inherited. |
| 45 | |
| 46 | =head1 SEE ALSO |
| 47 | |
| 48 | L<MARC::File::MARCMaker> |
| 49 | |
| 50 | =cut |
| 51 | package Catmandu::Importer::MARC::MiJscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/MiJ/; |
| 52 | use Catmandu::Sanescip-perl cpan Catmandu-MARC 1.32 Catmandu/Sane/; |
| 53 | use Mooscip-perl cpan Catmandu-MARC 1.32 Moo/; |
| 54 | use MARC::Recordscip-perl cpan Catmandu-MARC 1.32 MARC/Record/; |
| 55 | use Catmandu::Importer::MARC::Decoderscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/Decoder/; |
| 56 | use MARC::File::MiJscip-perl cpan Catmandu-MARC 1.32 MARC/File/MiJ/; |
| 57 | |
| 58 | our $VERSIONscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/MiJ/$VERSION. = '1.32'; |
| 59 | |
| 60 | withscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/MiJ/with(). 'Catmandu::Importer'; |
| 61 | |
| 62 | hasscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/MiJ/has(). id => (is => 'ro' , default => sub { '001' }); |
| 63 | hasscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/MiJ/has(). decoder => ( |
| 64 | is => 'ro', |
| 65 | lazy => 1 , |
| 66 | builder => sub { |
| 67 | Catmandu::Importer::MARC::Decoder->newscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/Decoder/new().; |
| 68 | } ); |
| 69 | |
| 70 | sub generatorscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/MiJ/generator(). { |
| 71 | my ($self) = @_scip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/MiJ/`@_`.; |
| 72 | my $file = MARC::File::MiJ->inscip-perl cpan Catmandu-MARC 1.32 MARC/File/MiJ/in().($self->filescip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/MiJ/file().); |
| 73 | |
| 74 | # MARC::File doesn't provide support for inline files |
| 75 | $file = $self->decoderscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/MiJ/decoder().->fake_marc_filescip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/MiJ/fake_marc_file().($self->fhscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/MiJ/fh().,'MARC::File::MiJ') unless $file; |
| 76 | sub { |
| 77 | $self->decodescip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/MiJ/decode().rscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/MiJ/decoder().->decode($file->nextscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/MiJ/next().(),$self->idscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/MiJ/id().); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | 1; |