Quotes fixed, see also perl #36079
[p5sagit/p5-mst-13.2.git] / lib / FindBin.pm
index c1b782c..b1d6404 100644 (file)
@@ -39,9 +39,29 @@ directory.
  $RealBin     - $Bin with all links resolved
  $RealScript  - $Script with all links resolved
 
+=head1 KNOWN ISSUES
+
+If there are two modules using C<FindBin> from different directories
+under the same interpreter, this won't work. Since C<FindBin> uses a
+C<BEGIN> block, it'll be executed only once, and only the first caller
+will get it right. This is a problem under mod_perl and other persistent
+Perl environments, where you shouldn't use this module. Which also means
+that you should avoid using C<FindBin> in modules that you plan to put
+on CPAN. To make sure that C<FindBin> will work is to call the C<again>
+function:
+
+  use FindBin;
+  FindBin::again(); # or FindBin->again;
+
+In former versions of FindBin there was no C<again> function. The
+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
+If perl is invoked as
 
    perl filename
 
@@ -73,7 +93,7 @@ package FindBin;
 use Carp;
 require 5.000;
 require Exporter;
-use Cwd qw(getcwd abs_path);
+use Cwd qw(getcwd cwd abs_path);
 use Config;
 use File::Basename;
 use File::Spec;
@@ -82,9 +102,9 @@ use File::Spec;
 %EXPORT_TAGS = (ALL => [qw($Bin $Script $RealBin $RealScript $Dir $RealDir)]);
 @ISA = qw(Exporter);
 
-$VERSION = "1.42";
+$VERSION = "1.45";
 
-BEGIN
+sub init
 {
  *Dir = \$Bin;
  *RealDir = \$RealBin;
@@ -138,9 +158,11 @@ BEGIN
 
      croak("Cannot find current script '$0'") unless(-f $script);
 
-     # Ensure $script contains the complete path incase we C<chdir>
+     # Ensure $script contains the complete path in case we C<chdir>
 
-     $script = File::Spec->catfile(getcwd(), $script)
+     my $cwd = getcwd();
+     defined $cwd or $cwd = cwd(); # try harder
+     $script = File::Spec->catfile($cwd, $script)
        unless File::Spec->file_name_is_absolute($script);
 
      ($Script,$Bin) = fileparse($script);
@@ -165,5 +187,9 @@ BEGIN
   }
 }
 
+BEGIN { init }
+
+*again = \&init;
+
 1; # Keep require happy