| 1 | package XML::CompareML::Base; | ||||||||||||
| 2 | 3 | $XML::CompareML::Base::VERSION = '0.2.13'; | |||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | |||||||||||||
| 7 | 3 | ▶ | use XML::LibXML; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 3 | ▶ | use XML::CompareML::DTD::Generate; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 3 | ▶ | use parent qw(Class::Accessor); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | 3 | __PACKAGE__->mk_accessors( qw(_timestamp root_elem impls_indexes impls_names), | |||||||||||
| 14 | qw(parser dom), ); | ||||||||||||
| 15 | |||||||||||||
| 16 | sub new | ||||||||||||
| 17 | 0 | ▶ | { | ||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 18 | 0 | my $class = shift; | |||||||||||
| 19 | 0 | my $self = {}; | |||||||||||
| 20 | 0 | bless $self, $class; | |||||||||||
| 21 | 0 | $self->_initialize(@_); | |||||||||||
| 22 | 0 | return $self; | |||||||||||
| 23 | } | ||||||||||||
| 24 | |||||||||||||
| 25 | sub _findnodes | ||||||||||||
| 26 | 0 | ▶ | { | ||||||||||
|
Subroutine
_findnodes: not called CC=1 SCAR=6.9
| |||||||||||||
| 27 | 0 | my $self = shift; | |||||||||||
| 28 | 0 | return $self->root_elem->findnodes(@_); | |||||||||||
| 29 | } | ||||||||||||
| 30 | |||||||||||||
| 31 | sub _xml_node_contents_to_string | ||||||||||||
| 32 | 0 | ▶ | { | ||||||||||
|
Subroutine
_xml_node_contents_to_string: not called CC=1 SCAR=6.9
| |||||||||||||
| 33 | 0 | my $self = shift; | |||||||||||
| 34 | 0 | my $node = shift; | |||||||||||
| 35 | 0 | my @child_nodes = $node->childNodes(); | |||||||||||
| 36 | 0 | my $ret = join( "", map { $_->toString() } @child_nodes ); | |||||||||||
| 37 | |||||||||||||
| 38 | # Remove leading and trailing space. | ||||||||||||
| 39 | 0 | $ret =~ s!^\s+!!mg; | |||||||||||
| 40 | 0 | $ret =~ s/\s+$//mg; | |||||||||||
| 41 | 0 | return $ret; | |||||||||||
| 42 | } | ||||||||||||
| 43 | |||||||||||||
| 44 | sub _impl_get_tag_text | ||||||||||||
| 45 | 0 | ▶ | { | ||||||||||
|
Subroutine
_impl_get_tag_text: not called CC=2 SCAR=17.9
| |||||||||||||
| 46 | 0 | my $self = shift; | |||||||||||
| 47 | 0 | my $impl_elem = shift; | |||||||||||
| 48 | 0 | my $tag = shift; | |||||||||||
| 49 | 0 | my ($name_elem) = $impl_elem->getChildrenByTagName($tag); | |||||||||||
| 50 | 0 | ▶ | if ( !defined($name_elem) ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 51 | { | ||||||||||||
| 52 | 0 | return; | |||||||||||
| 53 | } | ||||||||||||
| 54 | 0 | return $self->_xml_node_contents_to_string($name_elem); | |||||||||||
| 55 | } | ||||||||||||
| 56 | |||||||||||||
| 57 | sub _impl_get_name | ||||||||||||
| 58 | 0 | ▶ | { | ||||||||||
|
Subroutine
_impl_get_name: not called CC=1 SCAR=6.9
| |||||||||||||
| 59 | 0 | my $self = shift; | |||||||||||
| 60 | 0 | my $impl_elem = shift; | |||||||||||
| 61 | 0 | return $self->_impl_get_tag_text( $impl_elem, "name" ); | |||||||||||
| 62 | } | ||||||||||||
| 63 | |||||||||||||
| 64 | sub _get_implementations | ||||||||||||
| 65 | 0 | ▶ | { | ||||||||||
|
Subroutine
_get_implementations: not called CC=1 SCAR=6.9
| |||||||||||||
| 66 | 0 | my $self = shift; | |||||||||||
| 67 | return [ | ||||||||||||
| 68 | map { | ||||||||||||
| 69 | 0 | +{ | |||||||||||
| 70 | 0 | 'id' => $_->getAttribute("id"), | |||||||||||
| 71 | 'name' => $self->_impl_get_name($_) | ||||||||||||
| 72 | } | ||||||||||||
| 73 | } $self->_findnodes("/comparison/meta/implementations/impl") | ||||||||||||
| 74 | ]; | ||||||||||||
| 75 | } | ||||||||||||
| 76 | |||||||||||||
| 77 | sub _get_timestamp | ||||||||||||
| 78 | 0 | ▶ | { | ||||||||||
|
Subroutine
_get_timestamp: not called CC=2 SCAR=17.9
| |||||||||||||
| 79 | 0 | my $self = shift; | |||||||||||
| 80 | 0 | my @nodes = $self->_findnodes("/comparison/meta/timestamp"); | |||||||||||
| 81 | 0 | ▶ | if (@nodes) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 82 | { | ||||||||||||
| 83 | 0 | return $self->_xml_node_contents_to_string( $nodes[0] ); | |||||||||||
| 84 | } | ||||||||||||
| 85 | else | ||||||||||||
| 86 | { | ||||||||||||
| 87 | 0 | return; | |||||||||||
| 88 | } | ||||||||||||
| 89 | } | ||||||||||||
| 90 | |||||||||||||
| 91 | sub _initialize | ||||||||||||
| 92 | 0 | ▶ | { | ||||||||||
|
Subroutine
_initialize: not called CC=3 SCAR=24.8
| |||||||||||||
| 93 | 0 | my $self = shift; | |||||||||||
| 94 | 0 | my %args = (@_); | |||||||||||
| 95 | 0 | my $parser; | |||||||||||
| 96 | my $dom; | ||||||||||||
| 97 | 0 | ▶ | if ( $args{input_filename} ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 98 | { | ||||||||||||
| 99 | 0 | $parser = XML::LibXML->new(); | |||||||||||
| 100 | 0 | $parser->validation(0); | |||||||||||
| 101 | 0 | $dom = $parser->parse_file( $args{input_filename} ); | |||||||||||
| 102 | 0 | my $dtd = | |||||||||||
| 103 | XML::LibXML::Dtd->parse_string( | ||||||||||||
| 104 | XML::CompareML::DTD::Generate::get_dtd() ); | ||||||||||||
| 105 | 0 | $dom->validate($dtd); | |||||||||||
| 106 | } | ||||||||||||
| 107 | else | ||||||||||||
| 108 | { | ||||||||||||
| 109 | 0 | die "input_filename must be specified!"; | |||||||||||
| 110 | } | ||||||||||||
| 111 | 0 | ▶ | if ( $args{output_handle} ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 112 | { | ||||||||||||
| 113 | 0 | $self->{o} = $args{output_handle}; | |||||||||||
| 114 | } | ||||||||||||
| 115 | else | ||||||||||||
| 116 | { | ||||||||||||
| 117 | 0 | die "output_handle must be specified!"; | |||||||||||
| 118 | } | ||||||||||||
| 119 | 0 | $self->parser($parser); | |||||||||||
| 120 | 0 | $self->dom($dom); | |||||||||||
| 121 | 0 | $self->root_elem( $dom->getDocumentElement() ); | |||||||||||
| 122 | } | ||||||||||||
| 123 | |||||||||||||
| 124 | sub process | ||||||||||||
| 125 | 0 | ▶ | { | ||||||||||
|
Subroutine
process: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 126 | 0 | my $self = shift; | |||||||||||
| 127 | |||||||||||||
| 128 | 0 | my ($contents_elem) = $self->root_elem->getChildrenByTagName("contents"); | |||||||||||
| 129 | 0 | my ($top_section_elem) = $contents_elem->getChildrenByTagName("section"); | |||||||||||
| 130 | |||||||||||||
| 131 | 0 | my @impls = @{ $self->_get_implementations() }; | |||||||||||
| 132 | |||||||||||||
| 133 | 0 | $self->{impls} = \@impls; | |||||||||||
| 134 | $self->impls_indexes( | ||||||||||||
| 135 | 0 | +{ map { $impls[$_]->{'id'} => $_ } ( 0 .. $#impls ) } ); | |||||||||||
| 136 | 0 | $self->impls_names( +{ map { $_->{'id'} => $_->{'name'} } @impls } ); | |||||||||||
| 137 | 0 | $self->_timestamp( scalar( $self->_get_timestamp() ) ); | |||||||||||
| 138 | |||||||||||||
| 139 | 0 | $self->{document_text} = ""; | |||||||||||
| 140 | 0 | $self->{toc_text} = ""; | |||||||||||
| 141 | |||||||||||||
| 142 | # Make sure we print anything only when we finished extracting all | ||||||||||||
| 143 | # the meta-data. | ||||||||||||
| 144 | 0 | $self->_print_header(); | |||||||||||
| 145 | |||||||||||||
| 146 | 0 | $self->_start_rendering(); | |||||||||||
| 147 | |||||||||||||
| 148 | 0 | $self->_render_section( 'elem' => $top_section_elem, 'depth' => 0, ); | |||||||||||
| 149 | |||||||||||||
| 150 | 0 | $self->_finish_rendering(); | |||||||||||
| 151 | |||||||||||||
| 152 | 0 | print { *{ $self->{o} } } $self->{document_text}; | |||||||||||
| 153 | |||||||||||||
| 154 | 0 | $self->_print_footer(); | |||||||||||
| 155 | } | ||||||||||||
| 156 | |||||||||||||
| 157 | sub _name | ||||||||||||
| 158 | 0 | ▶ | { | ||||||||||
|
Subroutine
_name: not called CC=1 SCAR=6.9
| |||||||||||||
| 159 | 0 | my $self = shift; | |||||||||||
| 160 | 0 | my $id = shift; | |||||||||||
| 161 | 0 | return $self->impls_names->{$id}; | |||||||||||
| 162 | } | ||||||||||||
| 163 | |||||||||||||
| 164 | sub _sorter | ||||||||||||
| 165 | 0 | ▶ | { | ||||||||||
|
Subroutine
_sorter: not called CC=2 SCAR=17.9
| |||||||||||||
| 166 | 0 | my $self = shift; | |||||||||||
| 167 | 0 | my $impl = shift; | |||||||||||
| 168 | |||||||||||||
| 169 | 0 | my $indexes = $self->impls_indexes(); | |||||||||||
| 170 | |||||||||||||
| 171 | 0 | ▶ | if ( !exists( $indexes->{$impl} ) ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 172 | { | ||||||||||||
| 173 | 0 | die "Unknown system $impl"; | |||||||||||
| 174 | } | ||||||||||||
| 175 | 0 | return $indexes->{$impl}; | |||||||||||
| 176 | } | ||||||||||||
| 177 | |||||||||||||
| 178 | sub _out | ||||||||||||
| 179 | 0 | ▶ | { | ||||||||||
|
Subroutine
_out: not called CC=1 SCAR=6.9
| |||||||||||||
| 180 | 0 | my $self = shift; | |||||||||||
| 181 | 0 | $self->{document_text} .= join( "", @_ ); | |||||||||||
| 182 | } | ||||||||||||
| 183 | |||||||||||||
| 184 | sub _toc_out | ||||||||||||
| 185 | 0 | ▶ | { | ||||||||||
|
Subroutine
_toc_out: not called CC=1 SCAR=6.9
| |||||||||||||
| 186 | 0 | my $self = shift; | |||||||||||
| 187 | 0 | $self->{toc_text} .= join( "", @_ ); | |||||||||||
| 188 | } | ||||||||||||
| 189 | |||||||||||||
| 190 | sub _render_section | ||||||||||||
| 191 | 0 | ▶ | { | ||||||||||
|
Subroutine
_render_section: not called CC=5 SCAR=34.0
| |||||||||||||
| 192 | 0 | my $self = shift; | |||||||||||
| 193 | 0 | my %args = (@_); | |||||||||||
| 194 | 0 | my $section_elem = $args{elem}; | |||||||||||
| 195 | 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'}
| |||||||||||||
| 196 | |||||||||||||
| 197 | 0 | my ($expl) = $section_elem->getChildrenByTagName("expl"); | |||||||||||
| 198 | 0 | my ($title) = $section_elem->getChildrenByTagName("title"); | |||||||||||
| 199 | 0 | my ($compare) = $section_elem->getChildrenByTagName("compare"); | |||||||||||
| 200 | 0 | my @sub_sections = $section_elem->getChildrenByTagName("section"); | |||||||||||
| 201 | |||||||||||||
| 202 | 0 | my $title_string = $title->string_value(); | |||||||||||
| 203 | |||||||||||||
| 204 | 0 | my $id = $section_elem->getAttribute("id"); | |||||||||||
| 205 | |||||||||||||
| 206 | 0 | my @args = ( | |||||||||||
| 207 | 'depth' => $depth, | ||||||||||||
| 208 | 'id' => $id, | ||||||||||||
| 209 | 'title_string' => $title_string, | ||||||||||||
| 210 | 'expl' => $expl, | ||||||||||||
| 211 | 'sub_sections' => \@sub_sections, | ||||||||||||
| 212 | ); | ||||||||||||
| 213 | |||||||||||||
| 214 | 0 | $self->_render_section_start(@args); | |||||||||||
| 215 | |||||||||||||
| 216 | 0 | ▶ | if ($compare) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 217 | { | ||||||||||||
| 218 | 0 | $self->_render_sys_table_start(@args); | |||||||||||
| 219 | |||||||||||||
| 220 | 0 | my @systems = ( $compare->getChildrenByTagName("s") ); | |||||||||||
| 221 | my %kv = | ||||||||||||
| 222 | 0 | ( map { $_->getAttribute("id") => $self->_render_s_elem($_) } | |||||||||||
| 223 | @systems ); | ||||||||||||
| 224 | my @keys_sorted = | ||||||||||||
| 225 | 0 | ( sort { $self->_sorter($a) <=> $self->_sorter($b) } keys(%kv) ); | |||||||||||
| 226 | 0 | foreach my $k (@keys_sorted) | |||||||||||
| 227 | { | ||||||||||||
| 228 | $self->_render_sys_table_row( | ||||||||||||
| 229 | 'name' => $self->_name($k), | ||||||||||||
| 230 | 0 | 'desc' => $kv{$k}, | |||||||||||
| 231 | ); | ||||||||||||
| 232 | } | ||||||||||||
| 233 | 0 | $self->_render_sys_table_end(); | |||||||||||
| 234 | } | ||||||||||||
| 235 | |||||||||||||
| 236 | 0 | foreach my $sub (@sub_sections) | |||||||||||
| 237 | { | ||||||||||||
| 238 | 0 | $self->_render_section( | |||||||||||
| 239 | 'elem' => $sub, | ||||||||||||
| 240 | 'depth' => ( $depth + 1 ) | ||||||||||||
| 241 | ); | ||||||||||||
| 242 | } | ||||||||||||
| 243 | |||||||||||||
| 244 | 0 | $self->_render_section_end( @args, ); | |||||||||||
| 245 | } | ||||||||||||
| 246 | |||||||||||||
| 247 | |||||||||||||
| 248 | 3 | 1; | |||||||||||
| 249 | |||||||||||||
| 250 | __END__ | ||||||||||||