| 1 | package XML::CompareML::Base; | ||||||||||||
| 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::Base - base class for the CompareML-to-something converters. | ||||||||||||
| 9 | |||||||||||||
| 10 | =head1 SYNOPSIS | ||||||||||||
| 11 | |||||||||||||
| 12 | see L<XML::CompareML>. | ||||||||||||
| 13 | |||||||||||||
| 14 | =head1 METHODS | ||||||||||||
| 15 | |||||||||||||
| 16 | =head2 new() | ||||||||||||
| 17 | |||||||||||||
| 18 | A constructor - should be used by a derived class. | ||||||||||||
| 19 | |||||||||||||
| 20 | =head2 $compare->process() | ||||||||||||
| 21 | |||||||||||||
| 22 | See L<XML::CompareML> | ||||||||||||
| 23 | =cut | ||||||||||||
| 24 | |||||||||||||
| 25 | 2 | ▶ | use XML::LibXML; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 26 | |||||||||||||
| 27 | 2 | ▶ | use XML::CompareML::DTD::Generate; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 28 | |||||||||||||
| 29 | 2 | ▶ | use base qw(Class::Accessor); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 30 | |||||||||||||
| 31 | 2 | __PACKAGE__->mk_accessors( | |||||||||||
| 32 | qw(_timestamp root_elem impls_indexes impls_names), | ||||||||||||
| 33 | qw(parser dom), | ||||||||||||
| 34 | ); | ||||||||||||
| 35 | |||||||||||||
| 36 | sub new | ||||||||||||
| 37 | { | ||||||||||||
| 38 | 0 | ▶ | my $class = shift; | ||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 39 | 0 | my $self = {}; | |||||||||||
| 40 | 0 | bless $self, $class; | |||||||||||
| 41 | 0 | $self->_initialize(@_); | |||||||||||
| 42 | 0 | return $self; | |||||||||||
| 43 | } | ||||||||||||
| 44 | |||||||||||||
| 45 | sub _findnodes | ||||||||||||
| 46 | { | ||||||||||||
| 47 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_findnodes: not called CC=1 SCAR=6.9
| |||||||||||||
| 48 | 0 | return $self->root_elem->findnodes(@_); | |||||||||||
| 49 | } | ||||||||||||
| 50 | |||||||||||||
| 51 | sub _xml_node_contents_to_string | ||||||||||||
| 52 | { | ||||||||||||
| 53 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_xml_node_contents_to_string: not called CC=1 SCAR=6.9
| |||||||||||||
| 54 | 0 | my $node = shift; | |||||||||||
| 55 | 0 | my @child_nodes = $node->childNodes(); | |||||||||||
| 56 | 0 | my $ret = join("", map { $_->toString() } @child_nodes); | |||||||||||
| 57 | # Remove leading and trailing space. | ||||||||||||
| 58 | 0 | $ret =~ s!^\s+!!mg; | |||||||||||
| 59 | 0 | $ret =~ s/\s+$//mg; | |||||||||||
| 60 | 0 | return $ret; | |||||||||||
| 61 | } | ||||||||||||
| 62 | |||||||||||||
| 63 | sub _impl_get_tag_text | ||||||||||||
| 64 | { | ||||||||||||
| 65 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_impl_get_tag_text: not called CC=2 SCAR=17.9
| |||||||||||||
| 66 | 0 | my $impl_elem = shift; | |||||||||||
| 67 | 0 | my $tag = shift; | |||||||||||
| 68 | 0 | my ($name_elem) = $impl_elem->getChildrenByTagName($tag); | |||||||||||
| 69 | 0 | ▶ | if (!defined($name_elem)) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 70 | { | ||||||||||||
| 71 | 0 | return; | |||||||||||
| 72 | } | ||||||||||||
| 73 | 0 | return $self->_xml_node_contents_to_string($name_elem); | |||||||||||
| 74 | } | ||||||||||||
| 75 | |||||||||||||
| 76 | sub _impl_get_name | ||||||||||||
| 77 | { | ||||||||||||
| 78 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_impl_get_name: not called CC=1 SCAR=6.9
| |||||||||||||
| 79 | 0 | my $impl_elem = shift; | |||||||||||
| 80 | 0 | return $self->_impl_get_tag_text($impl_elem, "name"); | |||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | sub _get_implementations | ||||||||||||
| 84 | { | ||||||||||||
| 85 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_get_implementations: not called CC=1 SCAR=6.9
| |||||||||||||
| 86 | return | ||||||||||||
| 87 | [ | ||||||||||||
| 88 | map | ||||||||||||
| 89 | { | ||||||||||||
| 90 | 0 | +{ | |||||||||||
| 91 | 0 | 'id' => $_->getAttribute("id"), | |||||||||||
| 92 | 'name' => $self->_impl_get_name($_) | ||||||||||||
| 93 | } | ||||||||||||
| 94 | } | ||||||||||||
| 95 | $self->_findnodes("/comparison/meta/implementations/impl") | ||||||||||||
| 96 | ]; | ||||||||||||
| 97 | } | ||||||||||||
| 98 | |||||||||||||
| 99 | sub _get_timestamp | ||||||||||||
| 100 | { | ||||||||||||
| 101 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_get_timestamp: not called CC=2 SCAR=17.9
| |||||||||||||
| 102 | 0 | my @nodes = $self->_findnodes("/comparison/meta/timestamp"); | |||||||||||
| 103 | 0 | ▶ | if (@nodes) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 104 | { | ||||||||||||
| 105 | 0 | return $self->_xml_node_contents_to_string($nodes[0]); | |||||||||||
| 106 | } | ||||||||||||
| 107 | else | ||||||||||||
| 108 | { | ||||||||||||
| 109 | 0 | return undef; | |||||||||||
| 110 | } | ||||||||||||
| 111 | } | ||||||||||||
| 112 | |||||||||||||
| 113 | sub _initialize | ||||||||||||
| 114 | { | ||||||||||||
| 115 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_initialize: not called CC=3 SCAR=24.8
| |||||||||||||
| 116 | 0 | my %args = (@_); | |||||||||||
| 117 | 0 | my $parser; | |||||||||||
| 118 | my $dom; | ||||||||||||
| 119 | 0 | ▶ | if ($args{input_filename}) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 120 | { | ||||||||||||
| 121 | 0 | $parser = XML::LibXML->new(); | |||||||||||
| 122 | 0 | $parser->validation(0); | |||||||||||
| 123 | 0 | $dom = $parser->parse_file($args{input_filename}); | |||||||||||
| 124 | 0 | my $dtd = | |||||||||||
| 125 | XML::LibXML::Dtd->parse_string( | ||||||||||||
| 126 | XML::CompareML::DTD::Generate::get_dtd() | ||||||||||||
| 127 | ); | ||||||||||||
| 128 | 0 | $dom->validate($dtd); | |||||||||||
| 129 | } | ||||||||||||
| 130 | else | ||||||||||||
| 131 | { | ||||||||||||
| 132 | 0 | die "input_filename must be specified!"; | |||||||||||
| 133 | } | ||||||||||||
| 134 | 0 | ▶ | if ($args{output_handle}) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 135 | { | ||||||||||||
| 136 | 0 | $self->{o} = $args{output_handle}; | |||||||||||
| 137 | } | ||||||||||||
| 138 | else | ||||||||||||
| 139 | { | ||||||||||||
| 140 | 0 | die "output_handle must be specified!"; | |||||||||||
| 141 | } | ||||||||||||
| 142 | 0 | $self->parser($parser); | |||||||||||
| 143 | 0 | $self->dom($dom); | |||||||||||
| 144 | 0 | $self->root_elem($dom->getDocumentElement()); | |||||||||||
| 145 | } | ||||||||||||
| 146 | |||||||||||||
| 147 | sub process | ||||||||||||
| 148 | { | ||||||||||||
| 149 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
process: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 150 | |||||||||||||
| 151 | 0 | my ($contents_elem) = $self->root_elem->getChildrenByTagName("contents"); | |||||||||||
| 152 | 0 | my ($top_section_elem) = $contents_elem->getChildrenByTagName("section"); | |||||||||||
| 153 | |||||||||||||
| 154 | 0 | my @impls = @{$self->_get_implementations()}; | |||||||||||
| 155 | |||||||||||||
| 156 | 0 | $self->{impls} = \@impls; | |||||||||||
| 157 | 0 | $self->impls_indexes(+{ map { $impls[$_]->{'id'} => $_ } (0 .. $#impls) }); | |||||||||||
| 158 | 0 | $self->impls_names(+{map { $_->{'id'} => $_->{'name'} } @impls }); | |||||||||||
| 159 | 0 | $self->_timestamp($self->_get_timestamp()); | |||||||||||
| 160 | |||||||||||||
| 161 | 0 | $self->{document_text} = ""; | |||||||||||
| 162 | 0 | $self->{toc_text} = ""; | |||||||||||
| 163 | |||||||||||||
| 164 | # Make sure we print anything only when we finished extracting all | ||||||||||||
| 165 | # the meta-data. | ||||||||||||
| 166 | 0 | $self->_print_header(); | |||||||||||
| 167 | |||||||||||||
| 168 | 0 | $self->_start_rendering(); | |||||||||||
| 169 | |||||||||||||
| 170 | 0 | $self->_render_section('elem' => $top_section_elem, 'depth' => 0,); | |||||||||||
| 171 | |||||||||||||
| 172 | 0 | $self->_finish_rendering(); | |||||||||||
| 173 | |||||||||||||
| 174 | 0 | print {*{$self->{o}}} $self->{document_text}; | |||||||||||
| 175 | |||||||||||||
| 176 | 0 | $self->_print_footer(); | |||||||||||
| 177 | } | ||||||||||||
| 178 | |||||||||||||
| 179 | sub _name | ||||||||||||
| 180 | { | ||||||||||||
| 181 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_name: not called CC=1 SCAR=6.9
| |||||||||||||
| 182 | 0 | my $id = shift; | |||||||||||
| 183 | 0 | return $self->impls_names->{$id}; | |||||||||||
| 184 | } | ||||||||||||
| 185 | |||||||||||||
| 186 | sub _sorter | ||||||||||||
| 187 | { | ||||||||||||
| 188 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_sorter: not called CC=2 SCAR=17.9
| |||||||||||||
| 189 | 0 | my $impl = shift; | |||||||||||
| 190 | |||||||||||||
| 191 | 0 | my $indexes = $self->impls_indexes(); | |||||||||||
| 192 | |||||||||||||
| 193 | 0 | ▶ | if (!exists($indexes->{$impl})) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 194 | { | ||||||||||||
| 195 | 0 | die "Unknown system $impl"; | |||||||||||
| 196 | } | ||||||||||||
| 197 | 0 | return $indexes->{$impl}; | |||||||||||
| 198 | } | ||||||||||||
| 199 | |||||||||||||
| 200 | sub _out | ||||||||||||
| 201 | { | ||||||||||||
| 202 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_out: not called CC=1 SCAR=6.9
| |||||||||||||
| 203 | 0 | $self->{document_text} .= join("", @_); | |||||||||||
| 204 | } | ||||||||||||
| 205 | |||||||||||||
| 206 | sub _toc_out | ||||||||||||
| 207 | { | ||||||||||||
| 208 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_toc_out: not called CC=1 SCAR=6.9
| |||||||||||||
| 209 | 0 | $self->{toc_text} .= join("", @_); | |||||||||||
| 210 | } | ||||||||||||
| 211 | |||||||||||||
| 212 | sub _render_section | ||||||||||||
| 213 | { | ||||||||||||
| 214 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_render_section: not called CC=5 SCAR=34.0
| |||||||||||||
| 215 | 0 | my %args = (@_); | |||||||||||
| 216 | 0 | my $section_elem = $args{elem}; | |||||||||||
| 217 | 0 | ▶ | my $depth = $args{depth} || 0; | ||||||||||
|
Condition0%0/2
$args{'depth'} || 0
MC/DC0%0/1
$args{'depth'} || 0
$args{'depth'}
Truth table0%0/2
A
A= $args{'depth'}
| |||||||||||||
| 218 | |||||||||||||
| 219 | 0 | my ($expl) = $section_elem->getChildrenByTagName("expl"); | |||||||||||
| 220 | 0 | my ($title) = $section_elem->getChildrenByTagName("title"); | |||||||||||
| 221 | 0 | my ($compare) = $section_elem->getChildrenByTagName("compare"); | |||||||||||
| 222 | 0 | my @sub_sections = $section_elem->getChildrenByTagName("section"); | |||||||||||
| 223 | |||||||||||||
| 224 | 0 | my $title_string = $title->string_value(); | |||||||||||
| 225 | |||||||||||||
| 226 | 0 | my $id = $section_elem->getAttribute("id"); | |||||||||||
| 227 | |||||||||||||
| 228 | 0 | my @args = ( | |||||||||||
| 229 | 'depth' => $depth, | ||||||||||||
| 230 | 'id' => $id, | ||||||||||||
| 231 | 'title_string' => $title_string, | ||||||||||||
| 232 | 'expl' => $expl, | ||||||||||||
| 233 | 'sub_sections' => \@sub_sections, | ||||||||||||
| 234 | ); | ||||||||||||
| 235 | |||||||||||||
| 236 | 0 | $self->_render_section_start( | |||||||||||
| 237 | @args | ||||||||||||
| 238 | ); | ||||||||||||
| 239 | |||||||||||||
| 240 | 0 | ▶ | if ($compare) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 241 | { | ||||||||||||
| 242 | 0 | $self->_render_sys_table_start(@args); | |||||||||||
| 243 | |||||||||||||
| 244 | 0 | my @systems = ($compare->getChildrenByTagName("s")); | |||||||||||
| 245 | my %kv = | ||||||||||||
| 246 | (map | ||||||||||||
| 247 | 0 | { $_->getAttribute("id") => $self->_render_s_elem($_) } | |||||||||||
| 248 | @systems | ||||||||||||
| 249 | ); | ||||||||||||
| 250 | 0 | my @keys_sorted = (sort { $self->_sorter($a) <=> $self->_sorter($b) } keys(%kv)); | |||||||||||
| 251 | 0 | foreach my $k (@keys_sorted) | |||||||||||
| 252 | { | ||||||||||||
| 253 | $self->_render_sys_table_row( | ||||||||||||
| 254 | 'name' => $self->_name($k), | ||||||||||||
| 255 | 0 | 'desc' => $kv{$k}, | |||||||||||
| 256 | ); | ||||||||||||
| 257 | } | ||||||||||||
| 258 | 0 | $self->_render_sys_table_end(); | |||||||||||
| 259 | } | ||||||||||||
| 260 | |||||||||||||
| 261 | 0 | foreach my $sub (@sub_sections) | |||||||||||
| 262 | { | ||||||||||||
| 263 | 0 | $self->_render_section( | |||||||||||
| 264 | 'elem' => $sub, | ||||||||||||
| 265 | 'depth' => ($depth+1) | ||||||||||||
| 266 | ); | ||||||||||||
| 267 | } | ||||||||||||
| 268 | |||||||||||||
| 269 | $self->_render_section_end( | ||||||||||||
| 270 | 0 | @args, | |||||||||||
| 271 | ); | ||||||||||||
| 272 | } | ||||||||||||
| 273 | |||||||||||||
| 274 | =head1 AUTHOR | ||||||||||||
| 275 | |||||||||||||
| 276 | Shlomi Fish, L<http://www.shlomifish.org/>. | ||||||||||||
| 277 | |||||||||||||
| 278 | =head1 SEE ALSO | ||||||||||||
| 279 | |||||||||||||
| 280 | L<XML::CompareML> | ||||||||||||
| 281 | |||||||||||||
| 282 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 283 | |||||||||||||
| 284 | Copyright 2004, Shlomi Fish. All rights reserved. | ||||||||||||
| 285 | |||||||||||||
| 286 | You can use, modify and distribute this module under the terms of the MIT X11 | ||||||||||||
| 287 | license. ( L<http://www.opensource.org/licenses/mit-license.php> ). | ||||||||||||
| 288 | |||||||||||||
| 289 | =cut | ||||||||||||
| 290 | |||||||||||||
| 291 | 2 | 1; | |||||||||||