| 1 | =head1 NAME |
| 2 | |
| 3 | Catmandu::Importer::MARC::Lint - Package that imports USMARC records validated with MARC::Lint |
| 4 | |
| 5 | =head1 SYNOPSIS |
| 6 | |
| 7 | # From the command line |
| 8 | $ catmandu convert MARC --type Lint --fix "marc_map('245a','title')" < /foo/data.mrc |
| 9 | |
| 10 | # From perl |
| 11 | use Catmandu; |
| 12 | |
| 13 | # import records from file |
| 14 | my $importer = Catmandu->importer('MARC',file => '/foo/data.mrc', type => 'Lint'); |
| 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 DESCRIPTION |
| 30 | |
| 31 | All items produced with the Catmandu::Importer::MARC::Lint importer contain three keys: |
| 32 | |
| 33 | '_id' : the system identifier of the record (usually the 001 field) |
| 34 | 'record' : an ARRAY of ARRAYs containing the record data |
| 35 | 'lint' : the output of MARC::Lint's check_record on the MARC record |
| 36 | |
| 37 | =head1 CONFIGURATION |
| 38 | |
| 39 | =over |
| 40 | |
| 41 | =item id |
| 42 | |
| 43 | The MARC field which contains the system id (default: 001) |
| 44 | |
| 45 | =item file |
| 46 | |
| 47 | Read input from a local file given by its path. Alternatively a scalar |
| 48 | reference can be passed to read from a string. |
| 49 | |
| 50 | =item fh |
| 51 | |
| 52 | Read input from an L<IO::Handle>. If not specified, L<Catmandu::Util::io> is used to |
| 53 | create the input stream from the C<file> argument or by using STDIN. |
| 54 | |
| 55 | =item encoding |
| 56 | |
| 57 | Binmode of the input stream C<fh>. Set to C<:utf8> by default. |
| 58 | |
| 59 | =item fix |
| 60 | |
| 61 | An ARRAY of one or more fixes or file scripts to be applied to imported items. |
| 62 | |
| 63 | =back |
| 64 | |
| 65 | =head1 METHODS |
| 66 | |
| 67 | Every Catmandu::Importer is a Catmandu::Iterable all its methods are inherited. |
| 68 | |
| 69 | =head1 SEE ALSO |
| 70 | |
| 71 | L<Catmandu::Importer>, |
| 72 | L<Catmandu::Iterable> |
| 73 | |
| 74 | =cut |
| 75 | package Catmandu::Importer::MARC::Lintscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/Lint/; |
| 76 | use Catmandu::Sanescip-perl cpan Catmandu-MARC 1.32 Catmandu/Sane/; |
| 77 | use Mooscip-perl cpan Catmandu-MARC 1.32 Moo/; |
| 78 | use MARC::File::USMARCscip-perl cpan Catmandu-MARC 1.32 MARC/File/USMARC/; |
| 79 | use MARC::Lintscip-perl cpan Catmandu-MARC 1.32 MARC/Lint/; |
| 80 | use Catmandu::Importer::MARC::Decoderscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/Decoder/; |
| 81 | |
| 82 | our $VERSIONscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/Lint/$VERSION. = '1.32'; |
| 83 | |
| 84 | withscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/Lint/with(). 'Catmandu::Importer'; |
| 85 | |
| 86 | hasscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/Lint/has(). id => (is => 'ro' , default => sub { '001' }); |
| 87 | hasscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/Lint/has(). decoder => ( |
| 88 | is => 'ro', |
| 89 | lazy => 1 , |
| 90 | builder => sub { |
| 91 | Catmandu::Importer::MARC::Decoder->newscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/Decoder/new().; |
| 92 | } ); |
| 93 | |
| 94 | sub generatorscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/Lint/generator(). { |
| 95 | my ($self) = @_scip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/Lint/`@_`.; |
| 96 | my $lint = MARC::Lint->newscip-perl cpan Catmandu-MARC 1.32 MARC/Lint/new().; |
| 97 | my $file = MARC::File::USMARC->inscip-perl cpan Catmandu-MARC 1.32 MARC/File/USMARC/in().($self->fhscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/Lint/fh().); |
| 98 | # MARC::File doesn't provide support for inline files |
| 99 | $file = $self->decoderscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/Lint/decoder().->fake_marc_filescip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/Lint/fake_marc_file().($self->fhscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/Lint/fh().,'MARC::File::USMARC') unless $file; |
| 100 | sub { |
| 101 | my $marc = $file->nextscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/Lint/next().(); |
| 102 | |
| 103 | return undef unless $marc; |
| 104 | |
| 105 | my $doc = $self->decodescip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/Lint/decode().rscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/Lint/decoder().->decode($marc,$self->idscip-perl cpan Catmandu-MARC 1.32 Catmandu/Importer/MARC/Lint/id().); |
| 106 | $lint->check_recordscip-perl cpan Catmandu-MARC 1.32 MARC/Lint/check_record().( $marc ); |
| 107 | $doc->{lint} = [$lint->warningsscip-perl cpan Catmandu-MARC 1.32 MARC/Lint/warnings().]; |
| 108 | $doc; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | 1; |