| 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
| |||||||||||||||||||||||||||||
| 74 | 30 | ▶ | $opts{'-split'} = 0 unless exists $opts{'-split'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 30 | ▶ | $opts{'-pluck'} = 0 unless exists $opts{'-pluck'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 30 | ▶ | $opts{'-nested_arrays'} = 1 unless exists $opts{'-nested_arrays'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 30 | $opts{'-no-implicit-split'} = 1; | |||||||||||||||||||||||||||
| 78 | 30 | ▶ | $opts{'-force_array'} = 1 if (wantarray); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 30 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 7 | ▶ | defined($vals) && ref($vals) eq 'ARRAY' ? @$vals : ($vals); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $vals and ref $vals eq "ARRAY"
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"
| |||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | else { | ||||||||||||||||||||||||||||
| 91 | 23 | $vals; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 3 | 1; | |||||||||||||||||||||||||||