diff --git a/Changes b/Changes index c9470aee..c333df6f 100644 --- a/Changes +++ b/Changes @@ -4,6 +4,10 @@ Revision history for WWW::Mechanize [DOCUMENTATION] - Fix broken Pod + [ENHANCEMENTS] + - Upgrade to HTML::TreeBuilder version 5 to get support for weak references in + HTML::Element (GH#251) (Julien Fiegehenn) + 1.89 2018-10-18 19:13:34Z [ENHANCEMENTS] - Add support to find_image() and find_all_images() via 'id' diff --git a/dist.ini b/dist.ini index 51536a8a..6ba6166d 100644 --- a/dist.ini +++ b/dist.ini @@ -23,6 +23,7 @@ dir = bin [Prereqs / RuntimeRequires] perl = 5.006 +Scalar::Util = 1.14 [Prereqs / TestRequires] CGI = 4.32 diff --git a/lib/WWW/Mechanize.pm b/lib/WWW/Mechanize.pm index d90050a5..db5dc629 100644 --- a/lib/WWW/Mechanize.pm +++ b/lib/WWW/Mechanize.pm @@ -748,9 +748,9 @@ are passed to I: =item I<< $mech->content( format => 'text' ) >> Returns a text-only version of the page, with all HTML markup -stripped. This feature requires I to be installed, -or a fatal error will be thrown. This works only if the contents are -HTML. +stripped. This feature requires I version 5 or higher +to be installed, or a fatal error will be thrown. This works only if +the contents are HTML. =item I<< $mech->content( base_href => [$base_href|undef] ) >> @@ -822,7 +822,7 @@ sub content { =head2 $mech->text() Returns the text of the current HTML content. If the content isn't -HTML, $mech will die. +HTML, C<$mech> will die. The text is extracted by parsing the content, and then the extracted text is cached, so don't worry about performance of calling this @@ -834,13 +834,16 @@ sub text { my $self = shift; if ( not defined $self->{text} ) { - require HTML::TreeBuilder; + unless ( exists $INC{'HTML::TreeBuilder'} ) { + require HTML::TreeBuilder; + HTML::TreeBuilder->VERSION(5); + HTML::TreeBuilder->import('-weak'); + } my $tree = HTML::TreeBuilder->new(); $tree->parse( $self->content ); $tree->eof(); $tree->elementify(); # just for safety $self->{text} = $tree->as_text(); - $tree->delete; } return $self->{text}; diff --git a/t/content.t b/t/content.t index fe636784..b636fa2b 100644 --- a/t/content.t +++ b/t/content.t @@ -40,8 +40,8 @@ $mech->update_html($html); =cut SKIP: { - eval 'use HTML::TreeBuilder'; - skip 'HTML::TreeBuilder not installed', 2 if $@; + eval 'use HTML::TreeBuilder 5'; + skip 'HTML::TreeBuilder version 5 not installed', 2 if $@; my $text = $mech->content(format => 'text'); like( $text, qr/Fine/, 'Found Fine' );