I don't know what the best approach would be to allow the following:
I would like a program P to use a module M.pm, and they currently (and
always will) reside together in the same directory. I would like to be able to rename that directory and have it still work. I would also like to be able to run P from an arbitrary location, such that $CWD is not predictable. The code below does not satisfy these two requirements.
Here is the program that resides in ~/P:
#! /usr/bin/perl -w
use strict;
use M;
my $m = M->new;
and here is the module 'M' that resides in
~/M.pm:
package M;
sub new {1};
1;
I have considered:
- an install-time patching of the shebang to include the correct current path
- an install-time patching of a config file with the lib path
- some fiddling with $0, and unshifting the dir onto @INC
Can anyone suggest something better?