| 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::Lint; | ||||||||||
| 76 | 1 | ▶ | use Catmandu::Sane; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 77 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 78 | 1 | ▶ | use MARC::File::USMARC; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 79 | 1 | ▶ | use MARC::Lint; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 80 | 1 | ▶ | use Catmandu::Importer::MARC::Decoder; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 81 | |||||||||||
| 82 | 1 | our $VERSION = '1.33'; | |||||||||
| 83 | |||||||||||
| 84 | 1 | with 'Catmandu::Importer'; | |||||||||
| 85 | |||||||||||
| 86 | 1 | ▶ | has id => (is => 'ro' , default => sub { '001' }); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 87 | has decoder => ( | ||||||||||
| 88 | is => 'ro', | ||||||||||
| 89 | lazy => 1 , | ||||||||||
| 90 | 1 | ▶ | builder => sub { | ||||||||
|
Subroutine
_build_decoder: called CC=1 SCAR=0.0
| |||||||||||
| 91 | 1 | Catmandu::Importer::MARC::Decoder->new; | |||||||||
| 92 | 1 | } ); | |||||||||
| 93 | |||||||||||
| 94 | 1 | ▶ | sub generator { | ||||||||
|
Subroutine
generator: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 95 | 1 | my ($self) = @_; | |||||||||
| 96 | 1 | my $lint = MARC::Lint->new; | |||||||||
| 97 | 1 | my $file = MARC::File::USMARC->in($self->fh); | |||||||||
| 98 | # MARC::File doesn't provide support for inline files | ||||||||||
| 99 | 1 | ▶ | $file = $self->decoder->fake_marc_file($self->fh,'MARC::File::USMARC') unless $file; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | sub { | ||||||||||
| 101 | my $marc = $file->next(); | ||||||||||
| 102 | |||||||||||
| 103 | return undef unless $marc; | ||||||||||
| 104 | |||||||||||
| 105 | my $doc = $self->decoder->decode($marc,$self->id); | ||||||||||
| 106 | $lint->check_record( $marc ); | ||||||||||
| 107 | $doc->{lint} = [$lint->warnings]; | ||||||||||
| 108 | $doc; | ||||||||||
| 109 | } | ||||||||||
| 110 | 1 | } | |||||||||
| 111 | |||||||||||
| 112 | 1 | 1; | |||||||||