line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Catmandu::Exporter::MARC::MiJ - Exporter for MARC records to MARC in JSON |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# From the command line |
8
|
|
|
|
|
|
|
$ catmandu convert MARC --type XML to MARC --type MiJ < /foo/bar.xml |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# From Perl |
11
|
|
|
|
|
|
|
use Catmandu; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $importer = Catmandu->importer('MARC', file => "/foo/bar.xml" , type => 'XML'); |
14
|
|
|
|
|
|
|
my $exporter = Catmandu->exporter('MARC', file => "bar.json", type => 'MiJ' ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$exporter->add($importer); |
17
|
|
|
|
|
|
|
$exporter->commit; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 CONFIGURATION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=over |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=item file |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Write output to a local file given by its path or file handle. Alternatively a |
26
|
|
|
|
|
|
|
scalar reference can be passed to write to a string and a code reference can be |
27
|
|
|
|
|
|
|
used to write to a callback function. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=item fh |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Write the output to an L<IO::Handle>. If not specified, |
32
|
|
|
|
|
|
|
L<Catmandu::Util::io|Catmandu::Util/IO-functions> is used to create the output |
33
|
|
|
|
|
|
|
handle from the C<file> argument or by using STDOUT. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=item fix |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
An ARRAY of one or more fixes or file scripts to be applied to exported items. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=item encoding |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Binmode of the output stream C<fh>. Set to "C<:utf8>" by default. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=back |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 METHODS |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
See L<Catmandu::Exporter>, L<Catmandu::Addable>, L<Catmandu::Fixable>, |
48
|
|
|
|
|
|
|
L<Catmandu::Counter>, and L<Catmandu::Logger> for a full list of methods. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 FORMAT |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
The MARC-in-JSON record format contains two fields: |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
* 'leader' - the MARC leader |
55
|
|
|
|
|
|
|
* 'fields' - an array of MARC fields |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Each item in the MARC fields array contains the MARC tag and as value a hash |
58
|
|
|
|
|
|
|
containing three fields: |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
* 'subfields' - an array of MARC subfields |
61
|
|
|
|
|
|
|
* 'ind1' - the first indicator of the MARC tag |
62
|
|
|
|
|
|
|
* 'ind2' - the second indicator of the MARC tag |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Each subfield item is an hash containing the MARC subfield tag and its value. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
An example of one MARC record in the MiJ serialization format is given below: |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
{ |
69
|
|
|
|
|
|
|
"leader": "0000cam 2200000 4500", |
70
|
|
|
|
|
|
|
"fields": [ |
71
|
|
|
|
|
|
|
{ |
72
|
|
|
|
|
|
|
"100": { |
73
|
|
|
|
|
|
|
"subfields": [ |
74
|
|
|
|
|
|
|
{ |
75
|
|
|
|
|
|
|
"a": "Huberman, Leo," |
76
|
|
|
|
|
|
|
}, |
77
|
|
|
|
|
|
|
{ |
78
|
|
|
|
|
|
|
"d": "1903-1968." |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
], |
81
|
|
|
|
|
|
|
"ind1": "1", |
82
|
|
|
|
|
|
|
"ind2": " " |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
}, |
85
|
|
|
|
|
|
|
{ |
86
|
|
|
|
|
|
|
"700": { |
87
|
|
|
|
|
|
|
"subfields": [ |
88
|
|
|
|
|
|
|
{ |
89
|
|
|
|
|
|
|
"a": "Sweezy, Paul M." |
90
|
|
|
|
|
|
|
}, |
91
|
|
|
|
|
|
|
{ |
92
|
|
|
|
|
|
|
"q": "(Paul Marlor)," |
93
|
|
|
|
|
|
|
}, |
94
|
|
|
|
|
|
|
{ |
95
|
|
|
|
|
|
|
"d": "1910-2004." |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
], |
98
|
|
|
|
|
|
|
"ind1": "1", |
99
|
|
|
|
|
|
|
"ind2": " " |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
}, |
102
|
|
|
|
|
|
|
... |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 SEE ALSO |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
L<Catmandu::Exporter> |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
110
|
|
|
|
|
|
|
package Catmandu::Exporter::MARC::MiJ; |
111
|
1
|
|
|
1
|
|
6848
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
112
|
1
|
|
|
1
|
|
161
|
use Catmandu::Util qw(xml_escape is_different :array :is); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
250
|
|
113
|
1
|
|
|
1
|
|
6
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
114
|
1
|
|
|
1
|
|
623
|
use MARC::Record; |
|
1
|
|
|
|
|
5088
|
|
|
1
|
|
|
|
|
35
|
|
115
|
1
|
|
|
1
|
|
6
|
use MARC::Field; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
15
|
|
116
|
1
|
|
|
1
|
|
229
|
use MARC::File::MiJ; |
|
1
|
|
|
|
|
9110
|
|
|
1
|
|
|
|
|
220
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
our $VERSION = '1.21'; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
with 'Catmandu::Exporter', 'Catmandu::Exporter::MARC::Base'; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
has record => (is => 'ro' , default => sub { 'record'}); |
123
|
|
|
|
|
|
|
has record_format => (is => 'ro' , default => sub { 'raw'} ); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub add { |
126
|
|
|
|
|
|
|
my ($self, $data) = @_; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
if ($self->record_format eq 'MARC-in-JSON') { |
129
|
|
|
|
|
|
|
$data = $self->_json_to_raw($data); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
my $marc = $self->_raw_to_marc_record($data->{$self->record}); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
$self->fh->print(MARC::File::MiJ::encode($marc) . "\n"); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub commit { |
138
|
|
|
|
|
|
|
my ($self) = @_; |
139
|
|
|
|
|
|
|
$self->fh->flush; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
1; |