FindBin::Real - Locate directory of original perl script
use FindBin::Real; use lib FindBin::Real::Bin() . '/../lib'; or use FindBin::Real qw(Bin); use lib Bin() . '/../lib'; or # Run from /usr/bin/www/some/path/ or /usr/bin/www/some/other/path or any use FindBin::Real qw(BinDepth); use lib BinDepth(3) . '/lib'; # And always got /usr/bin/www/lib !
Locates the full path to the script bin directory to allow the use of paths relative to the bin directory.
This allows a user to setup a directory tree for some software with directories <root>/bin and <root>/lib and then the above example will allow the use of modules in the lib directory without knowing where the software tree is installed.
If perl is invoked using the -e option or the perl script is read from STDIN then FindBin sets both Bin() and RealBin() return values to the current directory.
STDIN
Bin()
RealBin()
- path to bin directory from where script was invoked
- basename of script from which perl was invoked
- Bin() with all links resolved
- Script() with all links resolved
- path to n-level parent directory
- the same as Bin()
- the same as RealBin()
If there are two modules using FindBin::Real from different directories under the same interpreter, this WOULD work. Since FindBin::Real uses functions instead of BEGIN block in FindBin, it'll be executed on every script, and all callers will get it right. This module can be used under mod_perl and other persistent Perl environments, where you shouldn't use FindBin.
FindBin::Real
BEGIN
FindBin
If perl is invoked as
perl filename
and filename does not have executable rights and a program called filename exists in the users $ENV{PATH} which satisfies both -x and -T then FindBin assumes that it was invoked via the $ENV{PATH}.
$ENV{PATH}
Workaround is to invoke perl as
perl ./filename
Serguei Trouchelle <stro@railways.dp.ua>
FindBin::Real uses code from FindBin module, which was written by
Graham Barr <gbarr@pobox.com> Nick Ing-Simmons <nik@tiuk.ti.com>
Copyright (c) 1995 Graham Barr & Nick Ing-Simmons. All rights reserved. Copyright (c) 2003-2005 Serguei Trouchelle. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install FindBin::Real, copy and paste the appropriate command in to your terminal.
cpanm
cpanm FindBin::Real
CPAN shell
perl -MCPAN -e shell install FindBin::Real
For more information on module installation, please visit the detailed CPAN module installation guide.