Troubleshooters.Com and Code Corner Present

Steve Litt's Perls of Wisdom:
Perl Modules Using CPAN
(With Snippets)

Copyright (C) 2003 by Steve Litt

Steve Litt is the author of Troubleshooting Techniques of the Successful TechnologistRapid Learning: Secret Weapon of the Successful Technologist, and Samba Unleashed.

Contents

Introduction

The Perl that comes stock on your Linux distribution or your Windows install is hugely powerful, but in fact it just scratches the surface. Throughout the years, people have created Perl modules to accomplish very specific tasks so that you don't need to rewrite the wheel to perform those same tasks.

But these modules are not, by default, on your computer. They reside on the CPAN website at http://www.cpan.org. Often you can simply download the Perl code comprising the new module, and place that Perl code in the right place. But sometimes it requires a recompile.

When working with Linux, you can actually use Perl itself to download, make, test and install new modules. That's often preferable.

Running the Perl CPAN Shell

Downloading and installing new modules can be done entirely from within the Perl CPAN shell. Working within the CPAN shell always triggers a compile, which can be good or bad, depending on the situation.

Obviously, if you have no C compiler (on a stock Windows box, for instance) or your C compiler is incompatible with the Perl modules, compiling is a bad thing. In cases where the new module is entirely Perl code, you'd be better downloading the module and manually placing it in the proper part of the Perl module tree. Also, compiling can take significant time, so you might want to go the straight Perl route. A further disadvantage of compiling is disk space. Source and object files take significant space, so if your /usr tree is almost full, you might want to stay away from compiles.

However, on fully compatible machines (Linux), using the CPAN shell with compiles is often the simplest route, and incorporates all features requiring recompilation.

To run the CPAN shell, AS ROOT run the following command:
perl -MCPAN -e 'shell'
You will be shown a prompt like this:
cpan> 
From that prompt you can get help with the help command:
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
cpan>


The main commands you'll use are get, make, test, and install. Although install would do all four, you should do them one at a time so that if there's an error you can better see exactly what happened. The clean command is helpful if you think you blew it and want to start over. look and readme are handy to see what's going on. You quit with q.

If it gripes about not having the proper header files, perhaps you don't have the header files for a higher level module. For instance, if your distro came with the .pm file for Tk, but not the headers, and then you try to compile Tk::JPEG, you would get such an error message. The solution is to get, make, test and install Tk, and then perform the same steps on Tk::JPEG.


 [ Troubleshooters.com| Code Corner | Email Steve Litt ]

Copyright (C)2003 by Steve Litt --Legal