lib/MKDoc/XML/TreePrinter.pm

filter: Statementstmt 97.9% 47 / 48 Branchbran 83.3% 15 / 18 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 90.7% 69 / 76 CC 12 SCAR 21.4
CC
12
Cov
93%
process
11.0
_encode_quot
2.0
BEGIN
1.0
CRAP 8.5
« lib/MKDoc/XML/Decode/Numeric.pm ↑ Summary lib/MKDoc/XML/Dumper.pm »
1 # -------------------------------------------------------------------------------------
2 # MKDoc::XML::TreePrinter
3 # -------------------------------------------------------------------------------------
4 # Author : Jean-Michel Hiver.
5 # Copyright : (c) MKDoc Holdings Ltd, 2003
6 #
7 # This module is the counterpart of MKDoc::XML::TreePrinter. It turns an XML
8 # tree back into a string.
9 #
10 # This module is distributed under the same license as Perl itself.
11 # -------------------------------------------------------------------------------------
12 package MKDoc::XML::TreePrinter;
13 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 ##
18 # $class->process (@nodes);
19 # ----------------------------
20 # Does the stuff.
21 ##
22 sub process
23 7 ▶{
Subroutine process: called CC=11 SCAR=24.0
Pod undocumented
24 7 my $class = shift;
25 7 my @nodes = @_;
26 7 my @res = ();
27
28 7 foreach my $node (@nodes)
29 {
30 25 ▶ ref $node or do {
Branch: 1 branch
BranchTrueFalseTotal
ref $node or do { push @res, $node; next } 10 15 25
31 15 push @res, $node;
32 15 next;
33 };
34  
35 10 ▶ $node->{_tag} =~ /\~pi/ and do {
Branch: 1 branch
BranchTrueFalseTotal
$node->{"_tag"} =~ /\~pi/ and do { push @res, qq[<?$node->{"text"}?>]; next } 1 9 10
36 1 push @res, "<?$node->{text}?>";
37 1 next;
38 };
39  
40 9 ▶ $node->{_tag} =~ /\~declaration/ and do {
Branch: 1 branch
BranchTrueFalseTotal
$node->{"_tag"} =~ /\~declaration/ and do { push @res, qq[<!$node->{"text"}>]; next } 1 8 9
41 1 push @res, "<!$node->{text}>";
42 1 next;
43 };
44  
45 8 ▶ $node->{_tag} =~ /\~comment/ and do {
Branch: 1 branch
BranchTrueFalseTotal
$node->{"_tag"} =~ /\~comment/ and do { push @res, '<!--' . $node->{"text"} . '-->'; next } 1 7 8
46 1 push @res, "<!--" . $node->{text} . "-->";
47 1 next;
48 };
49  
50 7 my $tag = $node->{_tag};
51 7 my %att = map { $_ => _encode_quot ($node->{$_}) } grep !/^_/, keys %{$node};
52 7 my $attr = join " ", map { "$_=\"$att{$_}\"" } keys %att;
53 7 my $open = $node->{_open};
54 7 my $close = $node->{_close};
55
56 7 ▶ $open && $close && do {
Branch: 1 branch
BranchTrueFalseTotal
$open and $close and do { if ($attr) { push @res, "<$tag $attr />"; } else { push @res, "<$tag />"; } ; next } 1 6 7
Condition66%2/3
$open and $close
!ll&&!rl&&r
061
MC/DC50%1/2
$open and $close
$open $close
Truth table66%2/3
A and B
A= $openB= $close
ABresult
0X0
100
111
57 0 ▶ if ($attr) { push @res, "<$tag $attr />" }
Branch: 1 branch
BranchTrueFalseTotal
if ($attr) { } 0 1 1
58 1 else { push @res, "<$tag />" }
59 1 next;
60 };
61
62 6 ▶ my $open_tag = $attr ? "<$tag $attr>" : "<$tag>";
Branch: 1 branch
BranchTrueFalseTotal
$attr ? : 1 5 6
63 6 my $close_tag = "</$tag>";
64 6 ▶ my @desc = $node->{_content} ? @{$node->{_content}} : ();
Branch: 1 branch
BranchTrueFalseTotal
$node->{'_content'} ? : 6 0 6
65
66 6 my $res = $open_tag . $class->process (@desc) . $close_tag;
67 6 push @res, $res;
68 6 next;
69 };
70  
71 7 return join '', @res;
72 }
73  
74  
75 sub _encode_quot
76 1 ▶{
Subroutine _encode_quot: called CC=2 SCAR=7.0
77 1 my $res = shift;
78 1 ▶ return '' unless (defined $res);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res 0 1 1
79  
80 1 $res =~ s/\"/\&quot\;/g;
81 1 return $res;
82 }
83  
84  
85 1 1;
86  
87  
88 __END__
« lib/MKDoc/XML/Decode/Numeric.pm ↑ Summary lib/MKDoc/XML/Dumper.pm »