p1
f1
p2
f2
f3
}; my $tree = HTML::TreeBuilder->new_from_content( $html); test_q( $tree, q{//p[@class="c1"]}, "p1p2"); test_q( $tree, q{//p[@class="c1"]/following::p[1]}, "f1f2"); test_q( $tree, q{//body/descendant::p[1]}, "p1"); test_q( $tree, q{//body/descendant::p[2]}, "f1"); test_q( $tree, q{//body/descendant::p[3]}, "p2"); test_q( $tree, q{//body/descendant::p[4]}, "f2"); test_q( $tree, q{//body/descendant::p[5]}, "f3"); test_q( $tree, q{//body/descendant::p[6]}, "" ); test_q( $tree, q{//body/p[1]}, "p1"); test_q( $tree, q{//body/p[2]}, "f1"); test_q( $tree, q{//body/p[3]}, "p2"); test_q( $tree, q{//body/p[4]}, "f2"); test_q( $tree, q{//body/p[5]}, "f3"); test_q( $tree, q{//body/p[6]}, "" ); test_q( $tree, q{//body//p[1]}, "p1"); test_q( $tree, q{//body//p[2]}, "f1"); test_q( $tree, q{//body//p[3]}, "p2"); test_q( $tree, q{//body//p[4]}, "f2"); test_q( $tree, q{//body//p[5]}, "f3"); test_q( $tree, q{//body//p[6]}, "" ); test_q( $tree, q{//p[1]}, "p1"); test_q( $tree, q{//p[2]}, "f1"); test_q( $tree, q{//p[3]}, "p2"); test_q( $tree, q{//p[4]}, "f2"); test_q( $tree, q{//p[5]}, "f3"); test_q( $tree, q{//p[6]}, "" ); test_q( $tree, q{//a/following::p}, "p1f1p2f2f3"); test_q( $tree, q{//p[@class="c1"][1]}, "p1"); test_q( $tree, q{//p[@class="c1"][2]}, "p2"); test_q( $tree, q{//a/following::p[1]}, "p1"); test_q( $tree, q{//a/following::p[2]}, "f1"); test_q( $tree, q{//a/following::p[3]}, "p2"); test_q( $tree, q{//a/following::p[4]}, "f2"); test_q( $tree, q{//a/following::p[5]}, "f3"); test_q( $tree, q{//p[@id="ip1"]/following::p[1]}, "f1"); test_q( $tree, q{//p[@id="ip1"][1]/following::p[1]}, "f1"); test_q( $tree, q{//p[@id="ip1"][1]/following::p[2]}, "p2"); test_q( $tree, q{//p[@id="ip1"][1]/following::p[3]}, "f2"); test_q( $tree, q{//p[@id="ip1"][1]/following::p[4]}, "f3"); test_q( $tree, q{//p[@id="ip3"]/following::p[1]}, "f2"); test_q( $tree, q{//p[@id="ip3"]/following::p[2]}, "f3"); test_q( $tree, q{//p[@class="c1"][1]/following::p[1]}, "f1"); test_q( $tree, q{//p[@class="c1"][1]/following::p[2]}, "p2"); test_q( $tree, q{//p[@class="c1"][1]/following::p[3]}, "f2"); test_q( $tree, q{//p[@class="c1"][1]/following::p[4]}, "f3"); test_q( $tree, q{//p[@class="c1"][2]/following::p[1]}, "f2"); test_q( $tree, q{//p[@class="c1"][2]/following::p[2]}, "f3"); sub test_q { my( $tree, $query, $expected)= @_; my $class= ref( $tree); is( $tree->findvalue( $query), $expected, "$class: $query ($expected)"); } HTML-TreeBuilder-XPath-0.14/t/pod_coverage.t 0000644 0001750 0001750 00000000462 11444212634 020762 0 ustar mrodrigu mrodrigu # $Id: /html-treebuilder-xpath/t/pod_coverage.t 40 2006-05-15T07:42:34.182385Z mrodrigu $ eval "use Test::Pod::Coverage 1.00 tests => 1"; if( $@) { print "1..1\nok 1\n"; warn "Test::Pod::Coverage 1.00 required for testing POD coverage"; exit; } pod_coverage_ok( "HTML::TreeBuilder::XPath"); HTML-TreeBuilder-XPath-0.14/t/HTML-TreeBuilder-XPath.t 0000644 0001750 0001750 00000007314 11444212634 022322 0 ustar mrodrigu mrodrigu # Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl HTML-TreeBuilder-XPath.t' ######################### use Test::More tests => 29; BEGIN { use_ok('HTML::TreeBuilder::XPath') }; ######################### my $doc='Intro p1
Intro p2
Intro p3 with bold text
para including links, more links, and even spans, several, and that is all folks.
0'; my $html= HTML::TreeBuilder::XPath->new_from_content( $doc); is( $html->findvalue( '//p[@id]/@id'), 'toto', 'attribute value'); is( $html->findvalue( '//title'), 'Example', 'element text'); is( $html->findvalue( '//span[1]'), 'spans', '[1]'); is( $html->findvalue( '/html/body//p[@id="toto"]/*[@id="bar"]/@class'), 'myspan', 'attribute'); is( $html->findvalue( '//p[@id="toto"]/text()[2]'), ', ', 'text node'); # test sorting is( $html->findvalue( '//*[@id="foo"]/@*'), 'myspanfoo', '2 atts on same element'); is( $html->findvalue( '//*[@id="foo"]/@id|//*[@id="foo"]/@class'), 'myspanfoo', '2 atts on same element'); is( $html->findvalue( '//*[@id="foo"]/@class|//*[@id="foo"]/@id'), 'myspanfoo', '2 atts on same element (unsorted)'); is( $html->findvalue( '//b'), 'boldall', '2 texts'); is( join( '|', $html->findvalues( '//b')), 'bold|all', '2 texts with findvalues'); is( join( '|', $html->findnodes_as_strings( '//b')), 'bold|all', '2 texts with findnodes_as_strings'); is( join( '|', $html->findvalues( '//a/@href')), 'http://foo.com/|/bar/', '2 texts with findvalues'); is( join( '|', $html->findnodes_as_strings( '//a/@href')), 'http://foo.com/|/bar/', '2 texts with findnodes_as_strings'); is( $html->findvalue( '//p[@id="toto"]/a'), 'linksmore links', '2 siblings'); is( $html->findvalue( '//p[@id="toto"]/a[1]|//p[@id="toto"]/a[2]'), 'linksmore links', '2 siblings'); is( $html->findvalue( '//@id[.="toto"]|//*[@id="bar"]|/html/body/h1|//@id[.="toto"]/../a[1]|//*[@id="foo"]'), 'Example headertotolinksspansseveral', 'query on various types of nodes'); is( $html->findvalue( './/*[@bgcolor="0"]'),'0', 'one child has a value of "0"'); { my $p= $html->findnodes( '//p[@id="toto"]')->[0]; is( $p->findvalue( './a'), 'linksmore links', 'query on siblings of an element'); is( $p->findvalue( './a[1]|./a[2]'), 'linksmore links', 'query on siblings of an element (ordered)'); is( $p->findvalue( './a[2]|./a[1]'), 'linksmore links', 'query on siblings of an element (not ordered)'); 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 //@id[.="toto"]/../a[1] 3 links //*[@id="foo"] 4 spans //*[@id="bar"] 5 several HTML-TreeBuilder-XPath-0.14/t/test_preceding.t 0000644 0001750 0001750 00000001327 11444212634 021325 0 ustar mrodrigu mrodrigu #!/usr/bin/perl use strict; use warnings; use HTML::TreeBuilder::XPath; use Test::More tests => 3; my $html=q{
p1
f1
p2
f2
f3
}; my $tree = HTML::TreeBuilder->new_from_content( $html); test_q( $tree, q{//p[@class="c1"][2]/preceding::p[1]}, "f1"); test_q( $tree, q{//p[@class="c1"][2]/preceding::p[2]}, "p1"); test_q( $tree, q{//p[@class="c1"][2]/preceding::p}, "p1f1"); sub test_q { my( $tree, $query, $expected)= @_; my $class= ref( $tree); is( $tree->findvalue( $query), $expected, "$class: $query ($expected)"); } HTML-TreeBuilder-XPath-0.14/Makefile.PL 0000644 0001750 0001750 00000001353 11444212634 017647 0 ustar mrodrigu mrodrigu use 5.006; use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. (my $EUMM= $ExtUtils::MakeMaker::VERSION)=~ tr/_//d; my @license = $EUMM > 6.30 ? qw(LICENSE perl) : (); WriteMakefile( NAME => 'HTML::TreeBuilder::XPath', VERSION_FROM => 'lib/HTML/TreeBuilder/XPath.pm', # finds $VERSION PREREQ_PM => { XML::XPathEngine => 0.12, HTML::TreeBuilder => 0, List::Util => 0 }, @license, ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'lib/HTML/TreeBuilder/XPath.pm', # retrieve abstract from module AUTHOR => 'Michel Rodriguez