Random Perl: Application local modules
Tuesday, October 14th, 2008 at 5:52 amPerl apps sometimes need modules that belong to them and aren’t installed into any global path.
Consider the following code:
use File::Spec::Functions qw(catpath splitpath rel2abs catdir);
use lib catpath((splitpath(rel2abs $0))[0, 1], catdir(qw(lib)));
If my program was named application (full path is /home/diablo/application-1.2.3/application), no matter how I ran it (via full path, ./application, ../application-1.2.3/application, /symlink_to_application-1.2.3/application, etc) or what I ran it from (console, fastcgi, mod_perl, etc), this code can find the directory named lib (full path is /home/diablo/application-1.2.3/lib/), and add it to Perl’s internal list of directories to look for modules in (aka @INC).
Thanks Aristotle!