in reply to adding library directories relative to $0
Find::Lib appears to be exactly that.
use Find::Lib '../lib';
By the way, you have abs_path (aka realpath) and dirname backwards.
use Cwd qw( abs_path ); use File::Basename qw( dirname ); use lib dirname(abs_path($0)).'/../lib';
The order in which you use them will fail if you create a symlink to the script.
Update: Find::Lib touts its handling of symlinks, but it fails to handle a symlink to the script.
$ find ! -type d -exec ls -l {} + lrwxrwxrwx 1 eric users 8 Feb 22 17:04 ./a.pl -> bin/a.pl -rwx------ 1 eric users 53 Feb 22 17:04 ./bin/a.pl -rw------- 1 eric users 16 Feb 22 17:03 ./lib/Mod.pm $ cat bin/a.pl #!/usr/bin/env perl use Find::Lib '../lib'; use Mod; $ cat lib/Mod.pm package Mod; 1; $ bin/a.pl $ a.pl Can't locate Mod.pm in @INC (@INC contains: /home/eric/usr/perlbrew/pe +rls/perl-5.12.2/lib/site_perl/5.12.2/i686-linux /home/eric/usr/perlbr +ew/perls/perl-5.12.2/lib/site_perl/5.12.2 /home/eric/usr/perlbrew/per +ls/perl-5.12.2/lib/5.12.2/i686-linux /home/eric/usr/perlbrew/perls/pe +rl-5.12.2/lib/5.12.2 .) at ./a.pl line 3. BEGIN failed--compilation aborted at ./a.pl line 3.
|
|---|