Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Can't locate object method new via package URI::URL

by ybiC (Prior)
on Apr 16, 2002 at 14:56 UTC ( #159510=perlquestion: print w/replies, xml ) Need Help??

ybiC has asked for the wisdom of the Perl Monks concerning the following question:

    Dear brothers and sisters in Perl,
I'm rewriting an existing codelet that nails up a dial connection via HTTP fetches, so that it randomly selects from a list of web pages to fetch and waits a random length of time between fetches.   All fairly straightforward and no problems.   That is, until I move the code from my workstation to the dial-connected firewall/proxy, where it fails to run and gives this error:

Can't locate object method "new" via package "URI::URL" at ./wtest.pl line 12

I've reinstalled URI, downgraded it to v1.17, upgraded it back to v1.18, all to no avail.   It can't be left to run on my workstation, as it would only fetch from firewall's proxy instead of from the web.   What other troubleshooting steps might you recommend?

Minimized code and additional details follow.
    stymied, puzzled, baffled and perplexed,
    Don

#!/usr/bin/perl -w # wtest.pl # 2002-04-16 ybiC $|++; require 5; use strict; use LWP::UserAgent; my $site = shift; my $url = new URI::URL($site); my $req = new HTTP::Request('GET', $url); my $ua = new LWP::UserAgent; my $resp = $ua->request($req); if ($resp->is_success) { # print $resp->content; print "Received response from $site\n"; } else { print "Error: ", $resp->message, "\n\n"; }

Relevant modules (all installed without a hitch):

  • URI
  • MIME::Base64
  • HTML::Parser
  • libnet
  • Digest::MD5
  • HTML::Tagset
  • LWP::UserAgent

@INC contains the following:

  • /usr/lib/perl5/5.005/i386-linux
  • /usr/lib/perl5/5.005
  • /usr/local/lib/site_perl/i386-linux
  • /usr/local/lib/site_perl/
  • /usr/lib/perl5

Perl 5.00503
Debian GNU/Linux 2.2r6

Replies are listed 'Best First'.
Re: Can't locate object method new via package URI::URL
by Fletch (Chancellor) on Apr 16, 2002 at 15:00 UTC

    Try adding use URI::URL;. And consider using URI instead (URI::URL is for backwards compatibility with older LWP code).

Re: Can't locate object method new via package URI::URL
by tachyon (Chancellor) on Apr 16, 2002 at 16:09 UTC

    See how you only use LWP::UserAgent; but then call new methods on to other packages. OK so we have all got used to using HTTP::Request's new() method when we use LWP. But why does this actually work. Afterall we have not a use HTTP::Request; -> because LWP::UserAgent did so this module is in %INC. Evidently you have different versions of LWP::UserAgent. A simple use URI::URL will fix the problem as Fletch notes. So will syncronising you LWP::UserAgent on the problem box with the one on the OK box. You can have a look at all the modules available to a script in %INC like:

    print $_, "\n" for keys %INC;

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://159510]
Approved by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2021-07-28 16:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?