New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove PATH-searching in FindBin #11297
Comments
From @perlpunkCreated by @perlpunkFindBin checks $ENV{PATH} for the current script name if $0 is not absolute So when a script uses FindBin and is called by $ perl perlscript.pl PATH is searched. In all other cases it takes the CWD and $0. So this feature is/was only useful for the case: I assume that anyone running a very old SunOS with that very old Unfortunately though, this feature will result in wrong paths when calling $ perl perlscript.pl under certain circumstances. If perlscript.pl is not executable and there is a perlscript.pl $ perl ./perlscript.pl So we have a feature that is very probably not needed anymore and Since FindBin is very handy, having the path in a variable so you can easily I would suggest to remove that old "feature" so that FindBin can be Also there should be mentioned in the docs that FindBin might give Attached is a patch written by Moritz Lenz. (*) /home/user $ perl perlscript.pl # calls /home/user/perlscript.pl since . is in PATH Perl Info
|
From @perlpunkFindBin.patchFrom 14d857058cef9f55b49413a3a13d2197945fc030 Mon Sep 17 00:00:00 2001
From: Moritz Lenz <moritz@faui2k3.org>
Date: Fri, 29 Apr 2011 19:44:52 +0200
Subject: [PATCH] Remove long-stading limitation from FindBin
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The FindBin documentation states as a known bug that it will return
a wrong result if a script of the same name as the current one exists in
$PATH, and is executable.
This patch removes the functionality of searching through $PATH.
According to Graham Barr it was only necessary because the SysV shell on
Sun4OS4 was broken - a system where I can't imagine anybody wanting
(and successfully compiling) a modern perl.
On Linux this part wasn't necessary in the case of `perl -S scriptname',
tests on other platforms are very welcome.
As a side effect, this patch also removes some IO operations, speeding up
FindBin slightly.
This patch is based on discussions with Tina M��ller.
Further "discussion": http://www.perlmonks.org/?node_id=41213
---
lib/FindBin.pm | 41 +----------------------------------------
1 files changed, 1 insertions(+), 40 deletions(-)
diff --git a/lib/FindBin.pm b/lib/FindBin.pm
index 892d6e5..cf6ecf2 100644
--- a/lib/FindBin.pm
+++ b/lib/FindBin.pm
@@ -59,21 +59,6 @@ workaround was to force the C<BEGIN> block to be executed again:
delete $INC{'FindBin.pm'};
require FindBin;
-=head1 KNOWN BUGS
-
-If perl is invoked as
-
- perl filename
-
-and I<filename> does not have executable rights and a program called
-I<filename> 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
-
- perl ./filename
-
=head1 AUTHORS
FindBin is supported as part of the core perl distribution. Please send bug
@@ -103,7 +88,7 @@ use File::Spec;
%EXPORT_TAGS = (ALL => [qw($Bin $Script $RealBin $RealScript $Dir $RealDir)]);
@ISA = qw(Exporter);
-$VERSION = "1.50";
+$VERSION = "1.51";
# needed for VMS-specific filename translation
@@ -145,30 +130,6 @@ sub init
}
else
{
- my $dosish = ($^O eq 'MSWin32' or $^O eq 'os2');
- unless(($script =~ m#/# || ($dosish && $script =~ m#\\#))
- && -f $script)
- {
- my $dir;
- foreach $dir (File::Spec->path)
- {
- my $scr = File::Spec->catfile($dir, $script);
-
- # $script can been found via PATH but perl could have
- # been invoked as 'perl file'. Do a dumb check to see
- # if $script is a perl program, if not then keep $script = $0
- #
- # well we actually only check that it is an ASCII file
- # we know its executable so it is probably a script
- # of some sort.
- if(-f $scr && -r _ && ($dosish || -x _) && -s _ && -T _)
- {
- $script = $scr;
- last;
- }
- }
- }
-
croak("Cannot find current script '$0'") unless(-f $script);
# Ensure $script contains the complete path in case we C<chdir>
--
1.7.2.5
|
From @cpansproutOn Mon May 02 10:17:02 2011, tinita wrote:
Thank you. Applied as ce6c0f3. |
The RT System itself - Status changed from 'new' to 'open' |
@cpansprout - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#89698 (status was 'resolved')
Searchable as RT89698$
The text was updated successfully, but these errors were encountered: