| 1 | package Net::Z3950::FOLIO::MARCHoldings; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 0 | ▶ | sub insertMARCHoldings { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
insertMARCHoldings: not called CC=13 SCAR=52.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 0 | my($rec, $marc, $cfg, $barcode) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 9 | 0 | ▶ | my $marcCfg = $cfg->{marcHoldings} || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$cfg->{'marcHoldings'} || {}
MC/DC0%0/1
$cfg->{'marcHoldings'} || {}
$cfg->{'marcHoldings'}
Truth table0%0/2
A
A= $cfg->{'marcHoldings'}
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 0 | my $holdingsObjects = $rec->holdings($marc); | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | ▶ | for (my $i = 0; $i < @$holdingsObjects; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | my $holdingsMap = _listOfPairs2map($holdingsObjects->[$i]); | |||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | my $itemObjects = $holdingsMap->{circulations}; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | my $marcField; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | if (scalar @$itemObjects == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | # Special case: we have holdings information, but no associated items | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | $marcField = _addSubfields($marcField, $marcCfg, $marcCfg->{holdingsElements}, $holdingsMap); | |||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | my $nitems = 0; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | for (my $j = 0; $j < @$itemObjects; $j++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | my $itemMap = _listOfPairs2map($itemObjects->[$j]); | |||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | next if $marcCfg->{restrictToItem} && $barcode && $itemMap->{itemId} ne $barcode; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$marcCfg->{"restrictToItem"} and $barcode and $itemMap->{"itemId"} ne $barcode
$marcCfg->{"restrictToItem"} and $barcode
MC/DC0%0/3
$marcCfg->{"restrictToItem"} and $barcode and $itemMap->{"itemId"} ne $barcode
$marcCfg->{"restrictToItem"}
$barcode
$itemMap->{"itemId"} ne $barcode
Truth table0%0/4
A and B and C
A= $marcCfg->{"restrictToItem"}B= $barcodeC= $itemMap->{"itemId"} ne $barcode
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | if ($nitems == 0 || $marcCfg->{holdingsInEachItem}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$nitems == 0 or $marcCfg->{"holdingsInEachItem"}
MC/DC0%0/2
$nitems == 0 or $marcCfg->{"holdingsInEachItem"}
$nitems == 0
$marcCfg->{"holdingsInEachItem"}
Truth table0%0/3
A or B
A= $nitems == 0B= $marcCfg->{"holdingsInEachItem"}
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | $marcField = _addSubfields($marcField, $marcCfg, $marcCfg->{holdingsElements}, $holdingsMap) | |||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | $marcField = _addSubfields($marcField, $marcCfg, $marcCfg->{itemElements}, $itemMap); | |||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | $nitems++; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | if ($marcCfg->{fieldPerItem} && $marcField) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$marcCfg->{"fieldPerItem"} and $marcField
MC/DC0%0/2
$marcCfg->{"fieldPerItem"} and $marcField
$marcCfg->{"fieldPerItem"}
$marcField
Truth table0%0/3
A and B
A= $marcCfg->{"fieldPerItem"}B= $marcField
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | $marc->append_fields($marcField); | |||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | $marcField = undef; | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | $marc->append_fields($marcField) if $marcField; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub _listOfPairs2map { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_listOfPairs2map: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my($listOfPairs) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my $map; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | for (my $j = 0; $j < @$listOfPairs; $j++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $keyVal = $listOfPairs->[$j]; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my($key, $val) = @$keyVal; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $map->{$key} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | return $map; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub _addSubfields { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_addSubfields: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my($marcField, $marcCfg, $elementsCfg, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | foreach my $subfield (sort keys %$elementsCfg) { | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | next if $subfield =~ /^#/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my $name = $elementsCfg->{$subfield}; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $val = $data->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 63 | # warn "considering key '$subfield' mapped to '$name' with value '$val'"; | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ($val || (defined $val && "$val" eq '0')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$val or defined $val and "$val" eq 0
defined $val and "$val" eq 0
MC/DC0%0/3
$val or defined $val and "$val" eq 0
$val
defined $val
"$val" eq 0
Truth table0%0/4
A or B and C
A= $valB= defined $valC= "$val" eq 0
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $marcField = _addSubfield($marcField, $marcCfg, $subfield, $val); | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | return $marcField; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub _addSubfield { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_addSubfield: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my($marcField, $marcCfg, $subfield, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ($marcField) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $marcField->add_subfields($subfield, $val); | |||||||||||||||||||||||||||||||||||||||||
| 78 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 79 | # Delayed creation | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $marcField = MARC::Field->new($marcCfg->{field}, @{ $marcCfg->{indicators}}, $subfield, $val); | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | return $marcField; | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | our @EXPORT_OK = qw(insertMARCHoldings); | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||