waiferv waiferv - 2 years ago 60
Javascript Question

WWW::Scripter as parent class causes weird error message

when I use

normally everything works fine:

use WWW::Scripter;
my $m = WWW::Scripter->new();

But when I try to subclass
like so:

package MyScripter;

use parent qw(WWW::Scripter);

sub new {
my ($class, @args) = @_;
my $self = $class->SUPER::new(@args);
return $self;

package main;

my $m = MyScripter->new();

I get this strange error message:

Error: Can't locate object method "prop" via package "MyScripter" at /home/myuser/localperl/lib/site_perl/5.18.2/JE/LValue.pm line 91

What is going on?

WWW::Scripter::VERSION => 0.030
JE::VERSION => 0.060

Answer Source

I guessed that the problem was dependent on the site being accessed, as I tried it with http://www.bbc.co.uk/ with no problems at all (except that it doesn't like the JavaScript apearing in XHTML CDATA sections).

This is because of a broken inheritance hierarchy. I haven't found the exact problem, but I believe it is because of the way the JavaScript plugin works. It expects to be (insists on being) called in the context of a WWW::Scripter object, and has an explicit

use WWW::Scripter 0.022

at the start, which will load all the method definitions from the basic module instead of from your subclass.

There is all sorts of nasty stuff in there, such as using the Perl 4 package name separator, like use LWP'UserAgent, and literal path loads like

require "WWW/Scripter/Plugin/JavaScript/" . "$$self[benm].pm"

which could hardly be more anti-inheritance.

Without some more work it is hard to tell whether it's an easy fix or a rewrite, but to solve your problem I suggest using roles rather than inheritance, which allows the role model much more freedom in how it does its thing. It's described nicely in perldoc perlootut and you do a lot worse than experimenting with Role::Tiny.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download