Net/Z3950/FOLIO/OPACXMLRecord.pm

filter: Statementstmt 28.8% 17 / 59 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 62.5% 5 / 8 Podpod 0.0% 0 / 1 totaltotal 24.4% 22 / 90 CC 12 SCAR 31.1
CC
12
Cov
22%
_makeXMLElement
42.0
_resolveHoldingsToXML
30.0
_quoteXML
6.0
CRAP 22.4
« Net/Z3950/FOLIO/HoldingsRecords.pm ↑ Summary Net/Z3950/FOLIO/Record.pm »
1 package Net::Z3950::FOLIO::OPACXMLRecord;
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 1 ▶use Net::Z3950::FOLIO::PostProcess::OPAC qw(postProcessHoldings);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 1 ▶sub makeOPACXMLRecord {
Subroutine makeOPACXMLRecord: called CC=2 SCAR=12.6
Pod undocumented
11 1 my($rec) = @_;
12 1 my $marc = $rec->marcRecord();
13 1 my $marcXML = $marc->as_xml_record();
14  
15 # The first line of $marcXML is an XML declaration, and there
16 # seems to be no way to have MARC::File::XML omit this, so we just
17 # snip it off.
18 0 $marcXML =~ s/.*?\n//m;
19  
20 # Indent to fit into the record nicely
21 0 $marcXML =~ s/^/ /gm;
22  
23 0 my $holdingsObjects = $rec->holdings($marc);
24 0 ▶ $holdingsObjects = postProcessHoldings(($rec->rs()->session()->{cfg}->{postProcessing} || {})->{opac}, $holdingsObjects);
Condition0%0/2
$rec->rs->session->{'cfg'}{'postProcessing'} || {}
l!l
00
MC/DC0%0/1
$rec->rs->session->{'cfg'}{'postProcessing'} || {}
$rec->rs->session->{'cfg'}{'postProcessing'}
Truth table0%0/2
A
A= $rec->rs->session->{'cfg'}{'postProcessing'}
Aresult
11
00
25 0 my $holdingsRecords = _resolveHoldingsToXML($holdingsObjects);
26  
27 0 return _makeXMLElement(0, 'opacRecord', (
28 [ 'bibliographicRecord', $marcXML, undef, 1 ],
29 [ 'holdings', $holdingsRecords, undef, 1 ],
30 ));
31 }
32  
33  
34 0 ▶sub _resolveHoldingsToXML {
Subroutine _resolveHoldingsToXML: not called CC=5 SCAR=34.0
35 0 my($holdingsObjects) = @_;
36  
37 0 foreach my $holding (@$holdingsObjects) {
38 0 ▶ for (my $i = 0; $i < @$holding; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$holding) 0 0 0
39 0 my $elem = $holding->[$i];
40 0 my($name, $value) = @$elem;
41 0 ▶ if ($name eq 'circulations') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "circulations") 0 0 0
42 0 my @acc;
43 0 ▶ for (my $j = 0; $j < @$value; $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < @$value) 0 0 0
44 0 my $circulation = $value->[$j];
45 0 push @acc, _makeXMLElement(8, 'circulation', @$circulation);
46 }
47 # XXX I am not ecstatic about overwriting this in place
48 0 $elem->[1] = join('', @acc);
49 }
50 }
51 }
52  
53 0 my @holdingsXML = map { _makeXMLElement(4, 'holding', @$_) } @$holdingsObjects;
54 0 return join('', @holdingsXML);
55 }
56  
57  
58 0 ▶sub _makeXMLElement {
Subroutine _makeXMLElement: not called CC=6 SCAR=37.4
59 0 my($indentLevel, $elementName, @elements) = @_;
60  
61 0 my $indent = ' ' x $indentLevel;
62 0 my $xml = "$indent<$elementName>\n";
63 0 foreach my $element (@elements) {
64 0 my($name, $value, $attr, $isPreAssembledXML) = @$element;
65 0 ▶ next if $name =~ /^_/ || !defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /^_/ or not defined $value 0 0 0
Condition0%0/3
$name =~ /^_/ or not defined $value
l!l&&r!l&&!r
000
MC/DC0%0/2
$name =~ /^_/ or not defined $value
$name =~ /^_/ not defined $value
Truth table0%0/3
A or not(B)
A= $name =~ /^_/B= not defined $value
ABresult
1X1
011
000
66  
67 0 my $added;
68 0 ▶ if ($attr) {
Branch: 2 branches
BranchTrueFalseTotal
if ($attr) { } 0 0 0
elsif (not $isPreAssembledXML) { } 0 0 0
69 0 my $quotedValue = _quoteXML($value);
70 0 $added = qq[<$name $attr="$quotedValue" />\n];
71 } elsif (!$isPreAssembledXML) {
72 0 my $quotedValue = _quoteXML($value);
73 0 $added = qq[<$name>$quotedValue</$name>\n];
74 } else {
75 0 $added = qq[<$name>\n$value$indent </$name>\n];
76 }
77 # warn "name=$name, value=$value, attr=$attr, added=$added";
78 0 $xml .= "$indent $added";
79 }
80 0 $xml .= "$indent</$elementName>\n";
81 }
82  
83  
84 0 ▶sub _quoteXML {
Subroutine _quoteXML: not called CC=2 SCAR=17.9
85 0 my($s) = @_;
86  
87 0 ▶ return '' if !defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 0 0
88 0 $s =~ s/&/&amp;/sg;
89 0 $s =~ s/</&lt;/sg;
90 0 $s =~ s/>/&gt;/sg;
91 0 $s =~ s/"/&quot;/sg;
92  
93 0 return $s
94 }
95  
96  
97 1 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
98 1 our @EXPORT_OK = qw(makeOPACXMLRecord);
99  
100  
101 1 1;
« Net/Z3950/FOLIO/HoldingsRecords.pm ↑ Summary Net/Z3950/FOLIO/Record.pm »