XML/Out.pm

filter: Statementstmt 19.1% 14 / 73 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 33.3% 4 / 12 Podpod 66.6% 4 / 6 totaltotal 16.1% 22 / 136 CC 22 SCAR 53.9
CC
22
Cov
12%
element
380.0
_init
6.0
xml_escape
6.0
CRAP 220.2
↑ Summary Include.pm »
1 # BW::XML::Out.pm
2 # Simple XML output
3 #
4 # by Bill Weinman - http://bw.org/
5 # Copyright (c) 1995-2010 The BearHeart Group, LLC
6 #
7 # See POD for History
8 #
9 package BW::XML::Out;
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use BW::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use base qw( BW::Base );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 our $VERSION = "1.4";
17 0 ▶sub version { $VERSION }
Subroutine version: not called CC=1 SCAR=6.9
Pod undocumented
18  
19 sub _init
20 0 ▶{
Subroutine _init: not called CC=2 SCAR=17.9
21 0 my $self = shift;
22 0 $self->SUPER::_init(@_);
23  
24 0 ▶ $self->indent_mul(2) unless $self->{indent_mul}; # default to 2 spaces of indentation
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"indent_mul"} 0 0 0
25  
26 0 return SUCCESS;
27 }
28  
29 # _setter_getter entry points
30 0 ▶sub indent_mul { BW::Base::_setter_getter(@_); }
Subroutine indent_mul: not called CC=1 SCAR=6.9
Pod documented
31 0 ▶sub indent_level { BW::Base::_setter_getter(@_); }
Subroutine indent_level: not called CC=1 SCAR=6.9
Pod documented
32  
33 sub element
34 0 ▶{
Subroutine element: not called CC=19 SCAR=59.4
Pod documented
35 0 my $sn = 'element';
36 0 my ( $self, $element, $content, $options ) = @_;
37 0 my $a = '';
38 0 my $attribs = '';
39 0 my $flags = {};
40 0 ▶ my $indent_level = $self->indent_level() || 0;
Condition0%0/2
$self->indent_level || 0
l!l
00
MC/DC0%0/1
$self->indent_level || 0
$self->indent_level
Truth table0%0/2
A
A= $self->indent_level
Aresult
11
00
41  
42 0 ▶ $options = {} unless $options;
Branch: 1 branch
BranchTrueFalseTotal
unless $options 0 0 0
43  
44 0 ▶ $content = '' unless defined $content;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $content 0 0 0
45 0 ▶ $content = $self->xml_escape($content) if ( $content and not $options->{xmlContent} );
Branch: 1 branch
BranchTrueFalseTotal
if $content and not $options->{"xmlContent"} 0 0 0
Condition0%0/3
$content and not $options->{"xmlContent"}
!ll&&!rl&&r
000
MC/DC0%0/2
$content and not $options->{"xmlContent"}
$content not $options->{"xmlContent"}
Truth table0%0/3
A and not(B)
A= $contentB= not $options->{"xmlContent"}
ABresult
0X0
100
111
46  
47 0 ▶ if ($options) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options) 0 0 0
48 0 ▶ if ( $options->{indentLevel} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"indentLevel"}) 0 0 0
49 0 $indent_level = $options->{indentLevel};
50 }
51 0 ▶ if ( $options->{indent} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"indent"}) 0 0 0
52 0 ++$indent_level;
53 }
54 0 ▶ if ( $options->{startTag} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($options->{'startTag'}) { } 0 0 0
elsif ($options->{'endTag'}) { } 0 0 0
elsif ($options->{'emptyTag'}) { } 0 0 0
55 0 $flags->{start} = TRUE;
56 } elsif ( $options->{endTag} ) {
57 0 $flags->{end} = TRUE;
58 0 --$indent_level;
59 } elsif ( $options->{emptyTag} ) {
60 0 $flags->{empty} = TRUE;
61 }
62  
63 0 ▶ if ( $options->{attribs} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"attribs"}) 0 0 0
64 0 my @ats = @{ $options->{attribs} };
65 0 foreach my $att (@ats) {
66 0 my @att = %$att;
67 0 my $a_lh = $self->xml_escape( $att[0] );
68 0 my $a_rh = $self->xml_escape( $att[1] );
69 0 $attribs .= qq{ ${a_lh}="${a_rh}"};
70 }
71 }
72 }
73  
74 # create the indent
75 0 $a .= ' ' x ( $indent_level * $self->indent_mul() );
76  
77 0 ▶ if ( $flags->{empty} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($flags->{'empty'}) { } 0 0 0
elsif ($flags->{'start'}) { } 0 0 0
elsif ($flags->{'end'}) { } 0 0 0
78 0 $a .= qq{<${element}${attribs} />};
79 } elsif ( $flags->{start} ) {
80 0 $a .= qq{<${element}${attribs}>};
81 } elsif ( $flags->{end} ) {
82 0 $a .= qq{</${element}>};
83 } else {
84 0 $a .= qq{<${element}${attribs}>${content}</${element}>};
85 }
86  
87 # terminate the element with a newline
88 0 ▶ $a .= "\n" unless $options->{noNewline};
Branch: 1 branch
BranchTrueFalseTotal
unless $options->{"noNewline"} 0 0 0
89  
90 0 ▶ if ( $options->{startTag} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"startTag"}) 0 0 0
91 0 ++$indent_level;
92 }
93  
94 # keep the indent level
95 0 $self->indent_level($indent_level);
96  
97 0 return $a;
98 }
99  
100 sub xml_escape
101 0 ▶{
Subroutine xml_escape: not called CC=2 SCAR=17.9
Pod undocumented
102 0 my ( $self, $c ) = @_;
103 0 ▶ return '' unless defined $c;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c 0 0 0
104 0 $c =~ s/&/&amp;/gsm;
105 0 $c =~ s/</&lt;/gsm;
106 0 $c =~ s/>/&gt;/gsm;
107 0 $c =~ s/"/&quot;/g;
108  
109 0 return $c;
110 }
111  
112 # set the error string and return FAILURE
113 sub _error
114 0 ▶{
Subroutine _error: not called CC=2 SCAR=17.9
115 0 my $self = shift;
116 0 ▶ $self->{error} = "$self->{me}: " . ( shift || 'unknown error' );
Condition0%0/2
shift() || 'unknown error'
l!l
00
MC/DC0%0/1
shift() || 'unknown error'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
117 0 return FAILURE;
118 }
119  
120 # get and clear error string
121 sub error
122 0 ▶{
Subroutine error: not called CC=1 SCAR=6.9
Pod documented
123 0 my $self = shift;
124 0 my $errstr = $self->{error};
125 0 $self->{error} = VOID;
126 0 return $errstr;
127 }
128  
129 1 1;
130  
131 __END__
↑ Summary Include.pm »