Installing CPAN Modules

There are two major build systems people use in their CPAN distributions. One is built around the common make tool, while the other is pure Perl.

By Hand

People don’t often install CPAN distributions by hand since they would have to handle all of the dependencies themselves, which is too much work. You can do it, though, and it’s useful to know how.

When you look inside the distribution, you’ll probably find a Makefile.PL or a Build.PL. You use them in the same way, as shown in Table 19-1.

Table 19-1. Build commands for the two major build tools

Makefile.PL

Build.PL

% perl Makefile.PL
% make
% make test
% make install
% perl Build.PL
% ./Build
% ./Build test
% ./Build install

With the defaults, both build systems try to install the distribution in the library paths you (or someone) set up when they built and installed the perl binary you used to run the build file. You can see those directories at the end of the output of perl –V.

You may not have permission to write into those directories, but you can install modules in any directory you please by telling build file where to install them. Build files change their behavior based on command-line options or environment variables.

% perl Makefile.PL INSTALL_BASE=/some/other/directory

% perl Build.PL ––install_base /some/other/directory

You don’t have to specify the options every time if you set them in the right environment variables. Each build system has an environment variable to hold default command-line options. Here’s ...

Get Programming Perl, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.