Permalink
Browse files

fix for xpath '/' ( XML::LibXML::Document object)

  • Loading branch information...
1 parent 4ea56db commit 1df9c5c19938f73288602d54b3c353ff973be1f0 @tomill committed Feb 9, 2010
Showing with 157 additions and 6 deletions.
  1. +5 −5 lib/Template/Semantic/Document.pm
  2. +152 −1 t/05_value-type.t
View
10 lib/Template/Semantic/Document.pm
@@ -212,7 +212,11 @@ sub _to_node {
sub _replace_node {
my ($self, $node, @replace) = @_;
- if ($node->isa('XML::LibXML::Attr')) {
+ if ($node->isa('XML::LibXML::Element')) {
+ $node->removeChildNodes;
+ $node->addChild($_->cloneNode(1)) for @replace;
+ }
+ elsif ($node->isa('XML::LibXML::Attr')) {
$node->setValue(join "", map { $_->textContent } @replace);
}
elsif ($node->isa('XML::LibXML::Comment')
@@ -222,10 +226,6 @@ sub _replace_node {
elsif ($node->isa('XML::LibXML::Text')) {
$node->setData(join "", map { $_->textContent } @replace);
}
- else {
- $node->removeChildNodes;
- $node->addChild($_->cloneNode(1)) for @replace;
- }
}
sub _serialize_inner {
View
153 t/05_value-type.t
@@ -1014,7 +1014,7 @@ use XML::LibXML;
-=== cdata scalar
+=== cdata x scalar
--- vars
'//text()[2]' => 'xxx > yyy'
--- template
@@ -1203,3 +1203,154 @@ use XML::LibXML;
<![CDATA[BAR]]>
</root>
+
+
+
+=== dom * scalar
+--- note: It is correct behavior to do nothing.
+--- vars
+'/' => 'xxx > yyy'
+--- template
+<div>foo</div>
+--- expected
+<div>foo</div>
+
+=== dom x scalar-ref
+--- note: It is correct behavior to do nothing.
+--- vars
+'/' => \'<b>xxx</b> > yyy'
+--- template
+<div>foo</div>
+--- expected
+<div>foo</div>
+
+=== dom x undef
+--- note: It is correct behavior to do nothing.
+--- vars
+'/' => undef
+--- template
+<div>foo</div>
+--- expected
+<div>foo</div>
+
+=== dom x XML::LibXML::Element
+--- note: It is correct behavior to do nothing.
+--- vars
+use XML::LibXML;
+'/' => do {
+ my $elem = XML::LibXML::Element->new('span');
+ $elem->appendText('foo');
+ $elem;
+}
+--- template
+<div>foo</div>
+--- expected
+<div>foo</div>
+
+=== dom x XML::LibXML::Text
+--- note: It is correct behavior to do nothing.
+--- vars
+use XML::LibXML;
+'/' => XML::LibXML::Text->new('xxx > yyy')
+--- template
+<div>foo</div>
+--- expected
+<div>foo</div>
+
+=== dom x XML::LibXML::Attr
+--- vars
+use XML::LibXML;
+'/' => XML::LibXML::Attr->new('class', 'xxx')
+--- template
+<div>foo</div>
+--- error
+^Can't assign XML::LibXML::Attr to any element
+
+=== dom x XML::LibXML::Comment
+--- note: It is correct behavior to do nothing.
+--- vars
+use XML::LibXML;
+'/' => XML::LibXML::Comment->new('xxx')
+--- template
+<div>foo</div>
+--- expected
+<div>foo</div>
+
+=== dom x XML::LibXML::CDATASection
+--- note: It is correct behavior to do nothing.
+--- vars
+use XML::LibXML;
+'/' => XML::LibXML::CDATASection->new('xxx')
+--- template
+<div>foo</div>
+--- expected
+<div>foo</div>
+
+=== dom x Template::Semantic::Document
+--- vars
+'/' => Template::Semantic->process(\'<span></span>')
+--- template
+<div>foo</div>
+--- error
+^Can't assign Template::Semantic::Document to XML::LibXML::Document
+
+=== dom x hashref
+--- vars
+'/' => {
+ '/span' => 'xxx',
+}
+--- template
+<div>foo</div>
+--- error
+^Can't assign hashref to XML::LibXML::Document
+
+=== dom x list
+--- note: It is correct behavior to do nothing.
+--- vars
+'/' => [
+ { '/li' => 'AAA' },
+ { '/li' => 'BBB' },
+]
+--- template
+<div>foo</div>
+--- error
+^Can't assign loop list to XML::LibXML::Document
+
+=== dom x sub (using $_)
+--- note: It is correct behavior to do nothing.
+--- vars
+'/' => sub { uc }
+--- template
+<div>foo</div>
+--- expected
+<div>foo</div>
+
+=== dom x sub (using @_)
+--- vars
+'/' => sub {
+ my $dom = shift;
+ die $dom->encoding;
+}
+--- template
+<?xml version="1.0" encoding="UTF-8"?>
+<div>foo</div>
+--- error
+^Callback error: UTF-8
+
+=== dom x sub (do nothing)
+--- vars
+'/' => sub { \$_ }
+--- template
+<div>foo</div>
+--- expected
+<div>foo</div>
+
+=== dom x filter
+--- note: It is correct behavior to do nothing.
+--- vars
+'/' => [ ' bar ', sub { uc }, 'trim' ]
+--- template
+<div>foo</div>
+--- expected
+<div>foo</div>
+

0 comments on commit 1df9c5c

Please sign in to comment.