Bash function for directory-dependent local::lib
On my laptop I use perlbrew to keep my system perl separate from my development perl. But I also develop various Perl projects with different dependencies, and would like to keep those dependencies separate if possible. Using a separate perlbrew perl for each project as well would be overkill in terms of diskspace, CPU energy and time so I thought local::lib might be useful.
If I install dependencies for a particular project using "cpanm -l extlib $MODULE" in the top level directory, the function below will automatically setup local::lib for that location when I change into that directory, and unset it when I change out. I use a test for the existence of a "extlib" directory and a Makefile.PL file because that is what I consistently have.
# Automatic local::lib setup based on extlib directory
if [[ $PWD != $MYOLDPWD ]]; then
if [[ -n $VERY_LOCAL_LIB_PATH ]]; then
export PATH=`echo $PATH | sed -e "s|$VERY_LOCAL_LIB_PATH:||g"`
if [[ -e Makefile.PL && -d extlib ]]; then
eval `perl -Mlocal::lib=extlib`
echo "[Using local::lib with $PWD/extlib]";
if [[ -n $OLDPERL5LIB ]]; then
echo "[local::lib turned off]";
Can this be improved? Is there are better way of achieving location dependent local::lib without resorting to FindBin/local::lib trickery in test scripts? It has also been mentioned that perlbrew and local::lib don't work together. If "extlib" was a perl-version-dependent location this could also be overcome.