Exporter/MARC/MARCMaker.pm

filter: Statementstmt 97.4% 38 / 39 Branchbran 88.8% 16 / 18 Conditioncond 100% 12 / 12 MC/DCmcdc 100% 8 / 8 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 94.1% 80 / 85 CC 15 SCAR 24.5
CC
15
Cov
96%
add
15.0
BEGIN
1.0
BEGIN
1.0
CRAP 11.5
« Exporter/MARC/Line.pm ↑ Summary Importer/MARC/Decoder.pm »
1 =head1 NAME
2  
3 Catmandu::Exporter::MARC::MARCMaker - Exporter for MARC records to USMARC
4  
5 =head1 SYNOPSIS
6  
7 # From the command line
8 $ catmandu convert MARC --type XML to MARC --type MARCMaker < /foo/data.mrc
9  
10 # From Perl
11 use Catmandu;
12  
13 my $importer = Catmandu->importer('MARC', file => "/foo/bar.mrc" , type => 'XML');
14 my $exporter = Catmandu->exporter('MARC', file => "marc.xml", type => 'MARCMaker' );
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::MARCMaker;
56 1 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
58  
59 1 our $VERSION = '1.33';
60  
61 1 with 'Catmandu::Exporter', 'Catmandu::Exporter::MARC::Base';
62  
63 2 ▶has record => (is => 'ro' , default => sub { 'record'});
Subroutine __ANON__: called CC=1 SCAR=0.0
64 2 ▶has record_format => (is => 'ro' , default => sub { 'raw'} );
Subroutine __ANON__: called CC=1 SCAR=0.0
65  
66 2 ▶sub add {
Subroutine add: called CC=15 SCAR=27.1
Pod undocumented
67 2 my ($self, $data) = @_;
68  
69 2 ▶ if ($self->record_format eq 'MARC-in-JSON') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->record_format eq "MARC-in-JSON") 0 2 2
70 0 $data = $self->_json_to_raw($data);
71 }
72  
73 2 for my $field (@{$data->{record}}) {
74 34 my ($field,$ind1,$ind2,@sf) = @$field;
75  
76 34 ▶ if (!defined($ind1) || $ind1 =~ /^\s*$/) { $ind1 = '/'}
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $ind1 or $ind1 =~ /^\s*$/) 26 8 34
Condition100%3/3
not defined $ind1 or $ind1 =~ /^\s*$/
l!l&&r!l&&!r
2248
MC/DC100%2/2
not defined $ind1 or $ind1 =~ /^\s*$/
not defined $ind1 $ind1 =~ /^\s*$/
Truth table100%3/3
not(A) or B
A= not defined $ind1B= $ind1 =~ /^\s*$/
ABresult
1X1
011
000
77 34 ▶ if (!defined($ind2) || $ind2 =~ /^\s*$/) { $ind2 = '/'}
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $ind2 or $ind2 =~ /^\s*$/) 27 7 34
Condition100%3/3
not defined $ind2 or $ind2 =~ /^\s*$/
l!l&&r!l&&!r
2257
MC/DC100%2/2
not defined $ind2 or $ind2 =~ /^\s*$/
not defined $ind2 $ind2 =~ /^\s*$/
Truth table100%3/3
not(A) or B
A= not defined $ind2B= $ind2 =~ /^\s*$/
ABresult
1X1
011
000
78  
79 34 ▶ next unless ($field =~ /^(LDR|\d{3})/);
Branch: 1 branch
BranchTrueFalseTotal
unless $field =~ /^(LDR|\d{3})/ 2 32 34
80  
81 32 my @sf_map = ();
82  
83 32 ▶ for (my $i = 0 ; $i < @sf ; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @sf) 48 32 80
84 48 ▶ if ($field eq 'LDR' || $field < 10) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field eq 'LDR' or $field < 10) { } 8 40 48
Condition100%3/3
$field eq "LDR" or $field < 10
l!l&&r!l&&!r
1740
MC/DC100%2/2
$field eq "LDR" or $field < 10
$field eq "LDR" $field < 10
Truth table100%3/3
A or B
A= $field eq "LDR"B= $field < 10
ABresult
1X1
011
000
85 8 ▶ push @sf_map , $sf[$i+1] if (defined($sf[$i+1]));
Branch: 1 branch
BranchTrueFalseTotal
if defined $sf[$i + 1] 8 0 8
86 }
87 else {
88 40 ▶ push @sf_map
Branch: 1 branch
BranchTrueFalseTotal
if defined $sf[$i + 1] 38 2 40
89 , "\$" . $sf[$i]
90 , $sf[$i+1] if (defined($sf[$i+1]));
91 }
92 }
93  
94 32 my $sf_str = join("",@sf_map);
95  
96 32 my $maker_field;
97  
98 32 ▶ if ($field =~ /^\d{3}$/ && $field >= 10) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /^\d{3}$/ and $field >= 10) { } 24 8 32
Condition100%3/3
$field =~ /^\d{3}$/ and $field >= 10
!ll&&!rl&&r
1724
MC/DC100%2/2
$field =~ /^\d{3}$/ and $field >= 10
$field =~ /^\d{3}$/ $field >= 10
Truth table100%3/3
A and B
A= $field =~ /^\d{3}$/B= $field >= 10
ABresult
0X0
100
111
99 24 $maker_field = "=$field $ind1$ind2$sf_str\n";
100 }
101 else {
102 8 $maker_field = "=$field $sf_str\n";
103 }
104  
105 32 $self->fh->print($maker_field);
106 }
107  
108 2 $self->fh->print("\n");
109 }
110  
111 2 ▶sub commit {
Subroutine commit: called CC=1 SCAR=0.0
Pod undocumented
112 2 my ($self) = @_;
113 2 $self->fh->flush;
114  
115 2 1;
116 }
117  
118 1 1;
« Exporter/MARC/Line.pm ↑ Summary Importer/MARC/Decoder.pm »