| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Catmandu::Importer::MARC; |
|
2
|
35
|
|
|
35
|
|
2055743
|
use Catmandu::Sane; |
|
|
35
|
|
|
|
|
3462056
|
|
|
|
35
|
|
|
|
|
257
|
|
|
3
|
35
|
|
|
35
|
|
9124
|
use Catmandu::Util; |
|
|
35
|
|
|
|
|
78
|
|
|
|
35
|
|
|
|
|
1357
|
|
|
4
|
35
|
|
|
35
|
|
197
|
use Moo; |
|
|
35
|
|
|
|
|
75
|
|
|
|
35
|
|
|
|
|
194
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.19'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has type => (is => 'ro' , default => sub { 'ISO' }); |
|
9
|
|
|
|
|
|
|
has skip_errors => (is => 'ro'); |
|
10
|
|
|
|
|
|
|
has _importer => (is => 'ro'); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Catmandu::Importer'; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub BUILD { |
|
15
|
41
|
|
|
41
|
0
|
234990
|
my ($self,$args) = @_; |
|
16
|
|
|
|
|
|
|
|
|
17
|
41
|
|
|
|
|
218
|
my $type = $self->type; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# keep USMARC temporary as alias for ISO, remove in future version |
|
20
|
|
|
|
|
|
|
# print deprecation warning |
|
21
|
41
|
100
|
|
|
|
218
|
if ($type eq 'USMARC') { |
|
22
|
1
|
|
|
|
|
2
|
$type = 'ISO'; |
|
23
|
1
|
|
|
|
|
15
|
warn( "deprecated", "Oops! Importer \"USMARC\" is deprecated. Use \"ISO\" instead." ); |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
41
|
100
|
|
|
|
166
|
if (exists $args->{records}) { |
|
27
|
1
|
|
|
|
|
4
|
$type = 'Record'; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
41
|
|
|
|
|
243
|
my $pkg = Catmandu::Util::require_package($type,'Catmandu::Importer::MARC'); |
|
31
|
|
|
|
|
|
|
|
|
32
|
30
|
|
|
|
|
781
|
delete $args->{file}; |
|
33
|
30
|
|
|
|
|
84
|
delete $args->{type}; |
|
34
|
30
|
|
|
|
|
81
|
delete $args->{fix}; |
|
35
|
|
|
|
|
|
|
|
|
36
|
30
|
|
|
|
|
617
|
$self->{_importer} = $pkg->new(file => $self->file, %$args); |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub generator { |
|
40
|
|
|
|
|
|
|
my ($self) = @_; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
if ($self->skip_errors) { |
|
43
|
|
|
|
|
|
|
my $gen = $self->_importer->generator; |
|
44
|
|
|
|
|
|
|
my $nr = 0; |
|
45
|
|
|
|
|
|
|
sub { |
|
46
|
|
|
|
|
|
|
my $item = 0; |
|
47
|
|
|
|
|
|
|
do { |
|
48
|
|
|
|
|
|
|
$nr++; |
|
49
|
|
|
|
|
|
|
try { |
|
50
|
|
|
|
|
|
|
$item = $gen->(); |
|
51
|
|
|
|
|
|
|
} catch { |
|
52
|
|
|
|
|
|
|
$self->log->error("error at record $nr : $_"); |
|
53
|
|
|
|
|
|
|
}; |
|
54
|
|
|
|
|
|
|
} while (defined($item) && $item == 0); |
|
55
|
|
|
|
|
|
|
$item; |
|
56
|
|
|
|
|
|
|
}; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
else { |
|
59
|
|
|
|
|
|
|
$self->_importer->generator; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
|
64
|
|
|
|
|
|
|
__END__ |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 NAME |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Catmandu::Importer::MARC - Package that imports MARC data |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# On the command line |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Convert MARC to JSON (default) |
|
75
|
|
|
|
|
|
|
$ catmandu convert MARC < /foo/bar.mrc |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Convert MARC to MARC |
|
78
|
|
|
|
|
|
|
$ catmandu convert MARC to MARC < /foo/bar.mrc > /foo/output.mrc |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Add fixes |
|
81
|
|
|
|
|
|
|
$ catmandu convert MARC to MARC --fix myfixes.txt < /foo/bar.mrc > /foo/output.mrc |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Create a list of titles |
|
84
|
|
|
|
|
|
|
$ catmandu convert MARC to TSV --fix "marc_map(245,title); retain(title)" < /foo/bar.mrc |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# Convert MARC XML |
|
87
|
|
|
|
|
|
|
$ catmandu convert MARC --type XML < /foo/bar.xml |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# Convert ALEPH sequential |
|
90
|
|
|
|
|
|
|
$ catmandu convert MARC --type ALEPHSEQ < /foo/bar.aleph |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# Convert on format to another format |
|
93
|
|
|
|
|
|
|
$ catmandu convert MARC --type ISO to MARC --type ALEPHSEQ < /foo/bar.mrc > /foo/bar.aleph |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Catmandu::Importer::MARC is a L<Catmandu::Importer> to import MARC records from an |
|
98
|
|
|
|
|
|
|
external source. Each record is imported as HASH containing two keys: |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=over |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item C<_id> |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
the system identifier of the record (usually the 001 field) |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item C<record> |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
an ARRAY of ARRAYs containing the record data |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=back |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 EXAMPLE ITEM |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
{ |
|
115
|
|
|
|
|
|
|
record => [ |
|
116
|
|
|
|
|
|
|
[ |
|
117
|
|
|
|
|
|
|
'001', |
|
118
|
|
|
|
|
|
|
undef, |
|
119
|
|
|
|
|
|
|
undef, |
|
120
|
|
|
|
|
|
|
'_', |
|
121
|
|
|
|
|
|
|
'fol05882032 ' |
|
122
|
|
|
|
|
|
|
], |
|
123
|
|
|
|
|
|
|
[ |
|
124
|
|
|
|
|
|
|
'245', |
|
125
|
|
|
|
|
|
|
'1', |
|
126
|
|
|
|
|
|
|
'0', |
|
127
|
|
|
|
|
|
|
'a', |
|
128
|
|
|
|
|
|
|
'Cross-platform Perl /', |
|
129
|
|
|
|
|
|
|
'c', |
|
130
|
|
|
|
|
|
|
'Eric F. Johnson.' |
|
131
|
|
|
|
|
|
|
], |
|
132
|
|
|
|
|
|
|
], |
|
133
|
|
|
|
|
|
|
_id' => 'fol05882032' |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 METHODS |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
This module inherits all methods of L<Catmandu::Importer> and by this |
|
139
|
|
|
|
|
|
|
L<Catmandu::Iterable>. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=over |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item file |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Read input from a local file given by its path. Alternatively a scalar |
|
148
|
|
|
|
|
|
|
reference can be passed to read from a string. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item fh |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Read input from an L<IO::Handle>. If not specified, L<Catmandu::Util::io> is used to |
|
153
|
|
|
|
|
|
|
create the input stream from the C<file> argument or by using STDIN. |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item fix |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
An ARRAY of one or more fixes or file scripts to be applied to imported items. |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item type |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
The MARC format to parse. The following MARC parsers are available: |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
ISO: L<Catmandu::Importer::MARC::ISO> (default) - a strict ISO 2709 parser |
|
164
|
|
|
|
|
|
|
RAW: L<Catmandu::Importer::MARC::RAW> - a loose ISO 2709 parser that skips faulty records |
|
165
|
|
|
|
|
|
|
ALEPHSEQ: L<Catmandu::Importer::MARC::ALEPHSEQ> - a parser for Ex Libris Aleph sequential files |
|
166
|
|
|
|
|
|
|
Lint: L<Catmandu::Importer::MARC::Lint> - a MARC syntax checker |
|
167
|
|
|
|
|
|
|
MicroLIF: L<Catmandu::Importer::MARC::MicroLIF> - a parser for the MicroLIF format |
|
168
|
|
|
|
|
|
|
MARCMaker: L<Catmandu::Importer::MARC::MARCMaker> - a parser for MARCMaker/MARCBreaker records |
|
169
|
|
|
|
|
|
|
MiJ: L<Catmandu::Importer::MARC::MiJ> (MARC in JSON) - a parser for the MARC-in-JSON format |
|
170
|
|
|
|
|
|
|
XML: L<Catmandu::Importer::MARC::XML> - a parser for the MARC XML format |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item skip_errors |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
If set, then any errors when parsing MARC input will be skipped and ignored. Use the |
|
175
|
|
|
|
|
|
|
debug setting of catmandu to view all error messages: |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
$ catmandu -D convert MARC --skip_errors 1 < /foo/bar.mrc |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item <other> |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Every MARC importer can have its own options. Check the documentation of the specific importer. |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=back |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
L<Catmandu::Exporter::MARC> |