Документация
HTML CSS PHP PERL другое

Section 3.8.  Installing Modules from CPAN

 
Previous
Table of Contents
Next

3.8. Installing Modules from CPAN

Installing a simple module from CPAN can be straightforward: we download the module distribution archive, unpack it, and change into its directory. We use wget here, but it doesn't matter which tool you use.

$ wget http://www.cpan.org/.../HTTP-Cookies-Safari-1.10.tar.gz
$ tar -xzf HTTP-Cookies-Safari-1.10.tar.gz
$ cd HTTP-Cookies-Safari-1.10s

From there we go one of two ways (which we'll explain in detail in Chapter 16). If we find a file named Makefile.PL, we run this series of commands to build, test, and finally install the source:

$ perl Makefile.PL
$ make
$ make test
$ make install

If we don't have permission to install modules in the system-wide directories,[*] we can tell Perl to install them under another path by using the PREFIX argument:

[*] These directories were set when the administrator installed Perl, and we can see them with perl -V.

$ perl Makefile.PL PREFIX=/Users/home/Ginger

To make Perl look in that directory for modules, we can set the PERL5LIB environment variable. Perl adds those directories to its module directory search list.

$ export PERL5LIB=/Users/home/Ginger

We can also use the lib pragma to add to the module search path, although this is not as friendly, since we have to change the code, but also because it might not be the same directory on other machines where we want to run the code.

#!/usr/bin/perl
use lib qw(/Users/home/Ginger);

Backing up for a minute, if we found a Build.PL file instead of a Makefile.PL, the process is the same. These distributions use Module::Build to build and install code. Since Module::Build is not a core Perl module,[*] we have to install it before we can install the distribution that needs it.

[*] At least not yet. It should be part of Perl 5.10, though.

$ perl Build.PL
$ perl Build
$ perl Build test
$ perl Build install

To install into our private directories using Module::Build, we add the install_base parameter. We tell Perl how to find modules the same way we did before.

$ perl Build.PL --install_base /Users/home/Ginger

Sometimes we find both Makefile.PL and Build.PL in a distribution. What do we do then? We can use either one. Play favorites, if you like.


Previous
Table of Contents
Next
© 2000- NIV