line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::marc_in_json; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
698
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
4
|
1
|
|
|
1
|
|
533
|
use Catmandu::MARC; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
5
|
1
|
|
|
1
|
|
8
|
use Moo; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
6
|
1
|
|
|
1
|
|
521
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
838
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
with 'Catmandu::Fix::Inlineable'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.20'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has reverse => (fix_opt => 1); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Transform a raw MARC array into MARC-in-JSON |
15
|
|
|
|
|
|
|
# See Ross Singer work at: |
16
|
|
|
|
|
|
|
# http://dilettantes.code4lib.org/blog/2010/09/a-proposal-to-serialize-marc-in-json/ |
17
|
|
|
|
|
|
|
sub fix { |
18
|
2
|
|
|
2
|
0
|
17357
|
my ($self, $data) = @_; |
19
|
|
|
|
|
|
|
|
20
|
2
|
100
|
|
|
|
14
|
if ($self->reverse) { |
21
|
1
|
|
|
|
|
5
|
return Catmandu::MARC->instance->marc_json_to_record($data); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
else { |
24
|
1
|
|
|
|
|
9
|
return Catmandu::MARC->instance->marc_record_to_json($data); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 NAME |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Catmandu::Fix::marc_in_json - transform a Catmandu MARC record into MARC-in-JSON |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 SYNOPSIS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Transform a Catmandu MARC 'record' into a MARC-in-JSON record |
35
|
|
|
|
|
|
|
marc_in_json() |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Reverse, transform a MARC-in-JSON record into a Catmandu MARC record |
38
|
|
|
|
|
|
|
marc_in_json(reverse:1) |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 DESCRIPTION |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Convert the MARC record into MARC-in-JSON format |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 METHODS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 marc_in_json( [OPT1:VAL, OPT2: VAL]) |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Convert a Catmandu MARC record into the MARC-in-JSON format. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 OPTIONS |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 reverse: 0|1 |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Convert a MARC-in-JSON record back into the Catmandu MARC format. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 INLINE |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
This Fix can be used inline in a Perl script: |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
use Catmandu::Fix::marc_in_json as => 'marc_in_json'; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $data = { record => [...] }; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$data = marc_in_json($data); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 SEE ALSO |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
L<Catmandu::Fix> |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |