For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > October 2006 > Question about Installed Packages









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Question about Installed Packages
Chris Share

2006-10-20, 6:56 pm

I'm trying to implement the following code:

########################################
##############

require LWP::UserAgent;

my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;

my $response = $ua->get('http://search.cpan.org/');

if ($response->is_success) {
print $response->content; # or whatever
}
else {
die $response->status_line;
}

########################################
##############

The code works but what I don't get is how do I know if LWP::UserAgent
(or even LWP) is installed on my machine.

If I use the Perl Package Manager and type: query LWP
I get the following:

Querying target 1 (ActivePerl 5.8.7.815)
1. LWP-UserAgent-Determined [1.03] a virtual browser that retries errors

This is a module (?) I installed myself.

Is LWP::UserAgent installed--I guess it must be because the code works.

Can someone explain this?

Cheers,

Chris


Rob Dixon

2006-10-20, 6:56 pm

Chris Share wrote:
> I'm trying to implement the following code:
>
> ########################################
##############
>
> require LWP::UserAgent;
>
> my $ua = LWP::UserAgent->new;
> $ua->timeout(10);
> $ua->env_proxy;
>
> my $response = $ua->get('http://search.cpan.org/');
>
> if ($response->is_success) {
> print $response->content; # or whatever
> }
> else {
> die $response->status_line;
> }
>
> ########################################
##############
>
> The code works but what I don't get is how do I know if LWP::UserAgent
> (or even LWP) is installed on my machine.
>
> If I use the Perl Package Manager and type: query LWP
> I get the following:
>
> Querying target 1 (ActivePerl 5.8.7.815)
> 1. LWP-UserAgent-Determined [1.03] a virtual browser that retries errors
>
> This is a module (?) I installed myself.
>
> Is LWP::UserAgent installed--I guess it must be because the code works.
>
> Can someone explain this?


First of all it should be

use LWP;

which does the 'require LWP::UserAgent' for you as well as checking that you're
running on an adequate version of Perl and setting the LWP version number.

And you can find out whether LWP is installed by entering

perl -MLWP -e"1"

on the command line. It will shout if the module isn't there. Your program will
also die at the require if it doesn't find LWP::UserAgent, saying something like
'Can't locate LWP/UserAgent.pm in @INC'.

HTH,

Rob

Chris Share

2006-10-20, 6:56 pm

Thanks for the info. Isn't this what the Perl Package Manager is for?

Rob Dixon wrote:
> Chris Share wrote:
>
>
>
> First of all it should be
>
> use LWP;
>
> which does the 'require LWP::UserAgent' for you as well as checking that
> you're
> running on an adequate version of Perl and setting the LWP version number.
>
> And you can find out whether LWP is installed by entering
>
> perl -MLWP -e"1"
>
> on the command line. It will shout if the module isn't there. Your
> program will
> also die at the require if it doesn't find LWP::UserAgent, saying
> something like
> 'Can't locate LWP/UserAgent.pm in @INC'.
>
> HTH,
>
> Rob
>
>

Derek B. Smith

2006-10-20, 6:56 pm


--- Chris Share <cshare01@qub.ac.uk> wrote:

> Thanks for the info. Isn't this what the Perl
> Package Manager is for?
>
> Rob Dixon wrote:
>

########################################
##############
> $ua->get('http://search.cpan.org/');
>

########################################
##############[color=darkred]
> know if LWP::UserAgent
> LWP
> browser that retries
> because the code works.
> well as checking that
> the LWP version number.
> entering
> isn't there. Your
> LWP::UserAgent, saying


yes but try pmtools. It is a module that will give
you various info about what modules are installed and
where they live and what versions to name a few.


________________________________________
__________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Rob Dixon

2006-10-20, 6:56 pm

Chris Share wrote:
> Rob Dixon wrote:
>
> Thanks for the info. Isn't this what the Perl Package Manager is for?



Hi Chris. Please bottom-post your replies. Thanks.

Perl Package Manager is an ActiveState utility that will tell you only what
packages it remembers installing itself. It won't tell you about anything that
you've installed with CPAN or even anything that was installed with Perl itself,
like List::Utils. And if it has been used to install a package which has since
been damaged or deleted behind its back it will happily tell you that it;s still
there. Using Perl itself to try to load the module as I described is the best
test.

Rob
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com