| 1 | package XML::XPath::Node; | ||||||||||||||||||||||
| 2 | |||||||||||||||||||||||
| 3 | 1 | $VERSION = '1.26'; | |||||||||||||||||||||
| 4 | |||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 6 | 1 | ▶ | use vars qw(@ISA @EXPORT $AUTOLOAD %EXPORT_TAGS @EXPORT_OK); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 7 | 1 | ▶ | use Exporter; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 9 | 1 | @ISA = ('Exporter'); | |||||||||||||||||||||
| 10 | |||||||||||||||||||||||
| 11 | sub UNKNOWN_NODE () {0;} | ||||||||||||||||||||||
| 12 | sub ELEMENT_NODE () {1;} | ||||||||||||||||||||||
| 13 | sub ATTRIBUTE_NODE () {2;} | ||||||||||||||||||||||
| 14 | sub TEXT_NODE () {3;} | ||||||||||||||||||||||
| 15 | sub CDATA_SECTION_NODE () {4;} | ||||||||||||||||||||||
| 16 | sub ENTITY_REFERENCE_NODE () {5;} | ||||||||||||||||||||||
| 17 | sub ENTITY_NODE () {6;} | ||||||||||||||||||||||
| 18 | sub PROCESSING_INSTRUCTION_NODE () {7;} | ||||||||||||||||||||||
| 19 | sub COMMENT_NODE () {8;} | ||||||||||||||||||||||
| 20 | sub DOCUMENT_NODE () {9;} | ||||||||||||||||||||||
| 21 | sub DOCUMENT_TYPE_NODE () {10;} | ||||||||||||||||||||||
| 22 | sub DOCUMENT_FRAGMENT_NODE () {11;} | ||||||||||||||||||||||
| 23 | sub NOTATION_NODE () {12;} | ||||||||||||||||||||||
| 24 | |||||||||||||||||||||||
| 25 | # Non core DOM stuff | ||||||||||||||||||||||
| 26 | sub ELEMENT_DECL_NODE () {13;} | ||||||||||||||||||||||
| 27 | sub ATT_DEF_NODE () {14;} | ||||||||||||||||||||||
| 28 | sub XML_DECL_NODE () {15;} | ||||||||||||||||||||||
| 29 | sub ATTLIST_DECL_NODE () {16;} | ||||||||||||||||||||||
| 30 | sub NAMESPACE_NODE () {17;} | ||||||||||||||||||||||
| 31 | |||||||||||||||||||||||
| 32 | # per-node constants | ||||||||||||||||||||||
| 33 | |||||||||||||||||||||||
| 34 | # All | ||||||||||||||||||||||
| 35 | sub node_parent () { 0; } | ||||||||||||||||||||||
| 36 | sub node_pos () { 1; } | ||||||||||||||||||||||
| 37 | sub node_global_pos () { 2; } | ||||||||||||||||||||||
| 38 | |||||||||||||||||||||||
| 39 | # Element | ||||||||||||||||||||||
| 40 | sub node_prefix () { 3; } | ||||||||||||||||||||||
| 41 | sub node_children () { 4; } | ||||||||||||||||||||||
| 42 | sub node_name () { 5; } | ||||||||||||||||||||||
| 43 | sub node_attribs () { 6; } | ||||||||||||||||||||||
| 44 | sub node_namespaces () { 7; } | ||||||||||||||||||||||
| 45 | sub node_ids () { 8; } | ||||||||||||||||||||||
| 46 | |||||||||||||||||||||||
| 47 | # Char | ||||||||||||||||||||||
| 48 | sub node_text () { 3; } | ||||||||||||||||||||||
| 49 | |||||||||||||||||||||||
| 50 | # PI | ||||||||||||||||||||||
| 51 | sub node_target () { 3; } | ||||||||||||||||||||||
| 52 | sub node_data () { 4; } | ||||||||||||||||||||||
| 53 | |||||||||||||||||||||||
| 54 | # Comment | ||||||||||||||||||||||
| 55 | sub node_comment () { 3; } | ||||||||||||||||||||||
| 56 | |||||||||||||||||||||||
| 57 | # Attribute | ||||||||||||||||||||||
| 58 | # sub node_prefix () { 3; } | ||||||||||||||||||||||
| 59 | sub node_key () { 4; } | ||||||||||||||||||||||
| 60 | sub node_value () { 5; } | ||||||||||||||||||||||
| 61 | |||||||||||||||||||||||
| 62 | # Namespaces | ||||||||||||||||||||||
| 63 | # sub node_prefix () { 3; } | ||||||||||||||||||||||
| 64 | sub node_expanded () { 4; } | ||||||||||||||||||||||
| 65 | |||||||||||||||||||||||
| 66 | 1 | @EXPORT = qw( | |||||||||||||||||||||
| 67 | UNKNOWN_NODE | ||||||||||||||||||||||
| 68 | ELEMENT_NODE | ||||||||||||||||||||||
| 69 | ATTRIBUTE_NODE | ||||||||||||||||||||||
| 70 | TEXT_NODE | ||||||||||||||||||||||
| 71 | CDATA_SECTION_NODE | ||||||||||||||||||||||
| 72 | ENTITY_REFERENCE_NODE | ||||||||||||||||||||||
| 73 | ENTITY_NODE | ||||||||||||||||||||||
| 74 | PROCESSING_INSTRUCTION_NODE | ||||||||||||||||||||||
| 75 | COMMENT_NODE | ||||||||||||||||||||||
| 76 | DOCUMENT_NODE | ||||||||||||||||||||||
| 77 | DOCUMENT_TYPE_NODE | ||||||||||||||||||||||
| 78 | DOCUMENT_FRAGMENT_NODE | ||||||||||||||||||||||
| 79 | NOTATION_NODE | ||||||||||||||||||||||
| 80 | ELEMENT_DECL_NODE | ||||||||||||||||||||||
| 81 | ATT_DEF_NODE | ||||||||||||||||||||||
| 82 | XML_DECL_NODE | ||||||||||||||||||||||
| 83 | ATTLIST_DECL_NODE | ||||||||||||||||||||||
| 84 | NAMESPACE_NODE | ||||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||||
| 86 | |||||||||||||||||||||||
| 87 | 1 | @EXPORT_OK = qw( | |||||||||||||||||||||
| 88 | node_parent | ||||||||||||||||||||||
| 89 | node_pos | ||||||||||||||||||||||
| 90 | node_global_pos | ||||||||||||||||||||||
| 91 | node_prefix | ||||||||||||||||||||||
| 92 | node_children | ||||||||||||||||||||||
| 93 | node_name | ||||||||||||||||||||||
| 94 | node_attribs | ||||||||||||||||||||||
| 95 | node_namespaces | ||||||||||||||||||||||
| 96 | node_text | ||||||||||||||||||||||
| 97 | node_target | ||||||||||||||||||||||
| 98 | node_data | ||||||||||||||||||||||
| 99 | node_comment | ||||||||||||||||||||||
| 100 | node_key | ||||||||||||||||||||||
| 101 | node_value | ||||||||||||||||||||||
| 102 | node_expanded | ||||||||||||||||||||||
| 103 | node_ids | ||||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||||
| 105 | |||||||||||||||||||||||
| 106 | 1 | %EXPORT_TAGS = ( | |||||||||||||||||||||
| 107 | 'node_keys' => [ | ||||||||||||||||||||||
| 108 | qw( | ||||||||||||||||||||||
| 109 | node_parent | ||||||||||||||||||||||
| 110 | node_pos | ||||||||||||||||||||||
| 111 | node_global_pos | ||||||||||||||||||||||
| 112 | node_prefix | ||||||||||||||||||||||
| 113 | node_children | ||||||||||||||||||||||
| 114 | node_name | ||||||||||||||||||||||
| 115 | node_attribs | ||||||||||||||||||||||
| 116 | node_namespaces | ||||||||||||||||||||||
| 117 | node_text | ||||||||||||||||||||||
| 118 | node_target | ||||||||||||||||||||||
| 119 | node_data | ||||||||||||||||||||||
| 120 | node_comment | ||||||||||||||||||||||
| 121 | node_key | ||||||||||||||||||||||
| 122 | node_value | ||||||||||||||||||||||
| 123 | node_expanded | ||||||||||||||||||||||
| 124 | node_ids | ||||||||||||||||||||||
| 125 | ), @EXPORT, | ||||||||||||||||||||||
| 126 | ], | ||||||||||||||||||||||
| 127 | ); | ||||||||||||||||||||||
| 128 | |||||||||||||||||||||||
| 129 | |||||||||||||||||||||||
| 130 | 1 | my $global_pos = 0; | |||||||||||||||||||||
| 131 | |||||||||||||||||||||||
| 132 | sub nextPos { | ||||||||||||||||||||||
| 133 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||
|
Subroutine
nextPos: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 134 | 0 | return $global_pos += 5; | |||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||
| 136 | |||||||||||||||||||||||
| 137 | sub resetPos { | ||||||||||||||||||||||
| 138 | 0 | ▶ | $global_pos = 0; | ||||||||||||||||||||
|
Subroutine
resetPos: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||
| 140 | |||||||||||||||||||||||
| 141 | 1 | my %DecodeDefaultEntity = | |||||||||||||||||||||
| 142 | ( | ||||||||||||||||||||||
| 143 | '"' => """, | ||||||||||||||||||||||
| 144 | ">" => ">", | ||||||||||||||||||||||
| 145 | "<" => "<", | ||||||||||||||||||||||
| 146 | "'" => "'", | ||||||||||||||||||||||
| 147 | "&" => "&" | ||||||||||||||||||||||
| 148 | ); | ||||||||||||||||||||||
| 149 | |||||||||||||||||||||||
| 150 | sub XMLescape { | ||||||||||||||||||||||
| 151 | 0 | ▶ | my ($str, $default) = @_; | ||||||||||||||||||||
|
Subroutine
XMLescape: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||
| 152 | 0 | ▶ | return undef unless defined $str; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 153 | 0 | ▶ | $default ||= ''; | ||||||||||||||||||||
|
Condition0%0/2
$default ||= ""
MC/DC0%0/1
$default ||= ""
$default
Truth table0%0/2
A
A= $default
| |||||||||||||||||||||||
| 154 | |||||||||||||||||||||||
| 155 | 0 | ▶ | if ($XML::XPath::EncodeUtf8AsEntity) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 156 | 0 | $str =~ s/([\xC0-\xDF].|[\xE0-\xEF]..|[\xF0-\xFF]...)|([$default])|(]]>)/ | |||||||||||||||||||||
| 157 | defined($1) ? XmlUtf8Decode ($1) : | ||||||||||||||||||||||
| 158 | 0 | ▶ | defined ($2) ? $DecodeDefaultEntity{$2} : "]]>" /egsx; | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||
| 160 | else { | ||||||||||||||||||||||
| 161 | 0 | $str =~ s/([$default])|(]]>)/ | |||||||||||||||||||||
| 162 | 0 | ▶ | defined ($1) ? $DecodeDefaultEntity{$1} : ']]>' /gsex; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||
| 164 | |||||||||||||||||||||||
| 165 | #?? could there be references that should not be expanded? | ||||||||||||||||||||||
| 166 | # e.g. should not replace &#nn; ¯ and &abc; | ||||||||||||||||||||||
| 167 | # $str =~ s/&(?!($ReName|#[0-9]+|#x[0-9a-fA-F]+);)/&/go; | ||||||||||||||||||||||
| 168 | |||||||||||||||||||||||
| 169 | 0 | $str; | |||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||
| 171 | |||||||||||||||||||||||
| 172 | # | ||||||||||||||||||||||
| 173 | # Opposite of XmlUtf8Decode plus it adds prefix "&#" or "&#x" and suffix ";" | ||||||||||||||||||||||
| 174 | # The 2nd parameter ($hex) indicates whether the result is hex encoded or not. | ||||||||||||||||||||||
| 175 | # | ||||||||||||||||||||||
| 176 | sub XmlUtf8Decode | ||||||||||||||||||||||
| 177 | { | ||||||||||||||||||||||
| 178 | 0 | ▶ | my ($str, $hex) = @_; | ||||||||||||||||||||
|
Subroutine
XmlUtf8Decode: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||
| 179 | 0 | my $len = length ($str); | |||||||||||||||||||||
| 180 | 0 | my $n; | |||||||||||||||||||||
| 181 | |||||||||||||||||||||||
| 182 | 0 | ▶ | if ($len == 2) { | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 183 | 0 | my @n = unpack "C2", $str; | |||||||||||||||||||||
| 184 | 0 | $n = (($n[0] & 0x3f) << 6) + ($n[1] & 0x3f); | |||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||
| 186 | elsif ($len == 3) { | ||||||||||||||||||||||
| 187 | 0 | my @n = unpack "C3", $str; | |||||||||||||||||||||
| 188 | 0 | $n = (($n[0] & 0x1f) << 12) + (($n[1] & 0x3f) << 6) + | |||||||||||||||||||||
| 189 | ($n[2] & 0x3f); | ||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||
| 191 | elsif ($len == 4) { | ||||||||||||||||||||||
| 192 | 0 | my @n = unpack "C4", $str; | |||||||||||||||||||||
| 193 | 0 | $n = (($n[0] & 0x0f) << 18) + (($n[1] & 0x3f) << 12) + | |||||||||||||||||||||
| 194 | (($n[2] & 0x3f) << 6) + ($n[3] & 0x3f); | ||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||
| 196 | elsif ($len == 1) { # just to be complete... | ||||||||||||||||||||||
| 197 | 0 | $n = ord ($str); | |||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||
| 199 | else { | ||||||||||||||||||||||
| 200 | 0 | die "bad value [$str] for XmlUtf8Decode"; | |||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||
| 202 | 0 | ▶ | $hex ? sprintf ("&#x%x;", $n) : "&#$n;"; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||
| 204 | |||||||||||||||||||||||
| 205 | sub new { | ||||||||||||||||||||||
| 206 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=13.0
Pod
documented
| |||||||||||||||||||||||
| 207 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 208 | 0 | my $impl = $class . "Impl"; | |||||||||||||||||||||
| 209 | 0 | my $this = $impl->new(@_); | |||||||||||||||||||||
| 210 | 0 | ▶ | if ($XML::XPath::SafeMode) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 211 | 0 | return $this; | |||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||
| 213 | 0 | my $self = \$this; | |||||||||||||||||||||
| 214 | 0 | return bless $self, $class; | |||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||
| 216 | |||||||||||||||||||||||
| 217 | sub AUTOLOAD { | ||||||||||||||||||||||
| 218 | 0 | ▶ | my $method = $AUTOLOAD; | ||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=1 SCAR=5.6
| |||||||||||||||||||||||
| 219 | 0 | $method =~ s/.*:://; | |||||||||||||||||||||
| 220 | # warn "AUTOLOAD $method!\n"; | ||||||||||||||||||||||
| 221 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 222 | 0 | *{$AUTOLOAD} = sub { | |||||||||||||||||||||
| 223 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||
| 224 | 0 | my $olderror = $@; # store previous exceptions | |||||||||||||||||||||
| 225 | 0 | my $obj = eval { $$self }; | |||||||||||||||||||||
| 226 | 0 | ▶ | if ($@) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 227 | 0 | ▶ | if ($@ =~ /Not a SCALAR reference/) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 228 | 0 | croak("No such method $method in " . ref($self)); | |||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||
| 230 | 0 | croak $@; | |||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||
| 232 | 0 | ▶ | if ($obj) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 233 | # make sure $@ propagates if this method call was the result | ||||||||||||||||||||||
| 234 | # of losing scope because of a die(). | ||||||||||||||||||||||
| 235 | 0 | ▶ | if ($method =~ /^(DESTROY|del_parent_link)$/) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 236 | 0 | $obj->$method(@_); | |||||||||||||||||||||
| 237 | 0 | ▶ | $@ = $olderror if $olderror; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 238 | 0 | return; | |||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||
| 240 | 0 | return $obj->$method(@_); | |||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||
| 242 | 0 | }; | |||||||||||||||||||||
| 243 | 0 | goto &$AUTOLOAD; | |||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||
| 245 | |||||||||||||||||||||||
| 246 | package XML::XPath::NodeImpl; | ||||||||||||||||||||||
| 247 | |||||||||||||||||||||||
| 248 | 1 | ▶ | use vars qw/@ISA $AUTOLOAD/; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 249 | 1 | @ISA = ('XML::XPath::Node'); | |||||||||||||||||||||
| 250 | |||||||||||||||||||||||
| 251 | sub new { | ||||||||||||||||||||||
| 252 | 0 | ▶ | die "Virtual base method"; | ||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||
| 254 | |||||||||||||||||||||||
| 255 | sub getNodeType { | ||||||||||||||||||||||
| 256 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
getNodeType: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 257 | 0 | return XML::XPath::Node::UNKNOWN_NODE; | |||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||
| 259 | |||||||||||||||||||||||
| 260 | ▶ | sub isElementNode {} | |||||||||||||||||||||
|
Subroutine
isElementNode: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 261 | ▶ | sub isAttributeNode {} | |||||||||||||||||||||
|
Subroutine
isAttributeNode: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 262 | ▶ | sub isNamespaceNode {} | |||||||||||||||||||||
|
Subroutine
isNamespaceNode: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 263 | ▶ | sub isTextNode {} | |||||||||||||||||||||
|
Subroutine
isTextNode: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 264 | ▶ | sub isProcessingInstructionNode {} | |||||||||||||||||||||
|
Subroutine
isProcessingInstructionNode: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 265 | ▶ | sub isPINode {} | |||||||||||||||||||||
|
Subroutine
isPINode: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 266 | ▶ | sub isCommentNode {} | |||||||||||||||||||||
|
Subroutine
isCommentNode: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 267 | |||||||||||||||||||||||
| 268 | sub getNodeValue { | ||||||||||||||||||||||
| 269 | 0 | ▶ | return; | ||||||||||||||||||||
|
Subroutine
getNodeValue: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||
| 271 | |||||||||||||||||||||||
| 272 | sub getValue { | ||||||||||||||||||||||
| 273 | 0 | ▶ | shift->getNodeValue(@_); | ||||||||||||||||||||
|
Subroutine
getValue: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||
| 275 | |||||||||||||||||||||||
| 276 | sub setNodeValue { | ||||||||||||||||||||||
| 277 | 0 | ▶ | return; | ||||||||||||||||||||
|
Subroutine
setNodeValue: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||
| 279 | |||||||||||||||||||||||
| 280 | sub setValue { | ||||||||||||||||||||||
| 281 | 0 | ▶ | shift->setNodeValue(@_); | ||||||||||||||||||||
|
Subroutine
setValue: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||
| 283 | |||||||||||||||||||||||
| 284 | sub getParentNode { | ||||||||||||||||||||||
| 285 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
getParentNode: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 286 | 0 | return $self->[XML::XPath::Node::node_parent]; | |||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||
| 288 | |||||||||||||||||||||||
| 289 | sub getRootNode { | ||||||||||||||||||||||
| 290 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
getRootNode: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 291 | 0 | ▶ | while (my $parent = $self->getParentNode) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 292 | 0 | $self = $parent; | |||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||
| 294 | 0 | return $self; | |||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||
| 296 | |||||||||||||||||||||||
| 297 | sub getElementById { | ||||||||||||||||||||||
| 298 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
getElementById: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 299 | 0 | my ($id) = @_; | |||||||||||||||||||||
| 300 | # warn "getElementById: $id\n"; | ||||||||||||||||||||||
| 301 | 0 | my $root = $self->getRootNode; | |||||||||||||||||||||
| 302 | 0 | my $node = $root->[XML::XPath::Node::node_ids]{$id}; | |||||||||||||||||||||
| 303 | # warn "returning node: ", $node->getName, "\n"; | ||||||||||||||||||||||
| 304 | 0 | return $node; | |||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||
| 306 | |||||||||||||||||||||||
| 307 | ▶ | sub getName { } | |||||||||||||||||||||
|
Subroutine
getName: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 308 | ▶ | sub getData { } | |||||||||||||||||||||
|
Subroutine
getData: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 309 | |||||||||||||||||||||||
| 310 | sub getChildNodes { | ||||||||||||||||||||||
| 311 | 0 | ▶ | return wantarray ? () : []; | ||||||||||||||||||||
|
Subroutine
getChildNodes: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||
| 313 | |||||||||||||||||||||||
| 314 | sub getChildNode { | ||||||||||||||||||||||
| 315 | 0 | ▶ | return; | ||||||||||||||||||||
|
Subroutine
getChildNode: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||
| 317 | |||||||||||||||||||||||
| 318 | sub getAttribute { | ||||||||||||||||||||||
| 319 | 0 | ▶ | return; | ||||||||||||||||||||
|
Subroutine
getAttribute: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||
| 321 | |||||||||||||||||||||||
| 322 | sub getAttributes { | ||||||||||||||||||||||
| 323 | 0 | ▶ | return wantarray ? () : []; | ||||||||||||||||||||
|
Subroutine
getAttributes: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||
| 325 | |||||||||||||||||||||||
| 326 | sub getAttributeNodes { | ||||||||||||||||||||||
| 327 | 0 | ▶ | shift->getAttributes(@_); | ||||||||||||||||||||
|
Subroutine
getAttributeNodes: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||
| 329 | |||||||||||||||||||||||
| 330 | sub getNamespaceNodes { | ||||||||||||||||||||||
| 331 | 0 | ▶ | return wantarray ? () : []; | ||||||||||||||||||||
|
Subroutine
getNamespaceNodes: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||
| 333 | |||||||||||||||||||||||
| 334 | sub getNamespace { | ||||||||||||||||||||||
| 335 | 0 | ▶ | return; | ||||||||||||||||||||
|
Subroutine
getNamespace: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||
| 337 | |||||||||||||||||||||||
| 338 | sub getLocalName { | ||||||||||||||||||||||
| 339 | 0 | ▶ | return; | ||||||||||||||||||||
|
Subroutine
getLocalName: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||
| 341 | |||||||||||||||||||||||
| 342 | 0 | ▶ | sub string_value { return; } | ||||||||||||||||||||
|
Subroutine
string_value: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 343 | |||||||||||||||||||||||
| 344 | sub get_pos { | ||||||||||||||||||||||
| 345 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
get_pos: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 346 | 0 | return $self->[XML::XPath::Node::node_pos]; | |||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||
| 348 | |||||||||||||||||||||||
| 349 | sub set_pos { | ||||||||||||||||||||||
| 350 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
set_pos: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 351 | 0 | $self->[XML::XPath::Node::node_pos] = shift; | |||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||
| 353 | |||||||||||||||||||||||
| 354 | sub get_global_pos { | ||||||||||||||||||||||
| 355 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
get_global_pos: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 356 | 0 | return $self->[XML::XPath::Node::node_global_pos]; | |||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||
| 358 | |||||||||||||||||||||||
| 359 | sub set_global_pos { | ||||||||||||||||||||||
| 360 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
set_global_pos: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 361 | 0 | $self->[XML::XPath::Node::node_global_pos] = shift; | |||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||
| 363 | |||||||||||||||||||||||
| 364 | sub renumber { | ||||||||||||||||||||||
| 365 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
renumber: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 366 | 0 | my $search = shift; | |||||||||||||||||||||
| 367 | 0 | my $diff = shift; | |||||||||||||||||||||
| 368 | |||||||||||||||||||||||
| 369 | 0 | foreach my $node ($self->findnodes($search)) { | |||||||||||||||||||||
| 370 | 0 | $node->set_global_pos( | |||||||||||||||||||||
| 371 | $node->get_global_pos + $diff | ||||||||||||||||||||||
| 372 | ); | ||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||
| 375 | |||||||||||||||||||||||
| 376 | sub insertAfter { | ||||||||||||||||||||||
| 377 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
insertAfter: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||
| 378 | 0 | my $newnode = shift; | |||||||||||||||||||||
| 379 | 0 | my $posnode = shift; | |||||||||||||||||||||
| 380 | |||||||||||||||||||||||
| 381 | 0 | my $pos_number = eval { $posnode->[XML::XPath::Node::node_children][-1]->get_global_pos() + 1; }; | |||||||||||||||||||||
| 382 | 0 | ▶ | if (!defined $pos_number) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 383 | 0 | $pos_number = $posnode->get_global_pos() + 1; | |||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||
| 385 | |||||||||||||||||||||||
| 386 | 0 | eval { | |||||||||||||||||||||
| 387 | 0 | ▶ | if ($pos_number == | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 388 | $posnode->findnodes( | ||||||||||||||||||||||
| 389 | 'following::node()' | ||||||||||||||||||||||
| 390 | )->get_node(1)->get_global_pos()) { | ||||||||||||||||||||||
| 391 | 0 | $posnode->renumber('following::node()', +5); | |||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||
| 393 | }; | ||||||||||||||||||||||
| 394 | |||||||||||||||||||||||
| 395 | 0 | my $pos = $posnode->get_pos; | |||||||||||||||||||||
| 396 | |||||||||||||||||||||||
| 397 | 0 | $newnode->setParentNode($self); | |||||||||||||||||||||
| 398 | 0 | splice @{$self->[XML::XPath::Node::node_children]}, $pos + 1, 0, $newnode; | |||||||||||||||||||||
| 399 | |||||||||||||||||||||||
| 400 | 0 | ▶ | for (my $i = $pos + 1; $i < @{$self->[XML::XPath::Node::node_children]}; $i++) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 401 | 0 | $self->[XML::XPath::Node::node_children][$i]->set_pos($i); | |||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||
| 403 | |||||||||||||||||||||||
| 404 | 0 | $newnode->set_global_pos($pos_number); | |||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||
| 406 | |||||||||||||||||||||||
| 407 | sub insertBefore { | ||||||||||||||||||||||
| 408 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
insertBefore: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||
| 409 | 0 | my $newnode = shift; | |||||||||||||||||||||
| 410 | 0 | my $posnode = shift; | |||||||||||||||||||||
| 411 | |||||||||||||||||||||||
| 412 | 0 | ▶ | my $pos_number = ($posnode->getPreviousSibling() || $posnode->getParentNode)->get_global_pos(); | ||||||||||||||||||||
|
Condition0%0/3
$posnode->getPreviousSibling || $posnode->getParentNode
MC/DC0%0/2
$posnode->getPreviousSibling || $posnode->getParentNode
$posnode->getPreviousSibling
$posnode->getParentNode
Truth table0%0/3
A || B
A= $posnode->getPreviousSiblingB= $posnode->getParentNode
| |||||||||||||||||||||||
| 413 | 0 | ▶ | if ($pos_number == $posnode->get_global_pos()) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 414 | 0 | $posnode->renumber('self::node() | descendant::node() | following::node()', +5); | |||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||
| 416 | |||||||||||||||||||||||
| 417 | 0 | my $pos = $posnode->get_pos; | |||||||||||||||||||||
| 418 | |||||||||||||||||||||||
| 419 | 0 | $newnode->setParentNode($self); | |||||||||||||||||||||
| 420 | 0 | splice @{$self->[XML::XPath::Node::node_children]}, $pos, 0, $newnode; | |||||||||||||||||||||
| 421 | |||||||||||||||||||||||
| 422 | 0 | ▶ | for (my $i = $pos; $i < @{$self->[XML::XPath::Node::node_children]}; $i++) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 423 | 0 | $self->[XML::XPath::Node::node_children][$i]->set_pos($i); | |||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||
| 425 | |||||||||||||||||||||||
| 426 | 0 | $newnode->set_global_pos($pos_number); | |||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||
| 428 | |||||||||||||||||||||||
| 429 | sub getPreviousSibling { | ||||||||||||||||||||||
| 430 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
getPreviousSibling: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 431 | 0 | my $pos = $self->[XML::XPath::Node::node_pos]; | |||||||||||||||||||||
| 432 | 0 | ▶ | return unless $self->[XML::XPath::Node::node_parent]; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 433 | 0 | return $self->[XML::XPath::Node::node_parent]->getChildNode($pos); | |||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||
| 435 | |||||||||||||||||||||||
| 436 | sub getNextSibling { | ||||||||||||||||||||||
| 437 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
getNextSibling: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 438 | 0 | my $pos = $self->[XML::XPath::Node::node_pos]; | |||||||||||||||||||||
| 439 | 0 | ▶ | return unless $self->[XML::XPath::Node::node_parent]; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 440 | 0 | return $self->[XML::XPath::Node::node_parent]->getChildNode($pos + 2); | |||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||
| 442 | |||||||||||||||||||||||
| 443 | sub setParentNode { | ||||||||||||||||||||||
| 444 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
setParentNode: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 445 | 0 | my $parent = shift; | |||||||||||||||||||||
| 446 | # warn "SetParent of ", ref($self), " to ", $parent->[XML::XPath::Node::node_name], "\n"; | ||||||||||||||||||||||
| 447 | 0 | $self->[XML::XPath::Node::node_parent] = $parent; | |||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||
| 449 | |||||||||||||||||||||||
| 450 | sub del_parent_link { | ||||||||||||||||||||||
| 451 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
del_parent_link: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 452 | 0 | $self->[XML::XPath::Node::node_parent] = undef; | |||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||
| 454 | |||||||||||||||||||||||
| 455 | sub dispose { | ||||||||||||||||||||||
| 456 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
dispose: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||
| 457 | 0 | foreach my $kid ($self->getChildNodes) { | |||||||||||||||||||||
| 458 | 0 | $kid->dispose; | |||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||
| 460 | 0 | foreach my $kid ($self->getAttributeNodes) { | |||||||||||||||||||||
| 461 | 0 | $kid->dispose; | |||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||
| 463 | 0 | foreach my $kid ($self->getNamespaceNodes) { | |||||||||||||||||||||
| 464 | 0 | $kid->dispose; | |||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||
| 466 | 0 | $self->[XML::XPath::Node::node_parent] = undef; | |||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||
| 468 | |||||||||||||||||||||||
| 469 | sub to_number { | ||||||||||||||||||||||
| 470 | 0 | ▶ | my $num = shift->string_value; | ||||||||||||||||||||
|
Subroutine
to_number: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 471 | 0 | return XML::XPath::Number->new($num); | |||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||
| 473 | |||||||||||||||||||||||
| 474 | sub find { | ||||||||||||||||||||||
| 475 | 0 | ▶ | my $node = shift; | ||||||||||||||||||||
|
Subroutine
find: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 476 | 0 | my ($path) = @_; | |||||||||||||||||||||
| 477 | 0 | my $xp = XML::XPath->new(); # new is v. lightweight | |||||||||||||||||||||
| 478 | 0 | return $xp->find($path, $node); | |||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||
| 480 | |||||||||||||||||||||||
| 481 | sub findvalue { | ||||||||||||||||||||||
| 482 | 0 | ▶ | my $node = shift; | ||||||||||||||||||||
|
Subroutine
findvalue: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 483 | 0 | my ($path) = @_; | |||||||||||||||||||||
| 484 | 0 | my $xp = XML::XPath->new(); | |||||||||||||||||||||
| 485 | 0 | return $xp->findvalue($path, $node); | |||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||
| 487 | |||||||||||||||||||||||
| 488 | sub findnodes { | ||||||||||||||||||||||
| 489 | 0 | ▶ | my $node = shift; | ||||||||||||||||||||
|
Subroutine
findnodes: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 490 | 0 | my ($path) = @_; | |||||||||||||||||||||
| 491 | 0 | my $xp = XML::XPath->new(); | |||||||||||||||||||||
| 492 | 0 | return $xp->findnodes($path, $node); | |||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||
| 494 | |||||||||||||||||||||||
| 495 | sub matches { | ||||||||||||||||||||||
| 496 | 0 | ▶ | my $node = shift; | ||||||||||||||||||||
|
Subroutine
matches: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 497 | 0 | my ($path, $context) = @_; | |||||||||||||||||||||
| 498 | 0 | my $xp = XML::XPath->new(); | |||||||||||||||||||||
| 499 | 0 | return $xp->matches($node, $path, $context); | |||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||
| 501 | |||||||||||||||||||||||
| 502 | sub to_sax { | ||||||||||||||||||||||
| 503 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
to_sax: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||
| 504 | 0 | ▶ | unshift @_, 'Handler' if @_ == 1; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 505 | 0 | my %handlers = @_; | |||||||||||||||||||||
| 506 | |||||||||||||||||||||||
| 507 | 0 | ▶ | my $doch = $handlers{DocumentHandler} || $handlers{Handler}; | ||||||||||||||||||||
|
Condition0%0/3
$handlers{'DocumentHandler'} || $handlers{'Handler'}
MC/DC0%0/2
$handlers{'DocumentHandler'} || $handlers{'Handler'}
$handlers{'DocumentHandler'}
$handlers{'Handler'}
Truth table0%0/3
A || B
A= $handlers{'DocumentHandler'}B= $handlers{'Handler'}
| |||||||||||||||||||||||
| 508 | 0 | ▶ | my $dtdh = $handlers{DTDHandler} || $handlers{Handler}; | ||||||||||||||||||||
|
Condition0%0/3
$handlers{'DTDHandler'} || $handlers{'Handler'}
MC/DC0%0/2
$handlers{'DTDHandler'} || $handlers{'Handler'}
$handlers{'DTDHandler'}
$handlers{'Handler'}
Truth table0%0/3
A || B
A= $handlers{'DTDHandler'}B= $handlers{'Handler'}
| |||||||||||||||||||||||
| 509 | 0 | ▶ | my $enth = $handlers{EntityResolver} || $handlers{Handler}; | ||||||||||||||||||||
|
Condition0%0/3
$handlers{'EntityResolver'} || $handlers{'Handler'}
MC/DC0%0/2
$handlers{'EntityResolver'} || $handlers{'Handler'}
$handlers{'EntityResolver'}
$handlers{'Handler'}
Truth table0%0/3
A || B
A= $handlers{'EntityResolver'}B= $handlers{'Handler'}
| |||||||||||||||||||||||
| 510 | |||||||||||||||||||||||
| 511 | 0 | $self->_to_sax ($doch, $dtdh, $enth); | |||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||
| 513 | |||||||||||||||||||||||
| 514 | ▶ | sub DESTROY {} | |||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 515 | |||||||||||||||||||||||
| 516 | 1 | ▶ | use Carp; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 517 | |||||||||||||||||||||||
| 518 | sub _to_sax { | ||||||||||||||||||||||
| 519 | 0 | ▶ | carp "_to_sax not implemented in ", ref($_[0]); | ||||||||||||||||||||
|
Subroutine
_to_sax: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||
| 521 | |||||||||||||||||||||||
| 522 | 1 | 1; | |||||||||||||||||||||
| 523 | __END__ | ||||||||||||||||||||||