line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::marc_in_json; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
875
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
678
|
use Catmandu::MARC; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
5
|
1
|
|
|
1
|
|
7
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
6
|
1
|
|
|
1
|
|
599
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
848
|
|
|
1
|
|
|
|
|
8
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
with 'Catmandu::Fix::Inlineable'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.21'; |
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
|
17220
|
my ($self, $data) = @_; |
19
|
|
|
|
|
|
|
|
20
|
2
|
100
|
|
|
|
15
|
if ($self->reverse) { |
21
|
1
|
|
|
|
|
8
|
return Catmandu::MARC->instance->marc_json_to_record($data); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
else { |
24
|
1
|
|
|
|
|
10
|
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; |