Exporter/MARC/ISO.pm

filter: Statementstmt 97.1% 34 / 35 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 2 totaltotal 88.6% 47 / 53 CC 4 SCAR 7.3
CC
4
Cov
90%
add
4.5
BEGIN
1.0
BEGIN
1.0
CRAP 2.1
« Exporter/MARC.pm ↑ Summary Importer/MARC.pm »
1 =head1 NAME
2  
3 Catmandu::Exporter::MARC::ISO - Exporter for MARC records to ISO
4  
5 =head1 SYNOPSIS
6  
7 # From the command line
8 $ catmandu convert MARC --type ISO to MARC --type XML < /foo/bar.mrc
9  
10 # From Perl
11 use Catmandu;
12  
13 my $importer = Catmandu->importer('MARC', file => "/foo/bar.mrc" , type => 'ISO');
14 my $exporter = Catmandu->exporter('MARC', file => "/foo/bar.xml", type => 'XML' );
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 SEE ALSO
51  
52 L<Catmandu::Exporter>
53  
54 =cut
55 package Catmandu::Exporter::MARC::ISO;
56 2 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 2 ▶use Catmandu::Util qw(xml_escape is_different :array :is);
Subroutine BEGIN: called CC=1 SCAR=0.0
58 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 2 ▶use MARC::Record;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 2 ▶use MARC::Field;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 2 ▶use MARC::File::USMARC;
Subroutine BEGIN: called CC=1 SCAR=0.0
62  
63 2 our $VERSION = '1.33';
64  
65 2 with 'Catmandu::Exporter', 'Catmandu::Exporter::MARC::Base';
66  
67 2 ▶has record => (is => 'ro' , default => sub { 'record'});
Subroutine __ANON__: called CC=1 SCAR=0.0
68 2 ▶has record_format => (is => 'ro' , default => sub { 'raw'} );
Subroutine __ANON__: called CC=1 SCAR=0.0
69  
70 2 ▶sub add {
Subroutine add: called CC=4 SCAR=15.0
Pod undocumented
71 2 my ($self, $data) = @_;
72  
73 2 ▶ if (keys %$data) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$data) 2 0 2
74 2 ▶ if ($self->record_format eq 'MARC-in-JSON') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->record_format eq "MARC-in-JSON") 0 2 2
75 0 $data = $self->_json_to_raw($data);
76 }
77  
78 2 ▶ if ($data->{$self->record}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$data{$self->record}) 2 0 2
79 2 my $marc = $self->_raw_to_marc_record($data->{$self->record});
80  
81 2 $self->fh->print(MARC::File::USMARC::encode($marc));
82 }
83 }
84 }
85  
86 1 ▶sub commit {
Subroutine commit: called CC=1 SCAR=0.0
Pod undocumented
87 2 my ($self) = @_;
88 2 $self->fh->flush;
89  
90 2 1;
91 }
92  
93 1 1;
« Exporter/MARC.pm ↑ Summary Importer/MARC.pm »