| 1 | package XML::CompareML::DocBook; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | =head1 NAME | ||||||||||
| 7 | |||||||||||
| 8 | XML::CompareML::DocBook - convert CompareML to DocBook | ||||||||||
| 9 | |||||||||||
| 10 | =head1 SYNOPSIS | ||||||||||
| 11 | |||||||||||
| 12 | See L<XML::CompareXML>. | ||||||||||
| 13 | |||||||||||
| 14 | =cut | ||||||||||
| 15 | |||||||||||
| 16 | 2 | ▶ | use XML::LibXML::Common qw(:w3c); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 2 | ▶ | use base 'XML::CompareML::Base'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | sub _print_header | ||||||||||
| 21 | { | ||||||||||
| 22 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_print_header: not called CC=1 SCAR=6.9
| |||||||||||
| 23 | 0 | my $o = $self->{o}; | |||||||||
| 24 | 0 | print {*{$o}} <<"EOF"; | |||||||||
| 25 | <?xml version="1.0" encoding="iso-8859-1"?> | ||||||||||
| 26 | <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" | ||||||||||
| 27 | "/usr/share/sgml/docbook/xml-dtd-4.1.2/docbookx.dtd"[ | ||||||||||
| 28 | ]> | ||||||||||
| 29 | <article> | ||||||||||
| 30 | |||||||||||
| 31 | EOF | ||||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | # Do Nothing | ||||||||||
| 35 | sub _start_rendering | ||||||||||
| 36 | ▶ | { | |||||||||
|
Subroutine
_start_rendering: not called CC=1 SCAR=0.0
| |||||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | # Do Nothing | ||||||||||
| 40 | sub _finish_rendering | ||||||||||
| 41 | ▶ | { | |||||||||
|
Subroutine
_finish_rendering: not called CC=1 SCAR=0.0
| |||||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | sub _print_footer | ||||||||||
| 45 | { | ||||||||||
| 46 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_print_footer: not called CC=1 SCAR=6.9
| |||||||||||
| 47 | 0 | print {*{$self->{o}}} "</article>\n"; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | sub _render_section_start | ||||||||||
| 51 | { | ||||||||||
| 52 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_render_section_start: not called CC=5 SCAR=34.0
| |||||||||||
| 53 | 0 | my %args = (@_); | |||||||||
| 54 | |||||||||||
| 55 | 0 | my $depth = $args{depth}; | |||||||||
| 56 | 0 | my $id = $args{id}; | |||||||||
| 57 | 0 | my $title_string = $args{title_string}; | |||||||||
| 58 | 0 | my $expl = $args{expl}; | |||||||||
| 59 | 0 | my $sub_sections = $args{sub_sections}; | |||||||||
| 60 | |||||||||||
| 61 | 0 | ▶ | if ($depth) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | { | ||||||||||
| 63 | 0 | $self->_out("<section id=\"$id\">\n"); | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 0 | $self->_out("<title>$title_string</title>\n"); | |||||||||
| 67 | |||||||||||
| 68 | 0 | ▶ | if ($depth == 0) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | { | ||||||||||
| 70 | 0 | ▶ | if (defined($self->_timestamp())) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | { | ||||||||||
| 72 | 0 | $self->_out("<articleinfo><date>" . $self->_timestamp() . | |||||||||
| 73 | "</date></articleinfo>\n"); | ||||||||||
| 74 | } | ||||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 0 | ▶ | if ($expl) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | { | ||||||||||
| 79 | 0 | $self->_out("<para>\n" . $self->_xml_node_contents_to_string($expl) . "\n</para>\n"); | |||||||||
| 80 | } | ||||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | sub _render_sys_table_start | ||||||||||
| 84 | { | ||||||||||
| 85 | 0 | ▶ | my ($self,%args) = @_; | ||||||||
|
Subroutine
_render_sys_table_start: not called CC=1 SCAR=6.9
| |||||||||||
| 86 | |||||||||||
| 87 | 0 | my $title_string = $args{title_string}; | |||||||||
| 88 | |||||||||||
| 89 | 0 | $self->_out(<<"EOF"); | |||||||||
| 90 | <table frame=\"all\"> | ||||||||||
| 91 | <title>Comparison - $title_string</title> | ||||||||||
| 92 | <tgroup cols=\"2\" align=\"left\" colsep=\"1\" rowsep=\"1\"> | ||||||||||
| 93 | <colspec colname=\"system\" /> | ||||||||||
| 94 | <colspec colname=\"description\" /> | ||||||||||
| 95 | <thead> | ||||||||||
| 96 | <row> | ||||||||||
| 97 | <entry><emphasis>System</emphasis></entry> | ||||||||||
| 98 | <entry><emphasis>Description</emphasis></entry> | ||||||||||
| 99 | </row> | ||||||||||
| 100 | </thead> | ||||||||||
| 101 | <tbody> | ||||||||||
| 102 | EOF | ||||||||||
| 103 | } | ||||||||||
| 104 | |||||||||||
| 105 | sub _html_to_docbook | ||||||||||
| 106 | { | ||||||||||
| 107 | 0 | ▶ | my $parent_node = shift; | ||||||||
|
Subroutine
_html_to_docbook: not called CC=5 SCAR=34.0
| |||||||||||
| 108 | 0 | my $not_first = shift; | |||||||||
| 109 | 0 | my @child_nodes = $parent_node->childNodes(); | |||||||||
| 110 | 0 | my $ret = ""; | |||||||||
| 111 | |||||||||||
| 112 | 0 | foreach my $node (@child_nodes) | |||||||||
| 113 | { | ||||||||||
| 114 | 0 | ▶ | if ($node->nodeType() == ELEMENT_NODE()) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 115 | { | ||||||||||
| 116 | 0 | ▶ | if ($node->nodeName() eq "a") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 117 | { | ||||||||||
| 118 | 0 | $ret .= "<ulink url=\"" . $node->getAttribute("href") . "\">"; | |||||||||
| 119 | } | ||||||||||
| 120 | else | ||||||||||
| 121 | { | ||||||||||
| 122 | 0 | my @attrs = $node->attributes(); | |||||||||
| 123 | 0 | $ret .= "<" . $node->nodeName() . " " . join(" ", map { "$_=\"".$node->getAttribute($_)."\""} @attrs) . ">"; | |||||||||
| 124 | } | ||||||||||
| 125 | 0 | $ret .= _html_to_docbook($node, 1); | |||||||||
| 126 | |||||||||||
| 127 | 0 | ▶ | if ($node->nodeName() eq "a") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 128 | { | ||||||||||
| 129 | 0 | $ret .= "</ulink>"; | |||||||||
| 130 | } | ||||||||||
| 131 | else | ||||||||||
| 132 | { | ||||||||||
| 133 | 0 | $ret .= "</" . $node->nodeName() . ">"; | |||||||||
| 134 | } | ||||||||||
| 135 | } | ||||||||||
| 136 | else | ||||||||||
| 137 | { | ||||||||||
| 138 | 0 | $ret .= $node->toString(); | |||||||||
| 139 | } | ||||||||||
| 140 | } | ||||||||||
| 141 | # Remove leading and trailing space. | ||||||||||
| 142 | 0 | if (1) | |||||||||
| 143 | { | ||||||||||
| 144 | 0 | $ret =~ s!^\s+!!mg; | |||||||||
| 145 | 0 | $ret =~ s/\s+$//mg; | |||||||||
| 146 | } | ||||||||||
| 147 | 0 | return $ret; | |||||||||
| 148 | } | ||||||||||
| 149 | |||||||||||
| 150 | sub _render_s_elem | ||||||||||
| 151 | { | ||||||||||
| 152 | 0 | ▶ | my ($self, $s_elem) = @_; | ||||||||
|
Subroutine
_render_s_elem: not called CC=1 SCAR=6.9
| |||||||||||
| 153 | 0 | return _html_to_docbook($s_elem); | |||||||||
| 154 | } | ||||||||||
| 155 | |||||||||||
| 156 | sub _render_sys_table_row | ||||||||||
| 157 | { | ||||||||||
| 158 | 0 | ▶ | my ($self, %args) = @_; | ||||||||
|
Subroutine
_render_sys_table_row: not called CC=1 SCAR=6.9
| |||||||||||
| 159 | |||||||||||
| 160 | $self->_out("<row>\n<entry>" . $args{name}. "</entry>\n" . | ||||||||||
| 161 | 0 | "<entry>\n" . $args{desc} . "\n</entry>\n</row>\n"); | |||||||||
| 162 | } | ||||||||||
| 163 | |||||||||||
| 164 | sub _render_sys_table_end | ||||||||||
| 165 | { | ||||||||||
| 166 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_render_sys_table_end: not called CC=1 SCAR=6.9
| |||||||||||
| 167 | 0 | $self->_out("</tbody>\n</tgroup>\n</table>\n"); | |||||||||
| 168 | } | ||||||||||
| 169 | |||||||||||
| 170 | sub _render_section_end | ||||||||||
| 171 | { | ||||||||||
| 172 | 0 | ▶ | my ($self, %args) = @_; | ||||||||
|
Subroutine
_render_section_end: not called CC=2 SCAR=17.9
| |||||||||||
| 173 | |||||||||||
| 174 | 0 | my $depth = $args{depth}; | |||||||||
| 175 | |||||||||||
| 176 | 0 | ▶ | if ($depth) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 177 | { | ||||||||||
| 178 | 0 | $self->_out("</section>\n"); | |||||||||
| 179 | } | ||||||||||
| 180 | } | ||||||||||
| 181 | |||||||||||
| 182 | =head1 AUTHOR | ||||||||||
| 183 | |||||||||||
| 184 | Shlomi Fish, L<http://www.shlomifish.org/>. | ||||||||||
| 185 | |||||||||||
| 186 | =head1 SEE ALSO | ||||||||||
| 187 | |||||||||||
| 188 | L<XML::CompareML> | ||||||||||
| 189 | |||||||||||
| 190 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 191 | |||||||||||
| 192 | Copyright 2004, Shlomi Fish. All rights reserved. | ||||||||||
| 193 | |||||||||||
| 194 | You can use, modify and distribute this module under the terms of the MIT X11 | ||||||||||
| 195 | license. ( L<http://www.opensource.org/licenses/mit-license.php> ). | ||||||||||
| 196 | |||||||||||
| 197 | =cut | ||||||||||
| 198 | |||||||||||
| 199 | 2 | 1; | |||||||||
| 200 | |||||||||||