Much of the benefit of using Perl for system administration work comes from all of the free code available in module form. The modules mentioned in this book can be found in one of three places:
- Comprehensive Perl Archive Network (CPAN)
CPAN is a huge archive of Perl source code, documentation, scripts, and modules that is replicated at over a hundred sites around the world. Information on CPAN can be found at http://www.cpan.org. The easiest way to find the modules on CPAN is to use the search engine developed and maintained by Elaine Ashton, Graham Barr, and Clifton Posey at http://search.cpan.org. The “CPAN Search:” box makes it simple to find the right modules for the job.
- Individual repositories for pre-built packages
In a moment we’ll encounter the Perl Package Manager (PPM ), an especially important tool for Win32 Perl users. This tool connects to repositories (the most famous one is housed at ActiveState) to retrieve pre-built module packages. A good list of these repositories can be found in the PPM Frequently Asked Questions list at http://www.activestate.com/Products/ActivePerl//docs/faq/ActivePerl-faq2.html. If a Win32 package we use does come from a repository other than ActiveState’s, I’ll be sure to point you at it. For MacOS modules, the canonical place to look is the MacPerl Module Porters site at http://pudge.net/mmp/.
- Individual web sites
Some modules are not published to CPAN or any of the PPM repositories. I’ll always tell you where to get modules if they are found off the beaten path.
How do you install one of these modules when you find it? The answer
depends on the operating system you are running. Perl now ships with
documentation on this process in a file called
perlmodinstall.pod
(type perldoc
perlmodinstall to read it). The next sections provide brief
summaries of the steps required for each operating system used in
this book.
In most cases, the process goes like this:
Download the module and unpack it.
Run perl
Makefile.PL
to create the necessaryMakefile.
Run make to build the package.
Run make test to run any test suites included with the module by the author.
Run make install to install it in the usual place for modules on your system.
If you want to save yourself the trouble of performing these steps
all by hand, you can use the CPAN
module by
Andreas J. König (shipped with Perl). This module allows you to
perform all of those steps by typing:
%perl -MCPAN -e shell
cpan>install
modulename
The CPAN
module is smart
enough to handle module dependencies (i.e., if one module requires
another module to run, it will install both modules for you
automatically). CPAN
also has a built-in search
function for finding related modules and packages. I recommend typing
perldoc CPAN on your system to see all of the
handy features of this module.
The process for installing modules on Win32 platforms mirrors that for Unix with one additional step, ppm. If you plan to install modules by hand using the Unix instructions above, you can use programs like WinZip (http://www.winzip.com) to unpack a distribution and nmake (found at ftp://ftp.microsoft.com/Softlib/MSLFILES/nmake15.exe) instead of make to build and install a module.
Some modules require compilation of C files as part of their build process. A large portion of the Perl users in the Win32 world do not have the necessary software installed on their computers for this compilation, so ActiveState created the Perl Package Manager to handle pre-built module distribution.
The PPM system is similar to that of
the CPAN
module. It uses a Perl program called
ppm.pl
to handle the download and installation
of special archive files from PPM repositories. You can either start
this program by typing ppm or by running
perl ppm.pl from within the Perl
bin
directory:
C:\Perl\bin>perl ppm.pl
PPM interactive shell (1.1.1) - type 'help' for available commands. PPM>install
module-name
ppm, like CPAN
, can also search
the list of available and installed modules for you. Type
help at the ppm command
prompt for more information on how to use these commands.
Installing
modules on MacOS is a strange hybrid of the methods we’ve seen
so far. Chris Nandor has put together a distribution called
cpan-mac (found either at CPAN or http://pudge.net/macperl) that includes
ports of CPAN
and a whole slew of other important
modules to the Mac.
Once the cpan-mac distribution is installed, it is
possible to download most Perl-only modules from CPAN and install
them. Nandor makes this task easy by providing an MacPerl droplet
called installme. Archive files (i.e.,
.tar.gz
files) dropped on top of
installme will be de-archived and installed in a
CPAN
-like fashion.
For more information on MacOS module installation, be sure to see an
expanded version of the perlmodinstall.pod
document mentioned earlier called macperl
modinstall.pod.
This can also be found at http://pudge.net/macperl.
Get Perl for System Administration now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.