Debian Codegraph @

lib/Catmandu/Exporter/MARC/MiJ.pm

raw symbols SCIP
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::MiJscip-perl cpan Catmandu-MARC 1.32 Catmandu/Exporter/MARC/MiJ/;
111 use Catmandu::Sanescip-perl cpan Catmandu-MARC 1.32 Catmandu/Sane/;
112 use Catmandu::Utilscip-perl cpan Catmandu-MARC 1.32 Catmandu/Util/ qw(xml_escape is_different :array :is);
113 use Mooscip-perl cpan Catmandu-MARC 1.32 Moo/;
114 use MARC::Recordscip-perl cpan Catmandu-MARC 1.32 MARC/Record/;
115 use MARC::Fieldscip-perl cpan Catmandu-MARC 1.32 MARC/Field/;
116 use MARC::File::MiJscip-perl cpan Catmandu-MARC 1.32 MARC/File/MiJ/;
117
118 our $VERSIONscip-perl cpan Catmandu-MARC 1.32 Catmandu/Exporter/MARC/MiJ/$VERSION. = '1.32';
119
120 withscip-perl cpan Catmandu-MARC 1.32 Catmandu/Exporter/MARC/MiJ/with(). 'Catmandu::Exporter', 'Catmandu::Exporter::MARC::Base';
121
122 hasscip-perl cpan Catmandu-MARC 1.32 Catmandu/Exporter/MARC/MiJ/has(). record => (is => 'ro' , default => sub { 'record'});
123 hasscip-perl cpan Catmandu-MARC 1.32 Catmandu/Exporter/MARC/MiJ/has(). record_format => (is => 'ro' , default => sub { 'raw'} );
124
125 sub addscip-perl cpan Catmandu-MARC 1.32 Catmandu/Exporter/MARC/MiJ/add(). {
126 my ($self, $data) = @_scip-perl cpan Catmandu-MARC 1.32 Catmandu/Exporter/MARC/MiJ/`@_`.;
127
128 if ($self->record_formatscip-perl cpan Catmandu-MARC 1.32 Catmandu/Exporter/MARC/MiJ/record_format(). eq 'MARC-in-JSON') {
129 $data = $self->_json_to_rawscip-perl cpan Catmandu-MARC 1.32 Catmandu/Exporter/MARC/MiJ/_json_to_raw().($data);
130 }
131
132 my $marc = $self->_raw_to_marc_recordscip-perl cpan Catmandu-MARC 1.32 Catmandu/Exporter/MARC/MiJ/_raw_to_marc_record().($data->{$self->recordscip-perl cpan Catmandu-MARC 1.32 Catmandu/Exporter/MARC/MiJ/record().});
133
134 my $res = MARC::File::MiJ::encodescip-perl cpan Catmandu-MARC 1.32 MARC/File/MiJ/encode().($marc);
135 utf8::decodescip-perl cpan Catmandu-MARC 1.32 utf8/decode().($res);
136 $self->fhscip-perl cpan Catmandu-MARC 1.32 Catmandu/Exporter/MARC/MiJ/fh().->printscip-perl cpan Catmandu-MARC 1.32 Catmandu/Exporter/MARC/MiJ/print().("$res\n");
137 }
138
139 sub commitscip-perl cpan Catmandu-MARC 1.32 Catmandu/Exporter/MARC/MiJ/commit(). {
140 my ($self) = @_scip-perl cpan Catmandu-MARC 1.32 Catmandu/Exporter/MARC/MiJ/`@_`.;
141 $self->fhscip-perl cpan Catmandu-MARC 1.32 Catmandu/Exporter/MARC/MiJ/fh().->flushscip-perl cpan Catmandu-MARC 1.32 Catmandu/Exporter/MARC/MiJ/flush().;
142
143 1;
144 }
145
146 1;