Fix/marc_in_json.pm

filter: Statementstmt 100% 20 / 20 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 96.4% 27 / 28 CC 2 SCAR 2.9
CC
2
Cov
100%
fix
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« Importer/MARC.pm ↑ Summary Fix/marc_xml.pm »
1 package Catmandu::Fix::marc_in_json;
2  
3 1 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Catmandu::MARC;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Catmandu::Fix::Has;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 with 'Catmandu::Fix::Inlineable';
9  
10 1 our $VERSION = '1.33';
11  
12 1 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 2 ▶sub fix {
Subroutine fix: called CC=2 SCAR=6.9
Pod undocumented
18 2 my ($self, $data) = @_;
19  
20 2 ▶ if ($self->reverse) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->reverse) { } 1 1 2
21 1 return Catmandu::MARC->instance->marc_json_to_record($data);
22 }
23 else {
24 1 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 1;
« Importer/MARC.pm ↑ Summary Fix/marc_xml.pm »