On Mon Apr 15 11:01:15 2013, LXP wrote:
Show quoted text> The following code:
>
> use WWW::Scripter ();
>
> my $w = WWW::Scripter->new;
> $w->dom_enabled(0);
> $w->get('
http://google.com/');
> $w->content;
>
> throws this error:
>
> Can't call method "charset" on an undefined value at
> .../WWW/Scripter.pm line 151.
>
> This appears to be because WWW::Scripter explicitly undefines the
> "document" attribute in its "_update_page" method, but the "content"
> method doesn't check for its existence before doing its own
> processing.
The attached patch includes a test and a fix for this problem.
diff --git a/lib/WWW/Scripter.pm b/lib/WWW/Scripter.pm
index 71f335f..6f05f8b 100644
--- a/lib/WWW/Scripter.pm
+++ b/lib/WWW/Scripter.pm
@@ -146,7 +146,7 @@ sub title { (shift->document||return)->title(@_) }
sub content {
my $self = shift;
- if($self->is_html) {
+ if($self->is_html && $self->document) {
my %parms = @_;
my $cs = (my $doc = $self->document)->charset;;
if(exists $parms{format} && $parms{format} eq 'text') {
diff --git a/t/dom.t b/t/dom.t
index 2e297ac..483c291 100644
--- a/t/dom.t
+++ b/t/dom.t
@@ -182,14 +182,15 @@ END
'window event handlers are not called when scripts are off';
}
-use tests 2; # dom_enabled
+use tests 3; # dom_enabled
{
my $m = new WWW::Scripter;
ok $m->dom_enabled(0), 'DOM enabled by default';
- $m->get('data:text/html,');
+ $m->get('data:text/html,123');
ok !$m->document, 'dom_enabled'
or diag $m->document->URL;
+ is $m->content, '123', 'content works when !dom_enabled';
}
use tests 1; # DOM tree ->charset