NAME

dual_lib_paths - collect lib dirs from both the physical and logical trees

SYNOPSIS

dual_lib_paths

DESCRIPTION

Calls FindBin::libs twice with different arguments to export two independent arrays of lib directories:

use FindBin::libs qw( abspath   export=remote );
use FindBin::libs qw( noabspath export=local  );

@remote holds the directories found walking up from $Bin_p (the physical path, symlinks resolved). @local holds the directories found walking up from $Bin_l (the logical path, symlinks preserved).

When no symlinks appear in the path, both arrays are identical. They differ when the script is invoked through a directory symlink.

Consider a layout where /home/user/app is a directory symlink pointing to the real source tree under /work/projects/app:

/home/user/                       # logical subtree (sandbox)
+-- lib/
|   \-- Override.pm               # alternate version for testing
\-- app -> /work/projects/app     # directory symlink

/work/projects/                   # physical subtree (production)
+-- lib/
|   \-- Production.pm             # stable version
\-- app/
    \-- bin/
        \-- myscript              # $0

Invoked as /home/user/app/bin/myscript:

$Bin_p = /work/projects/app/bin   # symlink resolved
$Bin_l = /home/user/app/bin       # symlink preserved

@remote  =>  ( '/work/projects/lib' )   # finds Production.pm
@local   =>  ( '/home/user/lib'     )   # finds Override.pm

Choosing which dirs to use lib

Export alone does not call use lib. To add both sets to @INC:

use FindBin::libs qw( abspath   use export=remote );
use FindBin::libs qw( noabspath use export=local  );

To load only the local (sandbox) tree, use @local after the fact:

use lib @local;

To prefer local overrides but fall back to remote, put local first:

use lib @local, @remote;

On a filesystem with no directory symlinks in the path, $Bin_l eq $Bin_p and both walks produce the same list. Keeping both calls is harmless in that case; @remote and @local simply hold the same paths.

SEE ALSO

FindBin::Bin, FindBin::libs, FindBin::Parents