/
marc_map.pm
89 lines (64 loc) · 2.24 KB
/
marc_map.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
=head1 NAME
Catmandu::Fix::Inline::marc_map - A marc_map-er for Perl scripts (DEPRECATED)
=head1 SYNOPSIS
use Catmandu::Fix::Inline::marc_map qw(:all);
my $title = marc_map($data,'245a');
my @authors = marc_map($data,'100ab');
# Get all 245 in an array
@arr = marc_map($data,'245');
# Or as a string
$str = marc_map($data,'245');
# str joined by a semi-colon
$f245 = marc_map($data, '245', -join , ';');
# Get the 245-$a$b$c subfields ordered as given in the record
$str = marc_map($data,'245abc');
# Get the 245-$c$b$a subfields orders as given in the mapping
$str = marc_map($data,'245cba', -pluck => 1);
# Get the 008 characters 35-35
$str = marc_map($data,'008_/35-35');
# Get all 100 subfields except the digits
$str = marc_map($data,'100^0123456789');
# If the 260c exist set the output to 'OK' (else undef)
$ok = marc_map($data,'260c',-value => 'OK');
# The $data should be a Catmandu-style MARC hash
{ record => [
['field', 'ind1' , 'ind2' , 'subfieldcode or underscore' , 'data' , 'subfield' , 'data' , ...] ,
...
]};
# Example
$data = { record => [
['001' , ' ', ' ' , '_' , 'myrecord-001' ] ,
['020' , ' ', ' ' , 'a' , '978-1449303587' ] ,
['245' , ' ', ' ' , 'a' , 'Learning Per' , 'c', '/ by Randal L. Schwartz'],
]};
=head1 DEPRECATED
This module is deprecated. Use the inline functionality of L<Catmandu::Fix::marc_map> instead.
=head1 SEE ALSO
L<Catmandu::Fix::Inline::marc_map>
=cut
package Catmandu::Fix::Inline::marc_map;
use Catmandu::MARC;
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw(marc_map);
%EXPORT_TAGS = (all => [qw(marc_map)]);
our $VERSION = '1.04';
sub marc_map {
my ($data,$marc_path,%opts) = @_;
# Set default to nested_arrays for backwards compatibility
$opts{'-join'} = '' unless exists $opts{'-join'};
$opts{'-split'} = 0 unless exists $opts{'-split'};
$opts{'-pluck'} = 0 unless exists $opts{'-pluck'};
$opts{'-nested_arrays'} = 1 unless exists $opts{'-nested_arrays'};
my $vals = Catmandu::MARC->instance->marc_map(
$data,
$marc_path,
\%opts);
if (wantarray) {
defined($vals) && ref($vals) eq 'ARRAY' ? @$vals : ($vals);
}
else {
$vals;
}
}
1;