| 1 | # $Id: LibXML.pm,v 1.15 2005/05/12 15:04:58 pajas Exp $ | ||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||
| 3 | package XML::XUpdate::LibXML; | ||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use XML::LibXML; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use XML::LibXML::XPathContext; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use vars qw(@ISA $debug $VERSION); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 11 | 1 | $debug=0; | |||||||||||||||||||||||||||||||||||
| 12 | 1 | $VERSION = '0.6.0'; | |||||||||||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub strip_space { | ||||||||||||||||||||||||||||||||||
|
Subroutine
strip_space: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 16 | 0 | my ($text)=@_; | |||||||||||||||||||||||||||||||||||
| 17 | 0 | $text=~s/^\s*//; | |||||||||||||||||||||||||||||||||||
| 18 | 0 | $text=~s/\s*$//; | |||||||||||||||||||||||||||||||||||
| 19 | 0 | return $text; | |||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | my $class=(ref($_[0]) || $_[0]); | ||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||||||||||||||||||
| 24 | 0 | my $var_pool = {}; | |||||||||||||||||||||||||||||||||||
| 25 | 0 | my $xpc = XML::LibXML::XPathContext->new(); | |||||||||||||||||||||||||||||||||||
| 26 | 0 | $xpc->registerVarLookupFunc(\&_get_var,$var_pool); | |||||||||||||||||||||||||||||||||||
| 27 | 0 | return bless [$var_pool, | |||||||||||||||||||||||||||||||||||
| 28 | "http://www.xmldb.org/xupdate", | ||||||||||||||||||||||||||||||||||||
| 29 | $xpc | ||||||||||||||||||||||||||||||||||||
| 30 | ], $class; | ||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub registerNs { | ||||||||||||||||||||||||||||||||||
|
Subroutine
registerNs: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 34 | 0 | my ($self,$prefix, $uri)=@_; | |||||||||||||||||||||||||||||||||||
| 35 | 0 | $self->[2]->registerNs($prefix,$uri); | |||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 39 | 0 | my ($self,$doc)=@_; | |||||||||||||||||||||||||||||||||||
| 40 | 0 | $self->[2]->setContextNode($doc); | |||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub _context { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_context: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 44 | 0 | my ($self,$name,$value)=@_; | |||||||||||||||||||||||||||||||||||
| 45 | 0 | return $self->[2]; | |||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub _set_var { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_set_var: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||
| 49 | 0 | my ($self,$name,$value)=@_; | |||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | print STDERR "DEBUG: Storing $name as ",ref($value),"\n" if $debug; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 51 | 0 | $self->[0]->{$name}=$value; | |||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub _get_var { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_get_var: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 55 | 0 | my ($data,$name)=@_; | |||||||||||||||||||||||||||||||||||
| 56 | 0 | return $data->{$name}; | |||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub set_namespace { | ||||||||||||||||||||||||||||||||||
|
Subroutine
set_namespace: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 60 | 0 | my ($self,$URI)=@_; | |||||||||||||||||||||||||||||||||||
| 61 | 0 | $self->[1]=$URI; | |||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub namespace { | ||||||||||||||||||||||||||||||||||
|
Subroutine
namespace: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 65 | 0 | my ($self)=@_; | |||||||||||||||||||||||||||||||||||
| 66 | 0 | return $self->[1]; | |||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub process { | ||||||||||||||||||||||||||||||||||
|
Subroutine
process: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 70 | 0 | my ($self,$dom,$updoc)=@_; | |||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | return unless ref($self); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||
| 73 | 0 | $self->init($dom); | |||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | print STDERR "DEBUG: Updating ",$dom->nodeName,"\n" if $debug; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 75 | 0 | foreach my $command ($updoc->getDocumentElement()->childNodes()) { | |||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ($command->nodeType == XML::LibXML::XML_ELEMENT_NODE) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if (lc($command->getNamespaceURI()) eq $self->namespace()) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | print STDERR "DEBUG: applying ",$command->toString(),"\n" if $debug; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 80 | 0 | $self->xupdate_command($dom,$command); | |||||||||||||||||||||||||||||||||||
| 81 | } else { | ||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | print STDERR "DEBUG: Ignorint element ",$command->toString(),"\n" if $debug; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub get_text { | ||||||||||||||||||||||||||||||||||
|
Subroutine
get_text: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 90 | 0 | my ($self,$node)=@_; | |||||||||||||||||||||||||||||||||||
| 91 | 0 | my $text=""; | |||||||||||||||||||||||||||||||||||
| 92 | 0 | foreach ($node->childNodes()) { | |||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if ($_->nodeType() == XML::LibXML::XML_TEXT_NODE || | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_->nodeType == 3 or $_->nodeType == 4
MC/DC0%0/2
$_->nodeType == 3 or $_->nodeType == 4
$_->nodeType == 3
$_->nodeType == 4
Truth table0%0/3
A or B
A= $_->nodeType == 3B= $_->nodeType == 4
| |||||||||||||||||||||||||||||||||||||
| 94 | $_->nodeType() == XML::LibXML::XML_CDATA_SECTION_NODE) { | ||||||||||||||||||||||||||||||||||||
| 95 | 0 | $text.=$_->getData(); | |||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||
| 98 | 0 | return strip_space($text); | |||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub add_attribute { | ||||||||||||||||||||||||||||||||||
|
Subroutine
add_attribute: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 102 | 0 | my ($self, $node, $attr_node)=@_; | |||||||||||||||||||||||||||||||||||
| 103 | 0 | $node->setAttributeNS($attr_node->getNamespaceURI, | |||||||||||||||||||||||||||||||||||
| 104 | $attr_node->getName(), | ||||||||||||||||||||||||||||||||||||
| 105 | $attr_node->getValue); | ||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | sub append { | ||||||||||||||||||||||||||||||||||
|
Subroutine
append: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 109 | 0 | my ($self,$node,$results)=@_; | |||||||||||||||||||||||||||||||||||
| 110 | 0 | foreach (@$results) { | |||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if ($_->nodeType == XML::LibXML::XML_ATTRIBUTE_NODE) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 112 | 0 | $self->add_attribute($node,$_); | |||||||||||||||||||||||||||||||||||
| 113 | } else { | ||||||||||||||||||||||||||||||||||||
| 114 | 0 | $node->appendChild($_); | |||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub insert_after { | ||||||||||||||||||||||||||||||||||
|
Subroutine
insert_after: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 120 | 0 | my ($self,$node,$results)=@_; | |||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ($node->nodeType == XML::LibXML::XML_ATTRIBUTE_NODE) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 123 | 0 | $self->append($node->getOwnerElement(),$results); | |||||||||||||||||||||||||||||||||||
| 124 | } else { | ||||||||||||||||||||||||||||||||||||
| 125 | 0 | foreach (reverse @$results) { | |||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | if ($_->nodeType == XML::LibXML::XML_ATTRIBUTE_NODE) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 127 | 0 | $self->add_attribute($node->parentNode(),$_); | |||||||||||||||||||||||||||||||||||
| 128 | } else { | ||||||||||||||||||||||||||||||||||||
| 129 | 0 | $node->parentNode()->insertAfter($_,$node); | |||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | sub insert_before { | ||||||||||||||||||||||||||||||||||
|
Subroutine
insert_before: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 136 | 0 | my ($self,$node,$results)=@_; | |||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | if ($node->nodeType == XML::LibXML::XML_ATTRIBUTE_NODE) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 138 | 0 | $self->append($node->getOwnerElement(),$results); | |||||||||||||||||||||||||||||||||||
| 139 | } else { | ||||||||||||||||||||||||||||||||||||
| 140 | 0 | foreach (@$results) { | |||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | if ($_->nodeType == XML::LibXML::XML_ATTRIBUTE_NODE) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 142 | 0 | $self->add_attribute($node->parentNode(),$_); | |||||||||||||||||||||||||||||||||||
| 143 | } else { | ||||||||||||||||||||||||||||||||||||
| 144 | 0 | $node->parentNode()->insertBefore($_,$node); | |||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | sub append_child { | ||||||||||||||||||||||||||||||||||
|
Subroutine
append_child: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 151 | 0 | my ($self,$node,$results,$child)=@_; | |||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | return unless @$results; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | if ($child ne "") { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 154 | # XUpdate WD is weird: | ||||||||||||||||||||||||||||||||||||
| 155 | # child=1 should mean make the new node 1st child | ||||||||||||||||||||||||||||||||||||
| 156 | # child=last() should mean make new node last child | ||||||||||||||||||||||||||||||||||||
| 157 | # but if there are n children before insertion, | ||||||||||||||||||||||||||||||||||||
| 158 | # last() evaluates to n but they want the new node | ||||||||||||||||||||||||||||||||||||
| 159 | # to be (n+1)th. | ||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||
| 161 | # so we must add it first, then calculate the position: | ||||||||||||||||||||||||||||||||||||
| 162 | 0 | my $ctxt = $self->_context(); | |||||||||||||||||||||||||||||||||||
| 163 | 0 | $self->append($node,$results); | |||||||||||||||||||||||||||||||||||
| 164 | 0 | my ($ref)=$ctxt->findnodes("node()[$child]",$node); | |||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | return unless $ref; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 166 | # check whether we should move results before $ref node | ||||||||||||||||||||||||||||||||||||
| 167 | 0 | foreach (@$results) { | |||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | return if $ref->isSameNode($_); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||
| 170 | # now move them | ||||||||||||||||||||||||||||||||||||
| 171 | 0 | foreach (@$results) { | |||||||||||||||||||||||||||||||||||
| 172 | 0 | $_->unbindNode(); | |||||||||||||||||||||||||||||||||||
| 173 | 0 | $node->insertBefore($_,$ref); | |||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||
| 175 | } else { | ||||||||||||||||||||||||||||||||||||
| 176 | 0 | $self->append($node,$results); | |||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | sub update { | ||||||||||||||||||||||||||||||||||
|
Subroutine
update: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 181 | 0 | my ($self,$node,$results)=@_; | |||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | if ($node->nodeType == XML::LibXML::XML_TEXT_NODE || | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
$node->nodeType == 3 or $node->nodeType == 4
MC/DC0%0/2
$node->nodeType == 3 or $node->nodeType == 4
$node->nodeType == 3
$node->nodeType == 4
Truth table0%0/3
A or B
A= $node->nodeType == 3B= $node->nodeType == 4
| |||||||||||||||||||||||||||||||||||||
| 184 | $node->nodeType == XML::LibXML::XML_CDATA_SECTION_NODE) { | ||||||||||||||||||||||||||||||||||||
| 185 | 0 | $self->insert_after($node,$results); | |||||||||||||||||||||||||||||||||||
| 186 | 0 | $node->unbindNode(); | |||||||||||||||||||||||||||||||||||
| 187 | ▶ | } elsif ($node->nodeType == XML::LibXML::XML_ATTRIBUTE_NODE || | |||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$node->nodeType == 2 or $node->nodeType == 7
MC/DC0%0/2
$node->nodeType == 2 or $node->nodeType == 7
$node->nodeType == 2
$node->nodeType == 7
Truth table0%0/3
A or B
A= $node->nodeType == 2B= $node->nodeType == 7
| |||||||||||||||||||||||||||||||||||||
| 188 | $node->nodeType == XML::LibXML::XML_PI_NODE) { | ||||||||||||||||||||||||||||||||||||
| 189 | 0 | $node->setValue(strip_space(join "", map { $_->to_literal() } @$results)); | |||||||||||||||||||||||||||||||||||
| 190 | } elsif ($node->nodeType == XML::LibXML::XML_ELEMENT_NODE) { | ||||||||||||||||||||||||||||||||||||
| 191 | 0 | foreach ($node->childNodes()){ | |||||||||||||||||||||||||||||||||||
| 192 | 0 | $_->unbindNode(); | |||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||
| 194 | 0 | $self->append($node,$results); | |||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | sub remove { | ||||||||||||||||||||||||||||||||||
|
Subroutine
remove: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 199 | 0 | my ($self, $node)=@_; | |||||||||||||||||||||||||||||||||||
| 200 | 0 | $node->unbindNode(); | |||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | sub rename { | ||||||||||||||||||||||||||||||||||
|
Subroutine
rename: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 204 | 0 | my ($self,$node,$name)=@_; | |||||||||||||||||||||||||||||||||||
| 205 | 0 | $node->setName($name); | |||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | sub process_instructions { | ||||||||||||||||||||||||||||||||||
|
Subroutine
process_instructions: not called CC=18 SCAR=58.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 209 | 0 | my ($self, $dom, $command)=@_; | |||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||
| 211 | 0 | my @result=(); | |||||||||||||||||||||||||||||||||||
| 212 | 0 | foreach my $inst ($command->childNodes()) { | |||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | print STDERR "DEBUG: Instruction ",$command->toString(),"\n" if $debug; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | if ( $inst->nodeType == XML::LibXML::XML_ELEMENT_NODE ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | if ( $inst->getLocalName() eq 'element' ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||
| 216 | 0 | my $new; | |||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | if ($inst->hasAttribute('namespace') and | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$inst->hasAttribute("namespace") and $inst->getAttribute("name") =~ /:/
MC/DC0%0/2
$inst->hasAttribute("namespace") and $inst->getAttribute("name") =~ /:/
$inst->hasAttribute("namespace")
$inst->getAttribute("name") =~ /:/
Truth table0%0/3
A and B
A= $inst->hasAttribute("namespace")B= $inst->getAttribute("name") =~ /:/
| |||||||||||||||||||||||||||||||||||||
| 218 | $inst->getAttribute('name')=~/:/) { | ||||||||||||||||||||||||||||||||||||
| 219 | 0 | $new=$dom->getOwnerDocument()->createElementNS( | |||||||||||||||||||||||||||||||||||
| 220 | $inst->getAttribute('namespace'), | ||||||||||||||||||||||||||||||||||||
| 221 | $inst->getAttribute('name') | ||||||||||||||||||||||||||||||||||||
| 222 | ); | ||||||||||||||||||||||||||||||||||||
| 223 | } else { | ||||||||||||||||||||||||||||||||||||
| 224 | 0 | $new=$dom->getOwnerDocument()->createElement($inst->getAttribute('name')); | |||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||
| 226 | 0 | $self->append($new,$self->process_instructions($dom,$inst)); | |||||||||||||||||||||||||||||||||||
| 227 | 0 | push @result,$new; | |||||||||||||||||||||||||||||||||||
| 228 | } elsif ( $inst->getLocalName() eq 'attribute' ) { | ||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | if ($inst->hasAttribute('namespace') and | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$inst->hasAttribute("namespace") and $inst->getAttribute("name") =~ /:/
MC/DC0%0/2
$inst->hasAttribute("namespace") and $inst->getAttribute("name") =~ /:/
$inst->hasAttribute("namespace")
$inst->getAttribute("name") =~ /:/
Truth table0%0/3
A and B
A= $inst->hasAttribute("namespace")B= $inst->getAttribute("name") =~ /:/
| |||||||||||||||||||||||||||||||||||||
| 230 | $inst->getAttribute('name')=~/:/) { | ||||||||||||||||||||||||||||||||||||
| 231 | 0 | my $att= | |||||||||||||||||||||||||||||||||||
| 232 | $dom->getOwnerDocument()-> | ||||||||||||||||||||||||||||||||||||
| 233 | createAttributeNS( | ||||||||||||||||||||||||||||||||||||
| 234 | $inst->getAttribute('namespace'), | ||||||||||||||||||||||||||||||||||||
| 235 | $inst->getAttribute('name') | ||||||||||||||||||||||||||||||||||||
| 236 | ); | ||||||||||||||||||||||||||||||||||||
| 237 | 0 | $att->setValue($self->get_text($inst)); | |||||||||||||||||||||||||||||||||||
| 238 | 0 | push @result,$att; | |||||||||||||||||||||||||||||||||||
| 239 | } else { | ||||||||||||||||||||||||||||||||||||
| 240 | 0 | my $att= | |||||||||||||||||||||||||||||||||||
| 241 | $dom->getOwnerDocument()-> | ||||||||||||||||||||||||||||||||||||
| 242 | createAttribute( | ||||||||||||||||||||||||||||||||||||
| 243 | $inst->getAttribute('name') | ||||||||||||||||||||||||||||||||||||
| 244 | ); | ||||||||||||||||||||||||||||||||||||
| 245 | 0 | $att->setValue($self->get_text($inst)); | |||||||||||||||||||||||||||||||||||
| 246 | 0 | push @result,$att; | |||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||
| 248 | } elsif ( $inst->getLocalName() eq 'text' ) { | ||||||||||||||||||||||||||||||||||||
| 249 | 0 | push @result,$dom->getOwnerDocument()->createTextNode($self->get_text($inst)); | |||||||||||||||||||||||||||||||||||
| 250 | } elsif ( $inst->getLocalName() eq 'processing-instruction' ) { | ||||||||||||||||||||||||||||||||||||
| 251 | 0 | push @result,$dom->getOwnerDocument()->createProcessingInstruction( | |||||||||||||||||||||||||||||||||||
| 252 | $inst->getAttribute('name'), | ||||||||||||||||||||||||||||||||||||
| 253 | $self->get_text($inst) | ||||||||||||||||||||||||||||||||||||
| 254 | ); | ||||||||||||||||||||||||||||||||||||
| 255 | } elsif ( $inst->getLocalName() eq 'comment' ) { | ||||||||||||||||||||||||||||||||||||
| 256 | 0 | push @result,$dom->getOwnerDocument()->createComment($self->get_text($inst)); | |||||||||||||||||||||||||||||||||||
| 257 | } elsif ( $inst->getLocalName() eq 'value-of' ) { | ||||||||||||||||||||||||||||||||||||
| 258 | 0 | my $value=$self->get_select($dom,$inst); | |||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | if ($value->isa('XML::LibXML::NodeList')) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 260 | 0 | push @result, map { $_->cloneNode(1) }$value->get_nodelist; | |||||||||||||||||||||||||||||||||||
| 261 | } else { | ||||||||||||||||||||||||||||||||||||
| 262 | 0 | push @result,$dom->getOwnerDocument()->createTextNode($value->to_literal()); | |||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||
| 264 | } else { | ||||||||||||||||||||||||||||||||||||
| 265 | # not in XUpdate DTD but in examples of XUpdate WD | ||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | push @result,$dom->getOwnerDocument()->importNode($inst) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 267 | unless (lc($inst->getNamespaceURI) eq $self->namespace()); | ||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||
| 269 | ▶ | } elsif ( $inst->nodeType == XML::LibXML::XML_CDATA_SECTION_NODE || | |||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$inst->nodeType == 4 or $inst->nodeType == 3
MC/DC0%0/2
$inst->nodeType == 4 or $inst->nodeType == 3
$inst->nodeType == 4
$inst->nodeType == 3
Truth table0%0/3
A or B
A= $inst->nodeType == 4B= $inst->nodeType == 3
| |||||||||||||||||||||||||||||||||||||
| 270 | $inst->nodeType == XML::LibXML::XML_TEXT_NODE) { | ||||||||||||||||||||||||||||||||||||
| 271 | 0 | push @result,$dom->getOwnerDocument()->importNode($inst); | |||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||
| 274 | 0 | return \@result; | |||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | sub get_select { | ||||||||||||||||||||||||||||||||||
|
Subroutine
get_select: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 278 | 0 | my ($self,$dom,$node)=@_; | |||||||||||||||||||||||||||||||||||
| 279 | 0 | my $xpath=$node->getAttribute('select'); | |||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | if ($xpath eq "") { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 281 | 0 | die "Error: Required attribute select is missing or empty at:\n". | |||||||||||||||||||||||||||||||||||
| 282 | $node->toString()."\nAborting!\n"; | ||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||
| 284 | 0 | return $self->_context->find($xpath); | |||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | sub get_test { | ||||||||||||||||||||||||||||||||||
|
Subroutine
get_test: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 288 | 0 | my ($self,$dom,$node)=@_; | |||||||||||||||||||||||||||||||||||
| 289 | 0 | my $xpath=$node->getAttribute('test'); | |||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | if ($xpath eq "") { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 291 | 0 | die "Error: Required attribute test is missing or empty at:\n". | |||||||||||||||||||||||||||||||||||
| 292 | $node->toString()."\nAborting!\n"; | ||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||
| 294 | 0 | return $self->_context->find($xpath); | |||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | sub xupdate_command { | ||||||||||||||||||||||||||||||||||
|
Subroutine
xupdate_command: not called CC=25 SCAR=64.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 298 | 0 | my ($self,$dom,$command)=@_; | |||||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | return unless ($command->getType == XML::LibXML::XML_ELEMENT_NODE); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | if ($command->getLocalName() eq 'variable') { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 301 | 0 | my $select=$self->get_select($dom,$command); | |||||||||||||||||||||||||||||||||||
| 302 | 0 | $self->_set_var($command->getAttribute('name'), $select); | |||||||||||||||||||||||||||||||||||
| 303 | } elsif ($command->getLocalName() eq 'if') { | ||||||||||||||||||||||||||||||||||||
| 304 | # xu:if | ||||||||||||||||||||||||||||||||||||
| 305 | 0 | my $test=$self->get_test($dom,$command); | |||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | if ($test) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | print STDERR "DEBUG: Conditional execution of ",$dom->nodeName,"\n" if $debug; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 308 | 0 | foreach my $subcommand ($command->childNodes()) { | |||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | if ($subcommand->nodeType == XML::LibXML::XML_ELEMENT_NODE) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | if (lc($subcommand->getNamespaceURI()) eq $self->namespace()) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | print STDERR "DEBUG: Applying ",$subcommand->toString(),"\n" if $debug; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 313 | 0 | $self->xupdate_command($dom,$subcommand); | |||||||||||||||||||||||||||||||||||
| 314 | } else { | ||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | print STDERR "DEBUG: Ignoring element ",$subcommand->toString(),"\n" if $debug; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||
| 321 | } else { | ||||||||||||||||||||||||||||||||||||
| 322 | 0 | my $select=$self->get_select($dom,$command); | |||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | if ($select->isa('XML::LibXML::NodeList')) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 324 | 0 | my @refnodes=$select->get_nodelist(); | |||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | if (@refnodes) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||
| 327 | # xu:insert-after | ||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | if ($command->getLocalName eq 'insert-after') { | ||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||
| 330 | 0 | foreach (@refnodes) { | |||||||||||||||||||||||||||||||||||
| 331 | 0 | $self->insert_after($_, | |||||||||||||||||||||||||||||||||||
| 332 | $self->process_instructions($dom,$command)); | ||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||
| 335 | # xu:insert-before | ||||||||||||||||||||||||||||||||||||
| 336 | } elsif ($command->getLocalName eq 'insert-before') { | ||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||
| 338 | 0 | foreach (@refnodes) { | |||||||||||||||||||||||||||||||||||
| 339 | 0 | $self->insert_before($_, | |||||||||||||||||||||||||||||||||||
| 340 | $self->process_instructions($dom,$command)); | ||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||
| 343 | # xu:append | ||||||||||||||||||||||||||||||||||||
| 344 | } elsif ($command->getLocalName eq 'append') { | ||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||
| 346 | 0 | foreach (@refnodes) { | |||||||||||||||||||||||||||||||||||
| 347 | 0 | my $results=$self->process_instructions($dom,$command); | |||||||||||||||||||||||||||||||||||
| 348 | 0 | my $child=$command->getAttribute('child'); | |||||||||||||||||||||||||||||||||||
| 349 | 0 | $self->append_child($_,$results,$child); | |||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||
| 352 | # xu:update | ||||||||||||||||||||||||||||||||||||
| 353 | } elsif ($command->getLocalName eq 'update') { | ||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||
| 355 | 0 | foreach (@refnodes) { | |||||||||||||||||||||||||||||||||||
| 356 | 0 | my $results=$self->process_instructions($dom,$command); | |||||||||||||||||||||||||||||||||||
| 357 | # Well, XUpdate WD is not very specific about this. | ||||||||||||||||||||||||||||||||||||
| 358 | # The content of this element should be PCDATA only. | ||||||||||||||||||||||||||||||||||||
| 359 | # I'm extending WD by allowing instruction list. | ||||||||||||||||||||||||||||||||||||
| 360 | 0 | $self->update($_,$results); | |||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||
| 363 | # xu:remove | ||||||||||||||||||||||||||||||||||||
| 364 | } elsif ($command->getLocalName eq 'remove') { | ||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||
| 366 | 0 | foreach (@refnodes) { | |||||||||||||||||||||||||||||||||||
| 367 | 0 | $self->remove($_); | |||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||
| 370 | # xu:rename | ||||||||||||||||||||||||||||||||||||
| 371 | } elsif ($command->getLocalName eq 'rename') { | ||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||
| 373 | 0 | foreach (@refnodes) { | |||||||||||||||||||||||||||||||||||
| 374 | 0 | $self->rename($_,$self->get_text($command)); | |||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||
| 379 | } else { | ||||||||||||||||||||||||||||||||||||
| 380 | 0 | die "XPath does not lead to a nodelist: ",$command->getAttribute('select'),"\n"; | |||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||
| 385 | 1 | 1; | |||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||
| 387 | __END__ | ||||||||||||||||||||||||||||||||||||