Tweaks to get Test::Builder::Tester's tests to work in the core.
[p5sagit/p5-mst-13.2.git] / lib / Cwd.pm
index cf07cb4..8d25af9 100644 (file)
@@ -170,7 +170,7 @@ use strict;
 use Exporter;
 use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION);
 
-$VERSION = '3.04';
+$VERSION = '3.12';
 
 @ISA = qw/ Exporter /;
 @EXPORT = qw(cwd getcwd fastcwd fastgetcwd);
@@ -199,15 +199,16 @@ if ($^O eq 'os2') {
     return 1;
 }
 
+# If loading the XS stuff doesn't work, we can fall back to pure perl
 eval {
-if ( $] >= 5.006 ) {
-  require XSLoader;
-  XSLoader::load( __PACKAGE__, $VERSION );
-} else {
-  require DynaLoader;
-  push @ISA, 'DynaLoader';
-  __PACKAGE__->bootstrap( $VERSION );
-}
+  if ( $] >= 5.006 ) {
+    require XSLoader;
+    XSLoader::load( __PACKAGE__, $VERSION );
+  } else {
+    require DynaLoader;
+    push @ISA, 'DynaLoader';
+    __PACKAGE__->bootstrap( $VERSION );
+  }
 };
 
 # Must be after the DynaLoader stuff:
@@ -314,7 +315,10 @@ sub _croak { require Carp; Carp::croak(@_) }
 
 # The 'natural and safe form' for UNIX (pwd may be setuid root)
 sub _backtick_pwd {
-    local @ENV{qw(PATH IFS CDPATH ENV BASH_ENV)};
+    # Localize %ENV entries in a way that won't create new hash keys
+    my @localize = grep exists $ENV{$_}, qw(PATH IFS CDPATH ENV BASH_ENV);
+    local @ENV{@localize};
+    
     my $cwd = `$pwd_cmd`;
     # Belt-and-suspenders in case someone said "undef $/".
     local $/ = "\n";
@@ -329,8 +333,9 @@ sub _backtick_pwd {
 unless ($METHOD_MAP{$^O}{cwd} or defined &cwd) {
     # The pwd command is not available in some chroot(2)'ed environments
     my $sep = $Config::Config{path_sep} || ':';
-    if( $^O eq 'MacOS' || (defined $ENV{PATH} &&
-                          $^O ne 'MSWin32' &&  # no pwd on Windows
+    my $os = $^O;  # Protect $^O from tainting
+    if( $os eq 'MacOS' || (defined $ENV{PATH} &&
+                          $os ne 'MSWin32' &&  # no pwd on Windows
                           grep { -x "$_/pwd" } split($sep, $ENV{PATH})) )
     {
        *cwd = \&_backtick_pwd;
@@ -640,10 +645,7 @@ sub _win32_cwd {
     return $ENV{'PWD'};
 }
 
-*_NT_cwd = \&_win32_cwd if (!defined &_NT_cwd && 
-                            defined &Win32::GetCwd);
-
-*_NT_cwd = \&_os2_cwd unless defined &_NT_cwd;
+*_NT_cwd = defined &Win32::GetCwd ? \&_win32_cwd : \&_os2_cwd;
 
 sub _dos_cwd {
     if (!defined &Dos::GetCwd) {