Managing multiple Perl module directories

If you develop in Perl or act as a system administrator, you have undoubtedly come up against the hassle of managing local collections of Perl modules.

I’ve tried everything in the past. I’ve built modules by hand specifying Makefile.PL prefix paths. I’ve flattened architecture specific directories. I’ve lived through the introduction of Module::Build and the inconsistencies between it and EUMM. I’ve built bundles, packages, even virtual machines. I’ve scripted in the shell and with CPAN/CPANplus.

Still, maintaining distinct directories of Perl modules for multiple current applications was a pain. Until now.

local::lib gets around the tedium of maintaining local Perl libraries. It modifies environment variables for you so you don’t have to screw with -I, INSTALL_BASE, –install_base, or PREFIX. Best of all, you can continue to use CPAN, too!

Here’s how easy it is:

 # install local::lib globally (assuming you have sudo/root)
 $ sudo perl -MCPAN -e 'CPAN::install(local::lib)
 # Set your local library dir
 $ cd ~/my_project/extlib
 # Set this as your local lib dir
 $ perl -Mlocal::lib=./

 # Update your environment for the current shell
 $ eval $(perl -Mlocal::lib=--self-contained,./)

 # Install a module
 $ perl -MCPAN -e 'CPAN::install(GD::SVG)'

A thing of beauty, really.