| 1 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | Catmandu::Exporter::MARC::Line - Exporter for MARC records to Index Data's MARC Line format | ||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | # From the command line | ||||||||||||||||||||||||||||||||
| 8 | $ catmandu convert MARC to MARC --type Line < t/camel.mrc | ||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | # From Perl | ||||||||||||||||||||||||||||||||
| 11 | use Catmandu; | ||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | my $importer = Catmandu->importer('MARC', file => "t/camel.mrc", type => 'ISO'); | ||||||||||||||||||||||||||||||||
| 14 | my $exporter = Catmandu->exporter('MARC', file => "camel.line", type => 'Line' ); | ||||||||||||||||||||||||||||||||
| 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 AUTHOR | ||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | Johann Rolschewski, E<lt>jorol at cpanE<gt> | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | L<Catmandu::Exporter> | ||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | =cut | ||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | package Catmandu::Exporter::MARC::Line; | ||||||||||||||||||||||||||||||||
| 61 | 1 | ▶ | use Catmandu::Sane; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 1 | our $VERSION = '1.33'; | |||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||
| 66 | 1 | with 'Catmandu::Exporter', 'Catmandu::Exporter::MARC::Base'; | |||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 2 | ▶ | has record => (is => 'ro', default => sub {'record'}); | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 69 | 2 | ▶ | has record_format => (is => 'ro', default => sub {'raw'}); | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | 11 | ▶ | sub add { | ||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=16 SCAR=28.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 72 | 11 | my ($self, $data) = @_; | |||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | 11 | ▶ | if ($self->record_format eq 'MARC-in-JSON') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 75 | 0 | $data = $self->_json_to_raw($data); | |||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | 11 | for my $field (@{$data->{record}}) { | |||||||||||||||||||||||||||||||
| 79 | 192 | my ($field, $ind1, $ind2, @sf) = @$field; | |||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | 192 | ▶ | if (!defined($ind1) || $ind1 =~ /^\s*$/) {$ind1 = ' '} | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $ind1 or $ind1 =~ /^\s*$/
MC/DC50%1/2
not defined $ind1 or $ind1 =~ /^\s*$/
not defined $ind1
$ind1 =~ /^\s*$/
Truth table66%2/3
not(A) or B
A= not defined $ind1B= $ind1 =~ /^\s*$/
| |||||||||||||||||||||||||||||||||
| 82 | 192 | ▶ | if (!defined($ind2) || $ind2 =~ /^\s*$/) {$ind2 = ' '} | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $ind2 or $ind2 =~ /^\s*$/
MC/DC50%1/2
not defined $ind2 or $ind2 =~ /^\s*$/
not defined $ind2
$ind2 =~ /^\s*$/
Truth table66%2/3
not(A) or B
A= not defined $ind2B= $ind2 =~ /^\s*$/
| |||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | 192 | ▶ | next unless ($field =~ /^(LDR|\d{3})/); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 192 | my @sf_map = (); | |||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | 192 | ▶ | for (my $i = 0; $i < @sf; $i += 2) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 89 | 273 | ▶ | if ($field eq 'LDR' || $field < 10) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$field eq "LDR" or $field < 10
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
| |||||||||||||||||||||||||||||||||
| 90 | 53 | ▶ | push @sf_map, $sf[$i + 1] if (defined($sf[$i + 1])); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||
| 92 | else { | ||||||||||||||||||||||||||||||||
| 93 | 220 | ▶ | push @sf_map, '$' . $sf[$i], $sf[$i + 1] | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 94 | if (defined($sf[$i + 1])); | ||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | 192 | my $sf_str = join(" ", @sf_map); | |||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | 192 | my $line; | |||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | 192 | ▶ | if ($field =~ /^\d{3}$/ && $field >= 10) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$field =~ /^\d{3}$/ and $field >= 10
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
| |||||||||||||||||||||||||||||||||
| 103 | 139 | $line = "$field $ind1$ind2 $sf_str\n"; | |||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||
| 105 | elsif ($field eq 'LDR') { | ||||||||||||||||||||||||||||||||
| 106 | 11 | $line = "$sf_str\n"; | |||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||
| 108 | else { | ||||||||||||||||||||||||||||||||
| 109 | 42 | $line = "$field $sf_str\n"; | |||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | 192 | $self->fh->print($line); | |||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | 11 | $self->fh->print("\n"); | |||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | 2 | ▶ | sub commit { | ||||||||||||||||||||||||||||||
|
Subroutine
commit: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 119 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 120 | 2 | $self->fh->flush; | |||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | 2 | 1; | |||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | 1 | 1; | |||||||||||||||||||||||||||||||