This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update ExtUtils-Install to 1.51
[perl5.git] / lib / Cwd.pm
index fa5948c..3bf704f 100644 (file)
@@ -171,7 +171,9 @@ use strict;
 use Exporter;
 use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION);
 
-$VERSION = '3.22';
+$VERSION = '3.29';
+my $xs_version = $VERSION;
+$VERSION = eval $VERSION;
 
 @ISA = qw/ Exporter /;
 @EXPORT = qw(cwd getcwd fastcwd fastgetcwd);
@@ -204,11 +206,11 @@ if ($^O eq 'os2') {
 eval {
   if ( $] >= 5.006 ) {
     require XSLoader;
-    XSLoader::load( __PACKAGE__, $VERSION );
+    XSLoader::load( __PACKAGE__, $xs_version);
   } else {
     require DynaLoader;
     push @ISA, 'DynaLoader';
-    __PACKAGE__->bootstrap( $VERSION );
+    __PACKAGE__->bootstrap( $xs_version );
   }
 };
 
@@ -479,7 +481,9 @@ sub chdir {
        return 1;
     }
 
-    if ($newdir =~ m#^/#s) {
+    if (ref $newdir eq 'GLOB') { # in case a file/dir handle is passed in
+       $ENV{'PWD'} = cwd();
+    } elsif ($newdir =~ m#^/#s) {
        $ENV{'PWD'} = $newdir;
     } else {
        my @curdir = split(m#/#,$ENV{'PWD'});
@@ -538,8 +542,8 @@ sub _perl_abs_path
        local *PARENT;
        unless (opendir(PARENT, $dotdots))
        {
-           _carp("opendir($dotdots): $!");
-           return '';
+           # probably a permissions issue.  Try the native command.
+           return File::Spec->rel2abs( $start, _backtick_pwd() );
        }
        unless (@cst = stat($dotdots))
        {
@@ -642,11 +646,38 @@ sub _vms_cwd {
 
 sub _vms_abs_path {
     return $ENV{'DEFAULT'} unless @_;
+    my $path = shift;
 
-    # may need to turn foo.dir into [.foo]
-    my $path = VMS::Filespec::pathify($_[0]);
-    $path = $_[0] unless defined $path;
+    if (-l $path) {
+        my $link_target = readlink($path);
+        die "Can't resolve link $path: $!" unless defined $link_target;
+           
+        return _vms_abs_path($link_target);
+    }
+
+    if (defined &VMS::Filespec::vms_realpath) {
+        my $path = $_[0];
+        if ($path =~ m#(?<=\^)/# ) {
+            # Unix format
+            return VMS::Filespec::vms_realpath($path);
+        }
+
+       # VMS format
+
+       my $new_path = VMS::Filespec::vms_realname($path); 
 
+       # Perl expects directories to be in directory format
+       $new_path = VMS::Filespec::pathify($new_path) if -d $path;
+       return $new_path;
+    }
+
+    # Fallback to older algorithm if correct ones are not
+    # available.
+
+    # may need to turn foo.dir into [.foo]
+    my $pathified = VMS::Filespec::pathify($path);
+    $path = $pathified if defined $pathified;
+       
     return VMS::Filespec::rmsexpand($path);
 }
 
@@ -658,7 +689,12 @@ sub _os2_cwd {
 }
 
 sub _win32_cwd {
-    $ENV{'PWD'} = Win32::GetCwd();
+    if (defined &DynaLoader::boot_DynaLoader) {
+       $ENV{'PWD'} = Win32::GetCwd();
+    }
+    else { # miniperl
+       chomp($ENV{'PWD'} = `cd`);
+    }
     $ENV{'PWD'} =~ s:\\:/:g ;
     return $ENV{'PWD'};
 }