From 34da6cec5a776efea53d807532e089a20e26cba6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Pedro=20Oliveira?= Date: Thu, 12 May 2005 21:36:48 +0100 Subject: [PATCH] Improve FindBin discovery of current directory, based on : Subject: FindBin.pm: incomplete getcwd/cwd patch? (#24375, #24379) Message-ID: <4283B050.6080805@di.uminho.pt> Plus POD fixes p4raw-id: //depot/perl@24704 --- lib/FindBin.pm | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/FindBin.pm b/lib/FindBin.pm index b1d6404..353a904 100644 --- a/lib/FindBin.pm +++ b/lib/FindBin.pm @@ -24,9 +24,9 @@ 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 ErootE/bin and ErootE/lib and then the above example will allow -the use of modules in the lib directory without knowing where the software -tree is installed. +directories C<< /bin >> and C<< /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 B<-e> option or the perl script is read from C then FindBin sets both C<$Bin> and C<$RealBin> to the current @@ -65,9 +65,10 @@ If perl is invoked as perl filename -and I does not have executable rights and a program called I -exists in the users C<$ENV{PATH}> which satisfies both B<-x> and B<-T> then FindBin -assumes that it was invoked via the C<$ENV{PATH}>. +and I does not have executable rights and a program called +I exists in the users C<$ENV{PATH}> which satisfies both B<-x> +and B<-T> then FindBin assumes that it was invoked via the +C<$ENV{PATH}>. Workaround is to invoke perl as @@ -76,7 +77,8 @@ Workaround is to invoke perl as =head1 AUTHORS FindBin is supported as part of the core perl distribution. Please send bug -reports to EFE using the perlbug program included with perl. +reports to EFE using the perlbug program +included with perl. Graham Barr EFE Nick Ing-Simmons EFE @@ -102,7 +104,15 @@ use File::Spec; %EXPORT_TAGS = (ALL => [qw($Bin $Script $RealBin $RealScript $Dir $RealDir)]); @ISA = qw(Exporter); -$VERSION = "1.45"; +$VERSION = "1.46"; + +sub cwd2 { + my $cwd = getcwd(); + # getcwd might fail if it hasn't access to the current directory. + # try harder. + defined $cwd or $cwd = cwd(); + $cwd; +} sub init { @@ -112,9 +122,8 @@ sub init if($0 eq '-e' || $0 eq '-') { # perl invoked with -e or script is on C - $Script = $RealScript = $0; - $Bin = $RealBin = getcwd(); + $Bin = $RealBin = cwd2(); } else { @@ -160,9 +169,7 @@ sub init # Ensure $script contains the complete path in case we C - my $cwd = getcwd(); - defined $cwd or $cwd = cwd(); # try harder - $script = File::Spec->catfile($cwd, $script) + $script = File::Spec->catfile(cwd2(), $script) unless File::Spec->file_name_is_absolute($script); ($Script,$Bin) = fileparse($script); @@ -192,4 +199,3 @@ BEGIN { init } *again = \&init; 1; # Keep require happy - -- 2.7.4