Granted, the correct alternative to FindBin is quite cumbersome. If it’s as annoying as this, and FindBin largely “works”, people will just shrug and do the wrong thing because it’s easier and its brokenness doesn’t usually affect them – an understandable reaction.
So I’m thinking I should wrap up the right approach in a tarball and put it on CPAN; something like
lib::relative where in the simplest case you can just say
But it could also do more; consider the following:
# Cwd::cwd() eq '/home/jrh'
# $0 eq 'bin/foo.pl`
use File::Spec::Functions qw( catpath splitpath rel2abs catdir );
use lib catpath( ( splitpath( rel2abs $0 ) )[ 0, 1 ], catdir( qw( lib perl5 ) ) );
# $INC eq '/home/jrh/bin/lib/perl5'
It would be trivial to have
import take extra arguments that are interpreted as path segments, so the above doozy becomes just this:
use lib::relative qw( lib perl5 );