# add custom libraries location to @INC my $lib_location; BEGIN { # only included during BEGIN use Cwd qw(realpath); use File::Spec::Functions 3.33 qw(splitpath catdir rel2abs); # rebase into absolute location if necessary; split into file components my ($vol_t, $prog_dir_t, $file_t) = splitpath( rel2abs($PROGRAM_NAME) ); my $lib_dir_t = catdir($prog_dir_t, '..', 'lib', 'perl5'); my $lib_loc_t = realpath(File::Spec->catpath($vol_t, $lib_dir_t, q{})); # force an untaint for $lib_loc_t - accept anything that has been provided # (or else we would have to create a regexp which would verify the correct # filename for UNIX, Windows, VMS, OS/2, ... - make sure this script is # in a sane location and cross fingers) $lib_location = ($lib_loc_t =~ /(.*)/xms)[0]; print "lib location: $lib_location\n"; } use lib $lib_location;