views:

400

answers:

3

I get the following error when I run the little sample script:

Can't locate object method "new" via package "WWW::Mechanize::Firefox" (perhaps you forgot to load "WWW::Mechanize::Firefox"?) at mechtest.pl line 2.

use WWW::Mechanize::Firefox;
my $mech = WWW::Mechanize::Firefox->new();
$mech->get('http://google.com');

$mech->eval_in_page('alert("Hello Firefox")');
my $png = $mech->content_as_png();

I have WWW::Mechanize::Firefox installed, I have the MozRepl plugin installed on Firefox. Why can't it find new?

A: 

Sounds like WWW::Mechanize::Firefox isn't installed properly. Reboot and confirm that it's installed properly (cpan, ppm etc).

Matthew Lock
A: 

The module requires some dependencies like MozRepl::RemoteObject etc. you should probably reinstall using cpan or ppm (if using ActiveState) etc

ghostdog74
I installed using the PPM.
SJaguar13
Missing dependencies would cause it to fail immediately when it hits the 'use', not when he calls ->new().
David Precious
+3  A: 

Most likely you are on Windows and have an old version of WWW::Mechanize::Firefox installed. That old version was at the time (badly) named Fire_F_ox (note the upper case F). Look whether you have a file FireFox.pm on your machine.

Windows has case-insensitive filesystems and hence will happily load a file FireFox.pm even if you request to load a file Firefox.pm.

The solution is to uninstall WWW::Mechanize::FireFox and to install WWW::Mechanize::Firefox. Also, for future reports, it immensively helps if you tell us the version of Perl, the version(s) of the module(s) and the OS you use.

-max

Corion