Net/Z3950/FOLIO/MARCHoldings.pm

filter: Statementstmt 20.7% 11 / 53 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 42.8% 3 / 7 Podpod 0.0% 0 / 1 totaltotal 12.2% 14 / 114 CC 20 SCAR 46.2
CC
20
Cov
12%
insertMARCHoldings
182.0
_addSubfields
42.0
_listOfPairs2map
6.0
CRAP 101.7
« Net/Z3950/FOLIO/RPN.pm ↑ Summary Net/Z3950/FOLIO/Session.pm »
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'} || {}
l!l
00
MC/DC0%0/1
$cfg->{'marcHoldings'} || {}
$cfg->{'marcHoldings'}
Truth table0%0/2
A
A= $cfg->{'marcHoldings'}
Aresult
11
00
10 0 my $holdingsObjects = $rec->holdings($marc);
11  
12 0 ▶ for (my $i = 0; $i < @$holdingsObjects; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$holdingsObjects) 0 0 0
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
BranchTrueFalseTotal
if (scalar @$itemObjects == 0) 0 0 0
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
BranchTrueFalseTotal
if ($j < @$itemObjects) 0 0 0
24 0 my $itemMap = _listOfPairs2map($itemObjects->[$j]);
25 0 ▶ next if $marcCfg->{restrictToItem} && $barcode && $itemMap->{itemId} ne $barcode;
Branch: 1 branch
BranchTrueFalseTotal
if $marcCfg->{"restrictToItem"} and $barcode and $itemMap->{"itemId"} ne $barcode 0 0 0
Condition0%0/6
$marcCfg->{"restrictToItem"} and $barcode and $itemMap->{"itemId"} ne $barcode
!ll&&!rl&&r
000
$marcCfg->{"restrictToItem"} and $barcode
!ll&&!rl&&r
000
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
ABCresult
0XX0
10X0
1100
1111
26 0 ▶ if ($nitems == 0 || $marcCfg->{holdingsInEachItem}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nitems == 0 or $marcCfg->{"holdingsInEachItem"}) 0 0 0
Condition0%0/3
$nitems == 0 or $marcCfg->{"holdingsInEachItem"}
l!l&&r!l&&!r
000
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"}
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if ($marcCfg->{"fieldPerItem"} and $marcField) 0 0 0
Condition0%0/3
$marcCfg->{"fieldPerItem"} and $marcField
!ll&&!rl&&r
000
MC/DC0%0/2
$marcCfg->{"fieldPerItem"} and $marcField
$marcCfg->{"fieldPerItem"} $marcField
Truth table0%0/3
A and B
A= $marcCfg->{"fieldPerItem"}B= $marcField
ABresult
0X0
100
111
32 0 $marc->append_fields($marcField);
33 0 $marcField = undef;
34 }
35 }
36  
37 0 ▶ $marc->append_fields($marcField) if $marcField;
Branch: 1 branch
BranchTrueFalseTotal
if $marcField 0 0 0
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
BranchTrueFalseTotal
if ($j < @$listOfPairs) 0 0 0
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
BranchTrueFalseTotal
if $subfield =~ /^#/ 0 0 0
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
BranchTrueFalseTotal
if ($val or defined $val and "$val" eq 0) 0 0 0
Condition0%0/6
$val or defined $val and "$val" eq 0
l!l&&r!l&&!r
000
defined $val and "$val" eq 0
!ll&&!rl&&r
000
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
ABCresult
1XX1
0111
00X0
0100
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
BranchTrueFalseTotal
if ($marcField) { } 0 0 0
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;
« Net/Z3950/FOLIO/RPN.pm ↑ Summary Net/Z3950/FOLIO/Session.pm »