line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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::MiJ; |
52
|
1
|
|
|
1
|
|
638
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
53
|
1
|
|
|
1
|
|
202
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
54
|
1
|
|
|
1
|
|
600
|
use MARC::Record; |
|
1
|
|
|
|
|
5143
|
|
|
1
|
|
|
|
|
40
|
|
55
|
1
|
|
|
1
|
|
305
|
use Catmandu::Importer::MARC::Decoder; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
56
|
1
|
|
|
1
|
|
234
|
use MARC::File::MiJ; |
|
1
|
|
|
|
|
9661
|
|
|
1
|
|
|
|
|
180
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
our $VERSION = '1.21'; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
with 'Catmandu::Importer'; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
has id => (is => 'ro' , default => sub { '001' }); |
63
|
|
|
|
|
|
|
has decoder => ( |
64
|
|
|
|
|
|
|
is => 'ro', |
65
|
|
|
|
|
|
|
lazy => 1 , |
66
|
|
|
|
|
|
|
builder => sub { |
67
|
1
|
|
|
1
|
|
18
|
Catmandu::Importer::MARC::Decoder->new; |
68
|
|
|
|
|
|
|
} ); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub generator { |
71
|
|
|
|
|
|
|
my ($self) = @_; |
72
|
|
|
|
|
|
|
my $file = MARC::File::MiJ->in($self->file); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# MARC::File doesn't provide support for inline files |
75
|
|
|
|
|
|
|
$file = $self->decoder->fake_marc_file($self->fh,'MARC::File::MiJ') unless $file; |
76
|
|
|
|
|
|
|
sub { |
77
|
|
|
|
|
|
|
$self->decoder->decode($file->next(),$self->id); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |