line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
1
|
|
556
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
61
|
1
|
|
|
1
|
|
186
|
use Catmandu::Util qw(xml_escape is_different :array :is); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
342
|
|
62
|
1
|
|
|
1
|
|
7
|
use List::Util; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
57
|
|
63
|
1
|
|
|
1
|
|
5
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
our $VERSION = '1.19'; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
with 'Catmandu::Exporter', 'Catmandu::Exporter::MARC::Base'; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
has record => (is => 'ro' , default => sub { 'record'}); |
70
|
|
|
|
|
|
|
has record_format => (is => 'ro' , default => sub { 'raw'} ); |
71
|
|
|
|
|
|
|
has skip_empty_subfields => (is => 'ro' , default => sub { 0 }); |
72
|
|
|
|
|
|
|
has default_fmt => (is => 'ro' , default => sub { 'BK'} ); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub add { |
75
|
|
|
|
|
|
|
my ($self,$data) = @_; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
if ($self->record_format eq 'MARC-in-JSON') { |
78
|
|
|
|
|
|
|
$data = $self->_json_to_raw($data); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my $id_str = $data->{_id}; |
82
|
|
|
|
|
|
|
$id_str =~ s{\D}{0}g if defined $id_str; |
83
|
|
|
|
|
|
|
my $_id = sprintf("%-9.9d", $id_str // 0); |
84
|
|
|
|
|
|
|
my $record = $data->{$self->record}; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my @lines = (); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Check required FMT field |
89
|
|
|
|
|
|
|
if (@$record > 0 && $record->[0]->[0] ne 'FMT') { |
90
|
|
|
|
|
|
|
push @lines , join('',$_id, ' ' , 'FMT', ' ', ' ' , ' L ' , $self->default_fmt); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
for my $field (@$record) { |
94
|
|
|
|
|
|
|
my ($tag,$ind1,$ind2,@data) = @$field; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
$ind1 = ' ' unless defined $ind1; |
97
|
|
|
|
|
|
|
$ind2 = ' ' unless defined $ind2; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
@data = $self->_clean_raw_data($tag,@data) if $self->skip_empty_subfields; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
next if $#data == -1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# Joins are faster than perl string concatenation |
104
|
|
|
|
|
|
|
if (index($tag,'LDR') == 0) { |
105
|
|
|
|
|
|
|
my $ldr = $data[1]; |
106
|
|
|
|
|
|
|
$ldr =~ s/ /^/og; |
107
|
|
|
|
|
|
|
push @lines , join('', $_id , ' ' , $tag , $ind1 , $ind2 , ' L ', $ldr ); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
elsif (index($tag,'008') == 0) { |
110
|
|
|
|
|
|
|
my $f008 = $data[1]; |
111
|
|
|
|
|
|
|
$f008 =~ s/ /^/og; |
112
|
|
|
|
|
|
|
push @lines , join('', $_id , ' ' , $tag , $ind1 , $ind2 , ' L ', $f008 ); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
elsif (index($tag,'FMT') == 0 || index($tag,'00') == 0) { |
115
|
|
|
|
|
|
|
push @lines , join('', $_id , ' ' , $tag , $ind1 , $ind2 , ' L ', $data[1] ); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
else { |
118
|
|
|
|
|
|
|
my @line = ('', $_id , ' ' , $tag , $ind1 , $ind2 , ' L '); |
119
|
|
|
|
|
|
|
while (@data) { |
120
|
|
|
|
|
|
|
my ($code,$val) = splice(@data, 0, 2); |
121
|
|
|
|
|
|
|
next unless $code =~ /[A-Za-z0-9]/o; |
122
|
|
|
|
|
|
|
next unless is_string($val); |
123
|
|
|
|
|
|
|
$val =~ s{[[:cntrl:]]}{}g; |
124
|
|
|
|
|
|
|
push @line , '$$' , $code , $val; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
push @lines , join('', @line); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
$self->fh->print(join("\n",@lines) , "\n"); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub commit { |
134
|
|
|
|
|
|
|
my $self = shift; |
135
|
|
|
|
|
|
|
$self->fh->flush; |
136
|
|
|
|
|
|
|
1; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
1; |