LWP Package issue in my script..

S

schimata

Hi guys,

I ahve the following code:

++++++++++++++++++++++++

use Cwd;
use XML::parser;
use LWP::Simple;
use HTTP::Status;
use LWP::UserAgent;

blah..blah..

blah..


my $ua = LWP::UserAgent->new;


$ua->timeout(1000);
$ua->env_proxy;
# $ua->credentials( 'tracker:80', 'tracker', 'hello' => 'abcd@123' );

my $url ='http://tracker/cfdocs/proddev/admin/ws/api/
get_all_subfeatures.cfm';
print "hello";
my $response = $ua->get($url);

+++++++++++++++++++++++++++++++

Now when I run this script, I get the following error:
++++++++++++++++++++++++++++++++++++++++++++++++++++
Can't locate object method "get" via package "LWP::UserAgent" at C:\cq
\featurexml.pl line 37.
++++++++++++++++++++++++++++++++++++++++++++++++++++

I think that it is the issue with the LWP stuff here. I see the below
versions of perl and LWP:
++++++++++++++++++++++++++++++++++++++
C:\cq>perl -v
This is perl, v5.6.0 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-2000, Larry Wall
Binary build 623 provided by ActiveState Tool Corp. http://www.ActiveState.com
Built 16:27:07 Dec 15 2000


C:\cq>perl -MLWP -e "print $LWP::VERSION"
5.48
+++++++++++++++++++++++++++++++++++++++

Do I need to re-compile LWP pachage? Any pointers here?

Thanks,
Srini
 
U

Uri Guttman

s> use LWP::Simple;
s> use HTTP::Status;
s> use LWP::UserAgent;

you don't need all three of those. LWP::Simple will load LWP::UserAgent
which will load HTTP::Status. and by loading all those you are confusing
yourself below.

s> blah..blah..
s> blah..

that isn't valid perl code! :)

s> my $ua = LWP::UserAgent->new;

so you are using the OO style with that module. read ITS docs on what
methods it supports.

s> $ua->timeout(1000);
s> $ua->env_proxy;

those are legit methods for that object.

s> my $url ='http://tracker/cfdocs/proddev/admin/ws/api/
s> get_all_subfeatures.cfm';

be careful when pasting in emails. that line wrapped and shouldn't have
and if someone cut/pasted it, it would likely fail because of the
newline in the url.

s> print "hello";
s> my $response = $ua->get($url);

ahh. is get() a method documented in LWP::UserAgent? no it isn't. it is
an exported sub in LWP::Simple which wraps code around its own $ua. so
you either call get() as a sub or use $ua and its methods. you can't
mix/match them.

uri
 
M

Mumia W.

s> use LWP::Simple;
s> use HTTP::Status;
s> use LWP::UserAgent;

you don't need all three of those. LWP::Simple will load LWP::UserAgent
which will load HTTP::Status. and by loading all those you are confusing
yourself below.

s> blah..blah..
s> blah..

that isn't valid perl code! :)

s> my $ua = LWP::UserAgent->new;

so you are using the OO style with that module. read ITS docs on what
methods it supports.

s> $ua->timeout(1000);
s> $ua->env_proxy;

those are legit methods for that object.

s> my $url ='http://tracker/cfdocs/proddev/admin/ws/api/
s> get_all_subfeatures.cfm';

be careful when pasting in emails. that line wrapped and shouldn't have
and if someone cut/pasted it, it would likely fail because of the
newline in the url.

s> print "hello";
s> my $response = $ua->get($url);

ahh. is get() a method documented in LWP::UserAgent? no it isn't.

The method is there. I am able to run Schimata's program after changing
the URL. Evidently, the program Schimata posted is not the one with the
problem.
it is
an exported sub in LWP::Simple which wraps code around its own $ua. so
you either call get() as a sub or use $ua and its methods. you can't
mix/match them.

uri

You are correct though in that using both LWP::Simple and LWP::UserAgent
is redundant.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top