Skip Menu |

This queue is for tickets about the HTML-TreeBuilder-XPath CPAN distribution.

Report information
The Basics
Id: 45248
Status: resolved
Priority: 0/
Queue: HTML-TreeBuilder-XPath

People
Owner: Nobody in particular
Requestors: DAKKAR [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.09
Fixed in: (no value)



Subject: HTML::TreeBuilder::XPath::Root lacks a few methods
the helper "Root" class should implement the whole interface for XML::XPathEngine, so that we can invoke 'findnodes' etc on any node obtained by another call to 'findnodes' Find a patch attached (with tests)
Subject: HTML-TreeBuilder-XPath-root.patch
diff --git a/lib/HTML/TreeBuilder/XPath.pm b/lib/HTML/TreeBuilder/XPath.pm index 9f15450..3d0feaf 100644 --- a/lib/HTML/TreeBuilder/XPath.pm +++ b/lib/HTML/TreeBuilder/XPath.pm @@ -336,6 +336,10 @@ sub getParentNode { return (); } sub getChildNodes { my @content= ( $_[0]->{_root}); return wantarray ? @content : \@content; } sub getAttributes { return [] } sub isDocumentNode { return 1 } +sub getRootNode { return $_[0] } +sub getName { return } +sub getNextSibling { return } +sub getPreviousSibling { return } # added to provide element-like methods to root, for use by cmp sub lineage { return ($_[0]); } diff --git a/t/HTML-TreeBuilder-XPath.t b/t/HTML-TreeBuilder-XPath.t index 33e818c..d1e91f1 100644 --- a/t/HTML-TreeBuilder-XPath.t +++ b/t/HTML-TreeBuilder-XPath.t @@ -3,7 +3,7 @@ ######################### -use Test::More tests => 19; +use Test::More tests => 25; BEGIN { use_ok('HTML::TreeBuilder::XPath') }; ######################### @@ -55,6 +55,18 @@ is( $html->findvalue('id("foo")'), 'spans', 'id function'); is( $html->findvalue('id("foo")/@id'), 'foo', 'id function (attribute)'); } +{ +# test for root +my ($fake_root)=$html->findnodes('/'); +ok( !$fake_root->getParentNode => "fake root does not have a parent"); +is( $fake_root->getRootNode, $fake_root, "fake root is its own root"); +ok( !@{$fake_root->getAttributes} => "fake root has no attributes"); +ok( !defined($fake_root->getName) => "fake root does not have a name"); +ok( !defined($fake_root->getNextSibling) => "fake root does not have a next sibling"); +ok( !defined($fake_root->getPreviousSibling) => "fake root does not have a prev sibling"); + +} + __END__ /html/body/h1 1 Example header //@id[.="toto"] 2 toto
The patch has been applied in version 0.10. Thank you.