# placed in a begin block so it gets executed before we # try to load any modules. use XXX statements for non-core # modules should be placed after this begin block BEGIN { # Taint mode will complain unless you set these paths. $ENV{PATH} = ""; $ENV{CDPATH} = ""; sub calcLib { if (caller(3)) { #this is loaded as module: caller(3) returns the files caller #can't use __FILE__ between {} my $sModuleFile = __FILE__; $sModuleFile = $INC{ $sModuleFile }; return $sModuleFile =~ /bin\/[^\/]+$/ ? "$sModuleFile/../../lib" : "$sModuleFile/.."; } else { #this is the main entry point: caller(3) returns no caller #use FindBin to get the full file path of this directory #untaint FindBin::Bin my $sModuleDir = $1 if ($FindBin::Bin =~ m/^(.*)$/); return $sModuleDir =~ m/\/bin$/ ? $sModuleDir . "/../lib" : $sModuleDir; } } use lib (calcLib); }