Simple/XMLOutStream.pm

filter: Statementstmt 96.7% 60 / 62 Branchbran 81.8% 18 / 22 Conditioncond 75.0% 6 / 8 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 100% 10 / 10 Podpod 100% 1 / 1 totaltotal 90.7% 98 / 108 CC 15 SCAR 16.7
CC
15
Cov
91%
_handle_element_start
10.0
_xml_escape
3.3
BEGIN
2.1
CRAP 5.3
« Simple/PullParserStartToken.pm ↑ Summary Simple/TranscodeDumb.pm »
1 package Pod::Simple::XMLOutStream;
2 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 29 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 29 ▶use Pod::Simple ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 29 our $VERSION = '3.48';
7 29 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.2
8 29 our @ISA = ('Pod::Simple');
9 29 ▶ *DEBUG = \&Pod::Simple::DEBUG unless defined &DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless defined &Pod::Simple::XMLOutStream::DEBUG 29 0 29
10 }
11  
12 29 our $ATTR_PAD;
13 29 ▶$ATTR_PAD = "\n" unless defined $ATTR_PAD;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Pod::Simple::XMLOutStream::ATTR_PAD 29 0 29
14 # Don't mess with this unless you know what you're doing.
15  
16 29 our $SORT_ATTRS;
17 29 ▶$SORT_ATTRS = 0 unless defined $SORT_ATTRS;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Pod::Simple::XMLOutStream::SORT_ATTRS 29 0 29
18  
19 469 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
20 469 my $self = shift;
21 469 my $new = $self->SUPER::new(@_);
22 469 ▶ $new->{'output_fh'} ||= *STDOUT{IO};
Condition50%1/2
$new->{"output_fh"} ||= *STDOUT{"IO"}
l!l
0469
MC/DC0%0/1
$new->{"output_fh"} ||= *STDOUT{"IO"}
$new->{"output_fh"}
Truth table50%1/2
A
A= $new->{"output_fh"}
Aresult
11
00
23 469 $new->keep_encoding_directive(1);
24 #$new->accept_codes('VerbatimFormatted');
25 469 return $new;
26 }
27  
28 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29  
30 1870 ▶sub _handle_element_start {
Subroutine _handle_element_start: called CC=10 SCAR=23.0
31 # ($self, $element_name, $attr_hash_r)
32 1870 my $fh = $_[0]{'output_fh'};
33 1870 my($key, $value);
34 1870 DEBUG and print STDERR "++ $_[1]\n";
35 1870 print $fh "<", $_[1];
36 1870 ▶ if($SORT_ATTRS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Pod::Simple::XMLOutStream::SORT_ATTRS) { } 1160 710 1870
37 1160 foreach my $key (sort keys %{$_[2]}) {
38 2043 ▶ unless($key =~ m/^~/s) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($key =~ /^~/s) 1602 441 2043
39 1602 ▶ next if $key eq 'start_line' and $_[0]{'hide_line_numbers'};
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "start_line" and $_[0]{"hide_line_numbers"} 907 695 1602
Condition66%2/3
$key eq "start_line" and $_[0]{"hide_line_numbers"}
!ll&&!rl&&r
6950907
MC/DC50%1/2
$key eq "start_line" and $_[0]{"hide_line_numbers"}
$key eq "start_line" $_[0]{"hide_line_numbers"}
Truth table66%2/3
A and B
A= $key eq "start_line"B= $_[0]{"hide_line_numbers"}
ABresult
0X0
100
111
40 695 _xml_escape($value = $_[2]{$key});
41 695 print $fh $ATTR_PAD, $key, '="', $value, '"';
42 }
43 }
44 } else { # faster
45 710 ▶ while(($key,$value) = each %{$_[2]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$_[2];}) 834 710 1544
46 834 ▶ unless($key =~ m/^~/s) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($key =~ /^~/s) 764 70 834
47 764 ▶ next if $key eq 'start_line' and $_[0]{'hide_line_numbers'};
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "start_line" and $_[0]{"hide_line_numbers"} 567 197 764
Condition100%3/3
$key eq "start_line" and $_[0]{"hide_line_numbers"}
!ll&&!rl&&r
18215567
MC/DC100%2/2
$key eq "start_line" and $_[0]{"hide_line_numbers"}
$key eq "start_line" $_[0]{"hide_line_numbers"}
Truth table100%3/3
A and B
A= $key eq "start_line"B= $_[0]{"hide_line_numbers"}
ABresult
0X0
100
111
48 197 _xml_escape($value);
49 197 print $fh $ATTR_PAD, $key, '="', $value, '"';
50 }
51 }
52 }
53 1870 print $fh ">";
54 1870 return;
55 }
56  
57 1278 ▶sub _handle_text {
Subroutine _handle_text: called CC=2 SCAR=6.9
58 1278 DEBUG and print STDERR "== \"$_[1]\"\n";
59 1278 ▶ if(length $_[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $_[1]) 1267 11 1278
60 1267 my $text = $_[1];
61 1267 _xml_escape($text);
62 1267 print {$_[0]{'output_fh'}} $text;
63 }
64 1278 return;
65 }
66  
67 1870 ▶sub _handle_element_end {
Subroutine _handle_element_end: called CC=1 SCAR=0.0
68 1870 DEBUG and print STDERR "-- $_[1]\n";
69 1870 print {$_[0]{'output_fh'}} "</", $_[1], ">";
70 1870 return;
71 }
72  
73 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
74 #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
75  
76 2159 ▶sub _xml_escape {
Subroutine _xml_escape: called CC=3 SCAR=12.0
77 2159 foreach my $x (@_) {
78 # Escape things very cautiously:
79 2159 ▶ if ("$]" >= 5.007_003) {
Branch: 1 branch
BranchTrueFalseTotal
if ("$]" >= 5.007003) { } 2159 0 2159
80 2159 $x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(utf8::native_to_unicode(ord($1))).';'/eg;
81 } else { # Is broken for non-ASCII platforms on early perls
82 0 $x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(ord($1)).';'/eg;
83 }
84 # Yes, stipulate the list without a range, so that this can work right on
85 # all charsets that this module happens to run under.
86 }
87 2159 return;
88 }
89  
90 #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
91 29 1;
92  
93 __END__
« Simple/PullParserStartToken.pm ↑ Summary Simple/TranscodeDumb.pm »