line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
1
|
|
571
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
55
|
1
|
|
|
1
|
|
423
|
use Catmandu::Importer::MARC::Decoder; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
56
|
1
|
|
|
1
|
|
6
|
use Moo; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
our $VERSION = '1.19'; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
with 'Catmandu::Importer'; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
has id => (is => 'ro' , default => sub { '001' }); |
63
|
|
|
|
|
|
|
has records => (is => 'rw'); |
64
|
|
|
|
|
|
|
has decoder => ( |
65
|
|
|
|
|
|
|
is => 'ro', |
66
|
|
|
|
|
|
|
lazy => 1 , |
67
|
|
|
|
|
|
|
builder => sub { |
68
|
1
|
|
|
1
|
|
23
|
Catmandu::Importer::MARC::Decoder->new; |
69
|
|
|
|
|
|
|
} ); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub generator { |
72
|
|
|
|
|
|
|
my ($self) = @_; |
73
|
|
|
|
|
|
|
my @records = @{$self->records}; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub { |
76
|
|
|
|
|
|
|
$self->decoder->decode(shift @records, $self->id); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |