In the past I've been typing over and over again the following kind of things:
use lib "$Bin/../../../app/lib";
use lib "$Bin/../locallib/";
use lib "$Bin/../../../common/lib";
use Bootstrap; # smartely imports additional libraries for my app
Especially in test files, I use this all over the place. The nice concept with the exported $Bin variable is that it allows you to specify local libs path relative to the given script or tool, making the code transportable easily.
But now, what I do, is I install everywhere I can Find::Lib module, that provides some nice benefits:
- reduces the typing to one line in most cases
- no crufty $Bin thing which doesn't even indicate a binary
- since version 0.04 handles well the case where symlinks are used all over the place (which is not the case whith FindBin)
The second example is advantageously rewritten to:
In conclusion, wherever you can install Find::Lib in system PERL5LIB, I recommend you use Find::Lib. Everywhere else you can use the buggy FindBin which is in Perl core, it is still better than using absolute paths in the source. Another solution is to use $ENV variables to indicate an application "base", but personnally I dislike it because I feel like I'll forget to update the env variable.
update: I just found out rlib on CPAN that has been around for 9 years. Find::Lib is more capable though