| 1 | =head1 NAME | ||
| 2 | |||
| 3 | Catmandu::Importer::MARC::Record - Package that imports an array of MARC::Record | ||
| 4 | |||
| 5 | =head1 SYNOPSIS | ||
| 6 | |||
| 7 | # From perl | ||
| 8 | use Catmandu; | ||
| 9 | use MARC::Record; | ||
| 10 | |||
| 11 | my $record = MARC::Record->new(); | ||
| 12 | my $field = MARC::Field->new('245','','','a' => 'My title.'); | ||
| 13 | $record->append_fields($field); | ||
| 14 | |||
| 15 | # import records from file | ||
| 16 | my $importer = Catmandu->importer('MARC',file => '/foo/data.mrc' , records => [$record]); | ||
| 17 | my $fixer = Catmandu->fixer("marc_map('245a','title')"); | ||
| 18 | |||
| 19 | $importer->each(sub { | ||
| 20 | my $item = shift; | ||
| 21 | ... | ||
| 22 | }); | ||
| 23 | |||
| 24 | # or using the fixer | ||
| 25 | |||
| 26 | $fixer->fix($importer)->each(sub { | ||
| 27 | my $item = shift; | ||
| 28 | printf "title: %s\n" , $item->{title}; | ||
| 29 | }); | ||
| 30 | |||
| 31 | =head1 METHODS | ||
| 32 | |||
| 33 | =head2 new(records => [ <Marc::Record> , ... ] , id => $field) | ||
| 34 | |||
| 35 | Parse an array of L<MARC::Record> into a L<Catmandu::Iterable>. Optionally provide an | ||
| 36 | id attribute specifying the source of the system identifer '_id' field (e.g. '001'). | ||
| 37 | |||
| 38 | =head1 INHERTED METHODS | ||
| 39 | |||
| 40 | =head2 count | ||
| 41 | |||
| 42 | =head2 each(&callback) | ||
| 43 | |||
| 44 | =head2 ... | ||
| 45 | |||
| 46 | Every Catmandu::Importer is a Catmandu::Iterable all its methods are inherited. | ||
| 47 | |||
| 48 | =head1 SEE ALSO | ||
| 49 | |||
| 50 | L<MARC::Record> | ||
| 51 | |||
| 52 | =cut | ||
| 53 | package Catmandu::Importer::MARC::Record; | ||
| 54 | 1 | ▶ | use Catmandu::Sane; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 55 | 1 | ▶ | use Catmandu::Importer::MARC::Decoder; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 56 | 1 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 57 | |||
| 58 | 1 | our $VERSION = '1.33'; | |
| 59 | |||
| 60 | 1 | with 'Catmandu::Importer'; | |
| 61 | |||
| 62 | 1 | ▶ | has id => (is => 'ro' , default => sub { '001' }); |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 63 | 1 | has records => (is => 'rw'); | |
| 64 | has decoder => ( | ||
| 65 | is => 'ro', | ||
| 66 | lazy => 1 , | ||
| 67 | 1 | ▶ | builder => sub { |
|
Subroutine
_build_decoder: called CC=1 SCAR=0.0
| |||
| 68 | 1 | Catmandu::Importer::MARC::Decoder->new; | |
| 69 | 1 | } ); | |
| 70 | |||
| 71 | 1 | ▶ | sub generator { |
|
Subroutine
generator: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 72 | 1 | my ($self) = @_; | |
| 73 | 1 | my @records = @{$self->records}; | |
| 74 | |||
| 75 | sub { | ||
| 76 | $self->decoder->decode(shift @records, $self->id); | ||
| 77 | } | ||
| 78 | 1 | } | |
| 79 | |||
| 80 | |||
| 81 | 1 | 1; | |