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
|
|
537
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
61
|
1
|
|
|
1
|
|
149
|
use Catmandu::Util qw(xml_escape is_different :array :is); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
222
|
|
62
|
1
|
|
|
1
|
|
6
|
use List::Util; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
43
|
|
63
|
1
|
|
|
1
|
|
5
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
our $VERSION = '1.21'; |
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 (@data < 2) { |
105
|
|
|
|
|
|
|
$self->log->warn("$tag doesn't have any data"); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
if (index($tag,'LDR') == 0) { |
108
|
|
|
|
|
|
|
my $ldr = $data[1]; |
109
|
|
|
|
|
|
|
$ldr =~ s/ /^/og; |
110
|
|
|
|
|
|
|
push @lines , join('', $_id , ' ' , $tag , $ind1 , $ind2 , ' L ', $ldr ); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
elsif (index($tag,'008') == 0) { |
113
|
|
|
|
|
|
|
my $f008 = $data[1]; |
114
|
|
|
|
|
|
|
$f008 =~ s/ /^/og; |
115
|
|
|
|
|
|
|
push @lines , join('', $_id , ' ' , $tag , $ind1 , $ind2 , ' L ', $f008 ); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
elsif (index($tag,'FMT') == 0 || index($tag,'00') == 0) { |
118
|
|
|
|
|
|
|
push @lines , join('', $_id , ' ' , $tag , $ind1 , $ind2 , ' L ', $data[1] ); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
else { |
121
|
|
|
|
|
|
|
my @line = ('', $_id , ' ' , $tag , $ind1 , $ind2 , ' L '); |
122
|
|
|
|
|
|
|
while (@data) { |
123
|
|
|
|
|
|
|
my ($code,$val) = splice(@data, 0, 2); |
124
|
|
|
|
|
|
|
next unless $code =~ /[A-Za-z0-9]/o; |
125
|
|
|
|
|
|
|
next unless is_string($val); |
126
|
|
|
|
|
|
|
$val =~ s{[[:cntrl:]]}{}g; |
127
|
|
|
|
|
|
|
push @line , '$$' , $code , $val; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
push @lines , join('', @line); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
$self->fh->print(join("\n",@lines) , "\n"); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub commit { |
137
|
|
|
|
|
|
|
my $self = shift; |
138
|
|
|
|
|
|
|
$self->fh->flush; |
139
|
|
|
|
|
|
|
1; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |