| 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
| |||||||||||||||||||||||||||||
| 31 | 15 | push @res, $node; | |||||||||||||||||||||||||||
| 32 | 15 | next; | |||||||||||||||||||||||||||
| 33 | }; | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 10 | ▶ | $node->{_tag} =~ /\~pi/ and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 1 | push @res, "<?$node->{text}?>"; | |||||||||||||||||||||||||||
| 37 | 1 | next; | |||||||||||||||||||||||||||
| 38 | }; | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 9 | ▶ | $node->{_tag} =~ /\~declaration/ and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 1 | push @res, "<!$node->{text}>"; | |||||||||||||||||||||||||||
| 42 | 1 | next; | |||||||||||||||||||||||||||
| 43 | }; | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 8 | ▶ | $node->{_tag} =~ /\~comment/ and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$open and $close
MC/DC50%1/2
$open and $close
$open
$close
Truth table66%2/3
A and B
A= $openB= $close
| |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ($attr) { push @res, "<$tag $attr />" } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 1 | else { push @res, "<$tag />" } | |||||||||||||||||||||||||||
| 59 | 1 | next; | |||||||||||||||||||||||||||
| 60 | }; | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 6 | ▶ | my $open_tag = $attr ? "<$tag $attr>" : "<$tag>"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 6 | my $close_tag = "</$tag>"; | |||||||||||||||||||||||||||
| 64 | 6 | ▶ | my @desc = $node->{_content} ? @{$node->{_content}} : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 1 | $res =~ s/\"/\"\;/g; | |||||||||||||||||||||||||||
| 81 | 1 | return $res; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 1 | 1; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | __END__ | ||||||||||||||||||||||||||||