Fix/Inline/marc_map.pm

filter: Statementstmt 100% 21 / 21 Branchbran 93.7% 15 / 16 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 2 / 2 Podpod 0.0% 0 / 1 totaltotal 86.6% 39 / 45 CC 10 SCAR 22.3
CC
10
Cov
92%
marc_map
10.1
BEGIN
1.0
CRAP 9.3
« Importer/MARC/Decoder.pm ↑ Summary Exporter/MARC/XML.pm »
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 ▶use Catmandu::MARC;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 3 require Exporter;
63  
64 3 @ISA = qw(Exporter);
65 3 @EXPORT_OK = qw(marc_map);
66 3 %EXPORT_TAGS = (all => [qw(marc_map)]);
67  
68 3 our $VERSION = '1.33';
69  
70 30 ▶sub marc_map {
Subroutine marc_map: called CC=10 SCAR=23.1
Pod undocumented
71 30 my ($data,$marc_path,%opts) = @_;
72 # Set default to nested_arrays for backwards compatibility
73 30 ▶ $opts{'-join'} = '' unless exists $opts{'-join'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts{"-join"} 29 1 30
74 30 ▶ $opts{'-split'} = 0 unless exists $opts{'-split'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts{"-split"} 24 6 30
75 30 ▶ $opts{'-pluck'} = 0 unless exists $opts{'-pluck'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts{"-pluck"} 27 3 30
76 30 ▶ $opts{'-nested_arrays'} = 1 unless exists $opts{'-nested_arrays'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts{"-nested_arrays"} 29 1 30
77 30 $opts{'-no-implicit-split'} = 1;
78 30 ▶ $opts{'-force_array'} = 1 if (wantarray);
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 7 23 30
79  
80 30 my $vals = Catmandu::MARC->instance->marc_map(
81 $data,
82 $marc_path,
83 \%opts);
84  
85 30 ▶ $vals = $vals->[0] if $opts{'-split'};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"-split"} 6 24 30
86  
87 30 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 7 23 30
88 7 ▶ defined($vals) && ref($vals) eq 'ARRAY' ? @$vals : ($vals);
Branch: 1 branch
BranchTrueFalseTotal
defined $vals && ref $vals eq 'ARRAY' ? : 7 0 7
Condition33%1/3
defined $vals and ref $vals eq "ARRAY"
!ll&&!rl&&r
007
MC/DC0%0/2
defined $vals and ref $vals eq "ARRAY"
defined $vals ref $vals eq "ARRAY"
Truth table33%1/3
A and B
A= defined $valsB= ref $vals eq "ARRAY"
ABresult
0X0
100
111
89 }
90 else {
91 23 $vals;
92 }
93 }
94  
95 3 1;
« Importer/MARC/Decoder.pm ↑ Summary Exporter/MARC/XML.pm »