File Coverage

blib/lib/Catmandu/Fix/Inline/marc_map.pm
Criterion Covered Total %
statement 14 14 100.0
branch 15 16 93.7
condition 1 3 33.3
subroutine 2 2 100.0
pod 0 1 0.0
total 32 36 88.8


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