LWP and the associated modules are available in various distributions free from the Comprehensive Perl Archive Network (CPAN). The main distributions are listed at the start of Appendix A, although the details of which modules are in which distributions change occasionally.
If you're using ActivePerl for Windows or MacPerl for Mac OS 9, you already have LWP. If you're on Unix and you don't already have LWP installed, you'll need to install it from CPAN using instructions given in the next section.
To test whether you already have LWP installed:
% perl -MLWP -le "print(LWP->VERSION)"
(The second character in
a lowercase L, not a digit one.)
If you see:
Can't locate LWP in @INC (@INC contains:
...lots of paths...). BEGIN failed--compilation aborted.
or if you see a version number lower than 5.64, you need to install LWP on your system.
There are two ways to install modules: using the CPAN shell or the old-fashioned manual way.
If you have never used the CPAN shell, you will need to configure it before you can use it. It will prompt you for some information before building its configuration file.
Invoke the CPAN shell by entering the following command at a system shell prompt:
% perl -MCPAN -eshell
If you've never run it before, you'll see this:
We have to reconfigure CPAN.pm due to following uninitialized parameters:
followed by a number of questions. For each question, the default answer is typically fine, but you may answer otherwise if you know that the default setting is wrong or not optimal. Once you've answered all the questions, a configuration file is created and you can start working with the CPAN shell.
If you need help at any time, you can read the CPAN shell's
manual page by typing
CPAN or by starting up the CPAN
-eshell at a system shell prompt) and
h at the
cpan> h Display Information command argument description a,b,d,m WORD or /REGEXP/ about authors, bundles, distributions, modules i WORD or /REGEXP/ about anything of above r NONE reinstall recommendations ls AUTHOR about files in the author's directory Download, Test, Make, Install... get download make make (implies get) test MODULES, make test (implies make) install DISTS, BUNDLES make install (implies test) clean make clean look open subshell in these dists' directories readme display these dists' README files Other h,? display this menu ! perl-code eval a perl command o conf [opt] set and query options q quit the cpan shell reload cpan load CPAN.pm again reload index load newer indices autobundle Snapshot force cmd unconditionally do cmd
All you have to do is enter:
cpan> install Bundle::LWP
The CPAN shell will show messages explaining what it's up to. You may need to answer questions to configure the various modules (e.g., libnet asks for mail hosts and so on for testing purposes).
After much activity, you should then have a fresh copy of LWP
on your system, with far less work than installing it manually one
distribution at a time. At the time of this writing,
install Bundle::LWP installs not just the
libwww-perl distribution, but also URI and HTML-Parser. It does not
install the HTML-Tree distribution that we'll use in Chapter 9 and Chapter 10. To do that,
cpan> install HTML::Tree
These commands do not install the HTML-Format distribution, which was also once part of the LWP distribution. I do not discuss HTML-Format in this book, but if you want to install it so that you have a complete LWP installation, enter this command:
cpan> install HTML::Format
Remember, LWP may be just about the most popular distribution in CPAN, but that's not all there is! Look around the web-related parts of CPAN (I prefer the interface at http://search.cpan.org, but you can also try http://kobesearch.cpan.org) as there are dozens of modules, from WWW::Automate to SOAP::Lite, that can simplify your web-related tasks.
The normal Perl module installation procedure is summed up in the document
perlmodinstall. You can read this
perlmodinstall at a shell prompt or online
CPAN is a network of a large collection of Perl software and documentation. See the CPAN FAQ at http://www.cpan.org/misc/cpan-faq.html for more information about CPAN and modules.
First, download the module distributions. LWP requires several other modules to operate successfully. You'll need to install the distributions given in Table 1-1, in the order in which they are listed.
Table 1-1. Modules used in this book
Fetch these modules from one of the FTP or web sites that form CPAN, listed at http://www.cpan.org/SITES.html and http://mirror.cpan.org. Sometimes CPAN has several versions of a module in the authors directory. Be sure to check the version number and get the latest.
For example to install MIME-Base64, you might first fetch http://www.cpan.org/authors/id/G/GA/GAAS/ to see which versions are there, then fetch http://www.cpan.org/authors/id/G/GA/GAAS/MIME-Base64-2.12.tar.gz and install that.
% tar xzf MIME-Base64-2.12.tar.gz % cd MIME-Base64-2.12 % perl Makefile.PL Checking if your kit is complete... Looks good Writing Makefile for MIME::Base64
Compile the code with the
% make cp Base64.pm blib/lib/MIME/Base64.pm cp QuotedPrint.pm blib/lib/MIME/QuotedPrint.pm /usr/bin/perl -I/opt/perl5/5.6.1/i386-freebsd -I/opt/perl5/5.6.1 /opt/perl5/5.6.1/ExtUtils/xsubpp -typemap /opt/perl5/5.6.1/ExtUtils/typemap Base64.xs > Base64.xsc && mv Base64.xsc Base64.c cc -c -fno-strict-aliasing -I/usr/local/include -O -DVERSION=\"2.12\" -DXS_VERSION=\"2.12\" -DPIC -fpic -I/opt/perl5/5.6.1/i386-freebsd/CORE Base64.c Running Mkbootstrap for MIME::Base64 ( ) chmod 644 Base64.bs rm -f blib/arch/auto/MIME/Base64/Base64.so LD_RUN_PATH="" cc -o blib/arch/auto/MIME/Base64/Base64.so -shared -L/opt Base64.o chmod 755 blib/arch/auto/MIME/Base64/Base64.so cp Base64.bs blib/arch/auto/MIME/Base64/Base64.bs chmod 644 blib/arch/auto/MIME/Base64/Base64.bs Manifying blib/man3/MIME::Base64.3 Manifying blib/man3/MIME::QuotedPrint.3
Then make sure everything works on your system with
% make test PERL_DL_NONLAZY=1 /usr/bin/perl -Iblib/arch -Iblib/lib -I/opt/perl5/5.6.1/i386-freebsd -I/opt/perl5/5.6.1 -e 'use Test::Harness qw(&runtests $verbose); $verbose=0; runtests @ARGV;' t/*.t t/base64..........ok t/quoted-print....ok t/unicode.........skipped test on this platform All tests successful, 1 test skipped. Files=3, Tests=306, 1 wallclock secs ( 0.52 cusr + 0.06 csys = 0.58 CPU)
If it passes the tests, install it with
install (as the superuser):
# make install Installing /opt/perl5/site_perl/5.6.1/i386-freebsd/auto/MIME/Base64/Base64.so Installing /opt/perl5/site_perl/5.6.1/i386-freebsd/auto/MIME/Base64/Base64.bs Files found in blib/arch: installing files in blib/lib into architecture dependent library tree Installing /opt/perl5/site_perl/5.6.1/i386-freebsd/MIME/Base64.pm Installing /opt/perl5/site_perl/5.6.1/i386-freebsd/MIME/QuotedPrint.pm Installing /usr/local/man/man3/MIME::Base64.3 Installing /usr/local/man/man3/MIME::QuotedPrint.3 Writing /opt/perl5/site_perl/5.6.1/i386-freebsd/auto/MIME/Base64/.packlist Appending installation info to /opt/perl5/5.6.1/i386-freebsd/perllocal.pod