Build.PL100664001750001750 315612515557700 20315 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25# ========================================================================= # THIS FILE IS AUTOMATICALLY GENERATED BY MINILLA. # DO NOT EDIT DIRECTLY. # ========================================================================= use 5.008_001; use strict; use warnings; use utf8; use Module::Build; use File::Basename; use File::Spec; my %args = ( license => 'perl', dynamic_config => 0, configure_requires => { 'Module::Build' => 0.38, }, name => 'HTML-TreeBuilder-LibXML', module_name => 'HTML::TreeBuilder::LibXML', allow_pureperl => 0, script_files => [glob('script/*'), glob('bin/*')], c_source => [qw()], PL_files => {}, test_files => ((-d '.git' || $ENV{RELEASE_TESTING}) && -d 'xt') ? 't/ xt/' : 't/', recursive_test_files => 1, ); if (-d 'share') { $args{share_dir} = 'share'; } my $builder = Module::Build->subclass( class => 'MyBuilder', code => q{ sub ACTION_distmeta { die "Do not run distmeta. Install Minilla and `minil install` instead.\n"; } sub ACTION_installdeps { die "Do not run installdeps. Run `cpanm --installdeps .` instead.\n"; } } )->new(%args); $builder->create_build_script(); use File::Copy; print "cp META.json MYMETA.json\n"; copy("META.json","MYMETA.json") or die "Copy failed(META.json): $!"; if (-f 'META.yml') { print "cp META.yml MYMETA.yml\n"; copy("META.yml","MYMETA.yml") or die "Copy failed(META.yml): $!"; } else { print "There is no META.yml... You may install this module from the repository...\n"; } Changes100664001750001750 1201612515557700 20327 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25Revision history for Perl extension HTML::TreeBuilder::LibXML 0.25 2015-04-21T23:39:33Z commit 5c46775d50678e611729135f3601b66e6a0d10cd Author: Yanick Champoux Date: Thu Jan 15 14:15:04 2015 -0500 silence warnings ... as the arguments can be undefined Fixes #10 0.24 2014-09-22T09:31:26Z - Removed Web::Scraper from runtime dependencies. https://github.com/tokuhirom/HTML-TreeBuilder-LibXML/issues/9 0.23 2013-05-17T00:16:48Z - fixed guts(), clone() and replace_with() to properly handle XML::LibXML::Dtd nodes - guts() now includes the Dtd node in the returned document (unless it were implicitly created) - clone() calls createInternalSubset() on the new document - replace_with() calls createInternalSubset() if the replacement is a XML::LibXML::Dtd (can't import Dtd node) (cafe01) 0.22 2013-05-13T00:04:09Z - improved guts(), calling nonBlankChildNodes() instead of childNodes() - improved HTML::TreeBuilder::LibXML::Node documentation (cafe01) 0.21 2013-05-12T19:12:53Z - fixed guts(), - now returning nodes from and instead of just - now returning text and comment nodes instead of just element nodes - returned nodes now belong to the same document - fixed to_HTML to render valid html, not xml (cafe01) 0.20 2013-05-10T20:44:16Z - improved replace_with() on document node. - fixed push_content() and unshift_content() to work with document mode. (cafe01) 0.19 2013-05-10T01:03:58Z - fixed replace_with() and parent(), to avoid calling appendChild() on a Document node, which is not supported by XML::LibXML. (cafe01) 0.18 2013-05-09T20:49:04Z - implemented all node methods needed for Web::Query::LibXML to work - clone_list - detach - delete_content - content_list - replace_with - push_content - unshift_content - postinsert - preinsert - disembowel (HTML::TreeBuilder::LibXML) (cafe01) - modified parse_file() to read file content, then call parse_content() - thats because parse_content() will detect (heuristically) when the parser will add implict tags, so guts() can work properly. (cafe01) 0.18 2013-05-09T01:27:46Z - implemented matches(), parent(), guts() node method (Carlos Fernando Avila Gratz) 0.17 handle /(de)?objectify_text/ for wassr
mixi ok.
}); $tree->eof; { my @nodes = $tree->look_down('_tag' => 'a'); is scalar(@nodes), 2; is $nodes[0]->attr('href'), 'http://wassr.jp/'; } { my @nodes = $tree->look_down(href => qr/mixi/); is scalar(@nodes), 1; is $nodes[0]->attr('href'), 'http://mixi.jp/'; } { my @nodes = $tree->look_down('_tag' => 'a', sub { $_[0]->attr('href') =~ /mixi/ }); is scalar(@nodes), 1; is $nodes[0]->attr('href'), 'http://mixi.jp/'; } { my $none = $tree->look_down('_tag' => 'a', sub { 0 }); ok !defined $none, "none because sub ref returns 0"; } { $tree->elementify; $tree->objectify_text; my @nodes = $tree->look_down('_tag' => '~text', sub { $_[0]->attr('text') =~ /alert/ }); is scalar(@nodes), 1; is $nodes[0]->attr('text'), 'alert("hello world")'; } $tree = $tree->delete; } sub _id { my $klass = shift; my $tree = $klass->new; $tree->parse($HTML); $tree->eof; my ($a) = $tree->look_down('_tag' => 'a'); is $a->id, undef; $a->id("OK"); is $a->id, 'OK'; is strip($a->as_HTML), 'wassr'; $a->id(undef); is strip($a->as_HTML), 'wassr'; $tree = $tree->delete; } sub _attr { my $klass = shift; my $tree = $klass->new; $tree->parse($HTML); $tree->eof; my ($a) = $tree->look_down('_tag' => 'a'); is $a->attr('href'), 'http://wassr.jp/'; $a->attr('href', 'http://ficia.com/'); is strip($a->as_HTML), 'wassr'; $a->attr('href', undef); is strip($a->as_HTML), 'wassr'; $tree = $tree->delete; } sub strip { local $_ = shift; s/\n$//g; s/>\s+ "this test requires Web::Scraper" unless eval "use Web::Scraper; 1"; plan tests => 2*3+1; can_ok 'HTML::TreeBuilder::LibXML', 'ignore_unknown'; my $html = <<'...'; wassr
mixi
... my $code = <<'...'; use Web::Scraper; my $ret = scraper { process '//a', 'text[]', 'TEXT'; process '//a', 'href[]', '@href'; process '//div', 'div[]', scraper { process '//a', 'link[]', 'TEXT'; }; }->scrape($html); is_deeply($ret->{text}, ['wassr', 'mixi']); is_deeply($ret->{href}, ['http://wassr.jp/', 'http://mixi.jp/']); is_deeply($ret->{div}, [{link => ['mixi']}]); ... &run; HTML::TreeBuilder::LibXML->replace_original(); &run; sub run { eval $code; die $@ if $@; } 03_destructor.t100664001750001750 63512515557700 22130 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25/tuse strict; use warnings; use Test::More; use HTML::TreeBuilder::LibXML; plan skip_all => 'this test requires HTML::TreeBuilder::XPath' unless eval 'use HTML::TreeBuilder::XPath;1;'; plan tests => 2; { my $destructor = HTML::TreeBuilder::LibXML->replace_original; isa_ok(HTML::TreeBuilder::XPath->new, 'HTML::TreeBuilder::LibXML'); } isa_ok(HTML::TreeBuilder::XPath->new, 'HTML::TreeBuilder::XPath'); 04_new_methods.t100664001750001750 54712515557700 22251 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25/tuse strict; use warnings; use Test::More; use HTML::TreeBuilder::LibXML; plan tests => 2; { my $root = HTML::TreeBuilder::LibXML->new_from_content("", "

foo

", ""); is $root->findvalue("//p"), "foo"; } { my $root = HTML::TreeBuilder::LibXML->new_from_file("t/test.html"); is $root->findvalue("//p"), "bar"; } 05_empty.t100664001750001750 57312515557700 21073 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25/tuse strict; use warnings; use Test::More; use HTML::TreeBuilder::LibXML; my @tests = ("foo", "bar\nbaz", " ", " \n ", ""); plan tests => 3 * @tests; for my $t (@tests) { my $tree = HTML::TreeBuilder::LibXML->new; $tree->parse($t); $tree->eof; ok $tree; eval { $tree->findnodes('//a') }; ok !$@ or diag $@; like $tree->as_HTML, qr//; } 06_web_query.t100664001750001750 363612515557700 21763 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25/tuse strict; use warnings; use Test::More; use HTML::TreeBuilder::LibXML; plan skip_all => "this test requires Web::Query" unless eval "use Web::Query; 1"; plan tests => 6; can_ok 'HTML::TreeBuilder::LibXML', 'parse_content'; can_ok 'HTML::TreeBuilder::LibXML', 'elementify'; my $html = <<'...';
... sub run { my @classes; my $text = wq($html)->find("ul#user-links li")->each(sub { push @classes, $_->find("a span")->attr("class"); })->end->find(".logout")->text; return (\@classes, $text); } isa_ok(HTML::TreeBuilder::XPath->new, 'HTML::TreeBuilder::XPath'); my ($their_classes, $their_text) = &run; HTML::TreeBuilder::LibXML->replace_original(); isa_ok(HTML::TreeBuilder::XPath->new, 'HTML::TreeBuilder::LibXML'); my ($our_classes, $our_text) = &run; is($our_text, $their_text); is_deeply($our_classes, $their_classes); HTML-TreeBuilder-XPath.t100664001750001750 1003412515557700 23454 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25/t# 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 => 31; BEGIN { use_ok('HTML::TreeBuilder::XPath') }; use HTML::TreeBuilder::LibXML; HTML::TreeBuilder::LibXML->replace_original; ######################### my $doc=' Example

Example header

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 TODO: { local $TODO = "I don't know, this order is required for xpath spec, or not??"; 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( $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)'); } is( $html->exists( '//p[@id]/@id' ) , 1 , 'does exist'); is( $html->exists( '//p[@id]/@id2' ) , 0 , 'does not exist' ); { my @p = $html->find( 'p' ); is( scalar @p , 4 , '4

'); is( $p[0]->getValue , 'Intro p1' , '

1'); my( $bq ) = $html->find( 'blockquote' ); is( $bq->getValue , 0 , 'bq' ); } { my @val = $html->findvalues('//span[@class="myspan"]'); is_deeply( \@val , [ qw/ spans several / ] , 'findvalues on multi element'); my( $val2 ) = $html->findvalues('//*[@id="bq"]'); is( $val2 , 0 , 'findvalues on unique element') } { my @children = $html->findnodes( '//p[@id="toto"]')->[0]->childNodes; is( scalar @children , 11 , 'child count'); is( $children[1]->getValue , 'links' , 'first child'); } { my @filter_nodes = $html->findnodes_filter( '//p' , sub { shift->getValue =~ /Intro / } ); is( scalar @filter_nodes , 3 , '3

' ); } { my ($div ) = $html->findnodes( '//div[@class="intro"]' ); my $left = $div->left; is( $left->tag , 'h1' ); my $right = $div->right; is( $right->tag , 'p' ); } __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 clone_list.t100664001750001750 106612515557700 21602 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25/tuse strict; use warnings; use Test::More; use Test::Exception; use HTML::TreeBuilder::LibXML; use HTML::TreeBuilder::LibXML::Node; use Data::Dumper; my $tree = HTML::TreeBuilder::LibXML->new_from_content('

foo
bar'); my @original = $tree->guts; my @clones = HTML::TreeBuilder::LibXML::Node->clone_list(@original); is join('|', map{$_->as_HTML} @clones), '
foo
|bar', 'clone_list'; is $clones[0]->{node}->isSameNode($original[0]->{node}), 0, 'clone is not the same as original'; done_testing; content_list.t100664001750001750 64512515557700 22136 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25/tuse strict; use warnings; use Test::More; use HTML::TreeBuilder::LibXML; use Data::Dumper; my $tree = HTML::TreeBuilder::LibXML->new_from_content('
foo
'); my $guts = $tree->guts; is join('|', map {$_->as_HTML} $guts->content_list), '
foo
|', 'content_list - list context'; is $guts->content_list, 2, 'content_list - scalar context'; done_testing; delete_content.t100664001750001750 51512515557700 22421 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25/tuse strict; use warnings; use Test::More; use Test::Exception; use HTML::TreeBuilder::LibXML; use Data::Dumper; my $tree = HTML::TreeBuilder::LibXML->new_from_content('

bar

'); my ($el) = $tree->guts; $el->delete_content; is $el->as_HTML, '
', 'delete_content'; done_testing; detach.t100664001750001750 71412515557700 20656 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25/tuse strict; use warnings; use Test::More; use Test::Exception; use HTML::TreeBuilder::LibXML; use Data::Dumper; my $tree = HTML::TreeBuilder::LibXML->new_from_content('

bar

'); my ($el) = $tree->guts; my ($p) = $el->findnodes('./p'); my $parent = $p->detach; is $parent->as_HTML, '
', 'detach returns old parent'; isa_ok $p->{node}->parentNode, 'XML::LibXML::Document', 'element new parent'; done_testing;disembowel.t100664001750001750 170312515557700 21577 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25/tuse strict; use warnings; use Test::More; use HTML::TreeBuilder::LibXML; use Data::Dumper; # list context my $tree = HTML::TreeBuilder::LibXML->new_from_content('
foo
'); my @nodes = $tree->disembowel; is join('|', map {$_->as_HTML} @nodes), '
foo
|', 'disembowel - list context'; isa_ok $nodes[0]->parent->{node}, 'XML::LibXML::Document', 'first node parent'; isa_ok $nodes[1]->parent->{node}, 'XML::LibXML::Document', 'second node parent'; ok $nodes[0]->parent->{node}->isSameNode($nodes[1]->parent->{node}), 'nodes belong to the same document'; # scalar context $tree = HTML::TreeBuilder::LibXML->new_from_content('
foo
'); my $node = $tree->disembowel; is $node->as_HTML, '
foo
bar
', 'disembowel - scalar context'; isa_ok $node->parent->{node}, 'XML::LibXML::Document', 'node parent'; done_testing; guts.t100664001750001750 272312515557700 20432 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25/tuse strict; use warnings; use Test::More; use HTML::TreeBuilder::LibXML; use Data::Dumper; # list context my $tree = HTML::TreeBuilder::LibXML->new_from_content('
foo
'); my @guts = $tree->guts; is join('|', map {$_->as_HTML} @guts), '
foo
|', 'guts - list context'; # scalar context my $guts = $tree->guts; isa_ok $guts->{node}->ownerDocument, 'XML::LibXML::Document'; is $guts->as_HTML, '
foo
bar
', 'guts - scalar context'; # guts() must return tags from implicit as well my @nodes = HTML::TreeBuilder::LibXML->new_from_content('head tag
body tag
')->guts; is join('|', map {$_->as_HTML} @nodes), 'head tag|
body tag
'; # guts must include text and comments @nodes = HTML::TreeBuilder::LibXML->new_from_content('head tag
body tag
some text')->guts; is join('|', map {$_->as_HTML} @nodes), "head tag|\n|
body tag
|\n| some text"; # guts must include DOCTYPE if its not implicit my $html_with_dtd = "\n
html5
\n"; $guts = HTML::TreeBuilder::LibXML->new_from_content($html_with_dtd)->guts; isa_ok $guts->{node}->ownerDocument->internalSubset, 'XML::LibXML::Dtd', "doctype"; is $guts->parent->as_HTML, $html_with_dtd, "document with doctype"; done_testing; matches.t100664001750001750 54012515557700 21047 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25/tuse strict; use warnings; use Test::More; use HTML::TreeBuilder::LibXML; use Data::Dumper; my $tree = HTML::TreeBuilder::LibXML->new_from_content('

bar

'); my ($el) = $tree->guts; is $el->matches('//p[@class="foo"]'), 1, 'matches - positive'; is $el->matches('//p[@class="bar"]'), undef, 'matches - negative'; done_testing; parent.t100664001750001750 215712515557700 20742 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25/tuse strict; use warnings; use Test::More; use Test::Exception; use HTML::TreeBuilder::LibXML; use HTML::TreeBuilder::LibXML::Node; use Data::Dumper; my $tree = HTML::TreeBuilder::LibXML->new_from_content('
foo
'); my ($div) = $tree->guts; # get parent isa_ok $div->parent, 'HTML::TreeBuilder::LibXML::Node', 'parent()'; is $div->parent->as_HTML, '
foo
', 'parent()->as_HTML'; # unset parent $div->parent(undef); is $div->parent, undef; # set parent dies_ok { $div->parent($div) } "can't set itself as parent"; # set a doc as parent my $doc = HTML::TreeBuilder::LibXML::Node->new(XML::LibXML->createDocument); $tree = HTML::TreeBuilder::LibXML->new_from_content('
foo
'); ($div) = $tree->guts; $div->parent($doc); is $doc->as_HTML, "
foo
\n", 'set a doc as parent'; # set a doc with child as parent $tree = HTML::TreeBuilder::LibXML->new_from_content('
foo
bar
'); my ($div_foo, $div_bar) = $tree->guts(1); $div_foo->parent($div_bar->parent); is $div_foo->parent->as_HTML, "
bar
foo
\n", 'set a doc with child as parent'; done_testing; postinsert.t100664001750001750 100212515557700 21647 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25/tuse strict; use warnings; use Test::More; use Test::Exception; use HTML::TreeBuilder::LibXML; use HTML::TreeBuilder::LibXML::Node; use Data::Dumper; my $tree = HTML::TreeBuilder::LibXML->new_from_content('
foo
bar'); my @nodes = $tree->guts; my ($p) = HTML::TreeBuilder::LibXML->new_from_content('

')->findnodes('//p'); $p->postinsert(@nodes); is $p->parent->as_HTML, '

foo
bar
', 'postinsert'; done_testing; preinsert.t100664001750001750 100012515557700 21446 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25/tuse strict; use warnings; use Test::More; use Test::Exception; use HTML::TreeBuilder::LibXML; use HTML::TreeBuilder::LibXML::Node; use Data::Dumper; my $tree = HTML::TreeBuilder::LibXML->new_from_content('
foo
bar'); my @nodes = $tree->guts; my ($p) = HTML::TreeBuilder::LibXML->new_from_content('

')->findnodes('//p'); $p->preinsert(@nodes); is $p->parent->as_HTML, '
foo
bar

', 'preinsert'; done_testing; push_content.t100664001750001750 126512515557700 22161 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25/tuse strict; use warnings; use Test::More; use Test::Exception; use HTML::TreeBuilder::LibXML; use Data::Dumper; my $tree = HTML::TreeBuilder::LibXML->new_from_content('
'); my ($el) = $tree->disembowel; $el->push_content('foo', scalar HTML::TreeBuilder::LibXML->new_from_content('

baz

')->guts, 'bar'); is $el->as_HTML, '
foo

baz

bar
', 'push_content'; my $doc = $el->parent; isa_ok $doc->{node}, 'XML::LibXML::Document'; $doc->push_content(HTML::TreeBuilder::LibXML->new_from_content('

cool

')->disembowel); is $doc->as_HTML, "
foo

baz

bar

cool

\n", 'when node is a document'; done_testing; replace_with.t100664001750001750 220612515557700 22112 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25/tuse strict; use warnings; use Test::More; use Test::Exception; use HTML::TreeBuilder::LibXML; use Data::Dumper; my $tree = HTML::TreeBuilder::LibXML->new_from_content('

bar

'); my ($div) = $tree->guts; my ($p) = $div->findnodes('//p'); my $p2 = $p->replace_with('foo', scalar HTML::TreeBuilder::LibXML->new_from_content('

baz

')->guts, 'bar'); isa_ok $p2, 'HTML::TreeBuilder::LibXML::Node', 'returned element'; ok $p2->{node}->isSameNode($p->{node}), 'returns same node'; isa_ok $p->{node}->parentNode, 'XML::LibXML::Document', 'replaced node has a document'; is $div->as_HTML, '
foo

baz

bar
', 'replace_with'; # when parent is a document $tree = HTML::TreeBuilder::LibXML->new_from_content('

bar

'); ($div) = $tree->disembowel; my $doc = $div->{node}->parentNode; $div = $div->replace_with('foo', scalar HTML::TreeBuilder::LibXML->new_from_content('

baz

')->guts, 'bar'); is $doc->toString, "\nfoo\n

baz

\nbar\n", 'replace_with when parent is a document'; #diag $div->as_HTML; #diag ref $div->{node}->parentNode; done_testing;test.html100664001750001750 5112515557700 21060 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25/t

bar

unshift_content.t100664001750001750 131512515557700 22656 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25/tuse strict; use warnings; use Test::More; use Test::Exception; use HTML::TreeBuilder::LibXML; use Data::Dumper; my $tree = HTML::TreeBuilder::LibXML->new_from_content('
STUFF
'); my ($el) = $tree->disembowel; $el->unshift_content('foo', scalar HTML::TreeBuilder::LibXML->new_from_content('

baz

')->guts, 'bar'); is $el->as_HTML, '
foo

baz

barSTUFF
', 'unshift_content'; my $doc = $el->parent; isa_ok $doc->{node}, 'XML::LibXML::Document'; $doc->unshift_content(HTML::TreeBuilder::LibXML->new_from_content('

cool

')->disembowel); is $doc->as_HTML, '

cool

foo

baz

barSTUFF
'."\n", 'when node is a document'; done_testing; benchmark.pl100664001750001750 167412515557700 22453 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25/tools#!/usr/bin/perl use strict; use warnings; use FindBin; use lib "$FindBin::Bin/../lib/"; use Web::Scraper; use URI; use Benchmark 'cmpthese'; use LWP::UserAgent; use HTML::TreeBuilder::LibXML; my $html = get_content(); my $scraper = scraper { process 'a > img', 'image[]' => '@src'; }; print "Web::Scraper: $Web::Scraper::VERSION\n"; print "HTML::TreeBuilder::XPath: $HTML::TreeBuilder::XPath::VERSION\n"; print "HTML::TreeBuilder::LibXML: $HTML::TreeBuilder::LibXML::VERSION\n"; cmpthese(50, { no_libxml => \&no_libxml, use_libxml => \&use_libxml, }); sub no_libxml { my $res = $scraper->scrape($html); } sub use_libxml { local *HTML::TreeBuilder::XPath::new = sub { HTML::TreeBuilder::LibXML->new(); }; my $res = $scraper->scrape($html); } sub get_content { my $ua = LWP::UserAgent->new; my $res = $ua->get('http://www.nicovideo.jp/'); $res->is_success or die 'cannot get html'; $res->content; } 02_perlcritic.t100664001750001750 240312515557700 22274 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25/xtuse strict; use warnings; use Test::More; eval { require Perl::Critic; Perl::Critic->VERSION(1.105); require Test::Perl::Critic; Test::Perl::Critic->VERSION(1.02); Test::Perl::Critic->import( -profile => \(join q{}, ) ); }; note $@ if $@; plan skip_all => "Perl::Critic 1.105+ or Test::Perl::Critic 1.02+ is not installed." if $@; all_critic_ok('lib', 'script', 'bin'); __END__ only=1 # ------------------------------------------------------------------------- # Not important. [BuiltinFunctions::ProhibitSleepViaSelect] [BuiltinFunctions::RequireGlobFunction] [ClassHierarchies::ProhibitOneArgBless] # ------------------------------------------------------------------------- # Bug detection [InputOutput::ProhibitBarewordFileHandles] [Modules::RequireFilenameMatchesPackage] [Subroutines::ProhibitNestedSubs] [Subroutines::ProhibitReturnSort] [TestingAndDebugging::RequireUseStrict] [Variables::ProhibitConditionalDeclarations] [Variables::RequireLexicalLoopIterators] [TestingAndDebugging::ProhibitNoStrict] allow=refs # ------------------------------------------------------------------------- # Security issue detection [InputOutput::RequireEncodingWithUTF8Layer] [Modules::ProhibitEvilModules] [InputOutput::ProhibitTwoArgOpen] META.yml100644001750001750 306212515557700 20264 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25--- abstract: 'HTML::TreeBuilder and XPath compatible interface with libxml' author: - 'Tokuhiro Matsuno ' build_requires: Test::Exception: '0' Test::More: '0.98' configure_requires: Module::Build: '0.38' dynamic_config: 0 generated_by: 'Minilla/v2.2.0, CPAN::Meta::Converter version 2.141520' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: HTML-TreeBuilder-LibXML no_index: directory: - t - xt - inc - share - eg - examples - author - builder provides: HTML::TreeBuilder::LibXML: file: lib/HTML/TreeBuilder/LibXML.pm version: '0.25' HTML::TreeBuilder::LibXML::Node: file: lib/HTML/TreeBuilder/LibXML/Node.pm requires: HTML::TreeBuilder::XPath: '0.14' LWP::UserAgent: '6' URI: '0' XML::LibXML: '1.7' perl: '5.008001' resources: bugtracker: https://github.com/tokuhirom/HTML-TreeBuilder-LibXML/issues homepage: https://github.com/tokuhirom/HTML-TreeBuilder-LibXML repository: git://github.com/tokuhirom/HTML-TreeBuilder-LibXML.git version: '0.25' x_contributors: - 'Masahiro Chiba ' - 'kimura.hideo ' - 'Tatsuhiko Miyagawa ' - 'Perlover ' - 'John SJ Anderson ' - 'Oleg G ' - 'Stanislaw Pusep ' - 'Carlos Fernando Avila Gratz ' - 'Carlos Fernando Avila Gratz ' - 'Yanick Champoux ' MANIFEST100644001750001750 101212515557700 20135 0ustar00tokuhiromtokuhirom000000000000HTML-TreeBuilder-LibXML-0.25Build.PL Changes LICENSE META.json README.md cpanfile lib/HTML/TreeBuilder/LibXML.pm lib/HTML/TreeBuilder/LibXML/Node.pm t/00_compile.t t/01_simple.t t/02_web_scraper.t t/03_destructor.t t/04_new_methods.t t/05_empty.t t/06_web_query.t t/HTML-TreeBuilder-XPath.t t/clone_list.t t/content_list.t t/delete_content.t t/detach.t t/disembowel.t t/guts.t t/matches.t t/parent.t t/postinsert.t t/preinsert.t t/push_content.t t/replace_with.t t/test.html t/unshift_content.t tools/benchmark.pl xt/02_perlcritic.t META.yml MANIFEST