I’ve taken over a project written in Perl that has a few dependencies such as Template::Toolkit, Image::ExifTool, and GD to name a few. Currently, these dependencies are built into a directory (“deps” folder) using the --prefix option in make. In the main Perl script, I have something like the following to import the necessary modules:
use File::Spec::Functions qw(catdir);
use lib "lib";
use lib catdir(qw(deps lib perl5 site_perl));
catdir is used to stray away from certain system requirements (such as assuming ‘/’ is the folder separator; if someone has another alternative, I’m open to suggestions!). The “lib” folder contains my modules, and the “deps/lib/perl5/site_perl” folder is where my dependencies were installed on my original machine.
However, after building the dependencies on another machine, it seems the needed libraries have moved around to different folders. I now need to use these statements for my script to run correctly:
use File::Spec::Functions qw(catdir);
use lib "lib";
use lib catdir(qw(deps lib perl 5.14.2));
use lib catdir(qw(deps share perl 5.14.2));
I was wondering if there was anyway specify the prefix directory (“deps”) and have the use lib pragma recursively search through that directory for my dependencies. Also, the users of this script do not have access to the Internet, so compiling my project as a CPAN module would be counterproductive.
Thanks for all the help!
Use INSTALL_BASE for the Makefile.PL and –install_base for Build.PL when installing modules. They provide stable install locations. PREFIX and –prefix try to emulate how perl has its system libraries laid out and is more useful for making packages.
Also you’ll want to run
rel2absover the path before feeding it to lib to give you an absolute path. This will protect you in case your codechdirs and then tries torequirea module. Or you can use lib::abs.And ikegami is correct, it’s unnecessary to make the file paths passed to lib portable. Just pass them in Unix style. Perl will figure it out.