| 1 | =head1 NAME | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | Catmandu::Exporter::MARC::ALEPHSEQ - Exporter for MARC records to Ex Libris' Aleph sequential | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # From the command line | ||||||||||||||||||||||||||||
| 8 | $ catmandu convert MARC to MARC --type ALEPHSEQ < /foo/data.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 => "marc.txt", type => 'ALEPHSEQ' ); | ||||||||||||||||||||||||||||
| 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 | =item default_fmt | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | Set the value of the default C<FMT> field when none is given. Set to C<BK> by default. | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =back | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =head1 METHODS | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | See L<Catmandu::Exporter>, L<Catmandu::Addable>, L<Catmandu::Fixable>, | ||||||||||||||||||||||||||||
| 52 | L<Catmandu::Counter>, and L<Catmandu::Logger> for a full list of methods. | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | L<Catmandu::Exporter> | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =cut | ||||||||||||||||||||||||||||
| 59 | package Catmandu::Exporter::MARC::ALEPHSEQ; | ||||||||||||||||||||||||||||
| 60 | 1 | ▶ | use Catmandu::Sane; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 61 | 1 | ▶ | use Catmandu::Util qw(xml_escape is_different :array :is); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 62 | 1 | ▶ | use List::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 63 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 1 | our $VERSION = '1.33'; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 1 | with 'Catmandu::Exporter', 'Catmandu::Exporter::MARC::Base'; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 2 | ▶ | has record => (is => 'ro' , default => sub { 'record'}); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 70 | 1 | ▶ | has record_format => (is => 'ro' , default => sub { 'raw'} ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | has skip_empty_subfields => (is => 'ro' , default => sub { 0 }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 72 | 2 | ▶ | has default_fmt => (is => 'ro' , default => sub { 'BK'} ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 2 | ▶ | sub add { | ||||||||||||||||||||||||||
|
Subroutine
add: called CC=19 SCAR=30.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 75 | 2 | my ($self,$data) = @_; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 2 | ▶ | if ($self->record_format eq 'MARC-in-JSON') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 1 | $data = $self->_json_to_raw($data); | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 2 | my $id_str = $data->{_id}; | |||||||||||||||||||||||||||
| 82 | 2 | ▶ | $id_str =~ s{\D}{0}g if defined $id_str; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 2 | ▶ | my $_id = sprintf("%-9.9d", $id_str // 0); | ||||||||||||||||||||||||||
|
Condition50%1/2
$id_str // 0
MC/DC0%0/1
$id_str // 0
$id_str
Truth table50%1/2
A
A= $id_str
| |||||||||||||||||||||||||||||
| 84 | 2 | my $record = $data->{$self->record}; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 2 | my @lines = (); | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | # Check required FMT field | ||||||||||||||||||||||||||||
| 89 | 2 | ▶ | if (@$record > 0 && $record->[0]->[0] ne 'FMT') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@$record > 0 and $record->[0][0] ne "FMT"
MC/DC50%1/2
@$record > 0 and $record->[0][0] ne "FMT"
@$record > 0
$record->[0][0] ne "FMT"
Truth table66%2/3
A and B
A= @$record > 0B= $record->[0][0] ne "FMT"
| |||||||||||||||||||||||||||||
| 90 | 1 | push @lines , join('',$_id, ' ' , 'FMT', ' ', ' ' , ' L ' , $self->default_fmt); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 2 | for my $field (@$record) { | |||||||||||||||||||||||||||
| 94 | 14 | my ($tag,$ind1,$ind2,@data) = @$field; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 14 | ▶ | $ind1 = ' ' unless defined $ind1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 14 | ▶ | $ind2 = ' ' unless defined $ind2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 14 | ▶ | @data = $self->_clean_raw_data($tag,@data) if $self->skip_empty_subfields; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 14 | ▶ | next if $#data == -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | # Joins are faster than perl string concatenation | ||||||||||||||||||||||||||||
| 104 | 14 | ▶ | if (@data < 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 0 | $self->log->warn("$tag doesn't have any data"); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | 14 | ▶ | if (index($tag,'LDR') == 0) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 108 | 2 | my $ldr = $data[1]; | |||||||||||||||||||||||||||
| 109 | 2 | $ldr =~ s/ /^/og; | |||||||||||||||||||||||||||
| 110 | 2 | push @lines , join('', $_id , ' ' , $tag , $ind1 , $ind2 , ' L ', $ldr ); | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | elsif (index($tag,'008') == 0) { | ||||||||||||||||||||||||||||
| 113 | 1 | my $f008 = $data[1]; | |||||||||||||||||||||||||||
| 114 | 1 | $f008 =~ s/ /^/og; | |||||||||||||||||||||||||||
| 115 | 1 | push @lines , join('', $_id , ' ' , $tag , $ind1 , $ind2 , ' L ', $f008 ); | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | ▶ | elsif (index($tag,'FMT') == 0 || index($tag,'00') == 0) { | |||||||||||||||||||||||||||
|
Condition100%3/3
index($tag, "FMT") == 0 or index($tag, "00") == 0
MC/DC100%2/2
index($tag, "FMT") == 0 or index($tag, "00") == 0
index($tag, "FMT") == 0
index($tag, "00") == 0
Truth table100%3/3
A or B
A= index($tag, "FMT") == 0B= index($tag, "00") == 0
| |||||||||||||||||||||||||||||
| 118 | 3 | push @lines , join('', $_id , ' ' , $tag , $ind1 , $ind2 , ' L ', $data[1] ); | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | else { | ||||||||||||||||||||||||||||
| 121 | 8 | my @line = ('', $_id , ' ' , $tag , $ind1 , $ind2 , ' L '); | |||||||||||||||||||||||||||
| 122 | 8 | ▶ | while (@data) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 10 | my ($code,$val) = splice(@data, 0, 2); | |||||||||||||||||||||||||||
| 124 | # some special characters are allowed as subfiled codes in local defined field | ||||||||||||||||||||||||||||
| 125 | # see https://www.loc.gov/marc/96principl.html#eight 8.4.2.3. | ||||||||||||||||||||||||||||
| 126 | 10 | ▶ | next unless $code =~ /[a-z0-9!"#\$%&'\(\)\*\+'-\.\/:;<=>]/o; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 10 | ▶ | next unless is_string($val); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 10 | $val =~ s{[[:cntrl:]]}{}g; | |||||||||||||||||||||||||||
| 129 | 10 | push @line , '$$' , $code , $val; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | 8 | push @lines , join('', @line); | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 2 | $self->fh->print(join("\n",@lines) , "\n"); | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 2 | ▶ | sub commit { | ||||||||||||||||||||||||||
|
Subroutine
commit: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 139 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 140 | 2 | $self->fh->flush; | |||||||||||||||||||||||||||
| 141 | 2 | 1; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 1 | 1; | |||||||||||||||||||||||||||