SubjectMap/XML.pm

filter: Statementstmt 82.8% 29 / 35 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 6 totaltotal 72.2% 39 / 54 CC 3 SCAR 4.4
CC
3
Cov
82%
esc
2.0
emptyElement
2.0
startTag
2.0
CRAP 1.5
« SubjectMap/Rule.pm ↑ Summary SubjectMap/Rules.pm »
1 package MARC::SubjectMap::XML;
2  
3 ## helper functions for xml creation
4 ## internal use only
5  
6 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 10 ▶use base qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 our @EXPORT_OK = qw( element emptyElement esc startTag endTag comment );
11  
12 12 ▶sub element {
Subroutine element: called CC=1 SCAR=0.0
Pod undocumented
13 12 my ($tag,$content,@attrs) = @_;
14 12 return startTag($tag,@attrs).esc($content).endTag($tag);
15 }
16  
17 0 ▶sub emptyElement {
Subroutine emptyElement: not called CC=1 SCAR=6.9
Pod undocumented
18 0 my ($tag,@attrs) = @_;
19 0 my $xml = startTag( $tag,@attrs);
20 0 $xml =~ s{>$}{ />};
21 0 return $xml;
22 }
23  
24 14 ▶sub startTag {
Subroutine startTag: called CC=2 SCAR=6.9
Pod undocumented
25 14 my ($tag,@attrs) = @_;
26 14 my $xml = "<$tag";
27 14 ▶ while ( @attrs ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@attrs) 8 14 22
28 8 my $key = shift(@attrs);
29 8 my $val = esc( shift(@attrs) );
30 8 $xml .= qq( $key="$val");
31 }
32 14 $xml .= ">";
33 14 return $xml;
34 }
35  
36 14 ▶sub endTag {
Subroutine endTag: called CC=1 SCAR=0.0
Pod undocumented
37 14 my $tag = shift;
38 14 return ( "</$tag>" );
39 }
40  
41 27 ▶sub esc {
Subroutine esc: called CC=2 SCAR=7.0
Pod undocumented
42 27 my $str = shift;
43 27 ▶ return "" if ! defined($str);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 0 27 27
44 27 $str =~ s/</&lt;/g;
45 27 $str =~ s/>/&gt;/g;
46 ## be careful not to encode ampersands that are valid entities
47 27 $str =~ s/&(?!(amp|apos|lt|gt);)/&amp;/g;
48 27 return $str;
49 }
50  
51 0 ▶sub comment {
Subroutine comment: not called CC=1 SCAR=6.9
Pod undocumented
52 0 my $str = shift;
53 0 return qq(<!-- $str -->);
54 }
55  
56 10 1;
57  
58  
« SubjectMap/Rule.pm ↑ Summary SubjectMap/Rules.pm »