Upgrade to Pathtools-3.18
[p5sagit/p5-mst-13.2.git] / lib / File / Spec / VMS.pm
index 58cac1e..f8c488d 100644 (file)
@@ -71,7 +71,7 @@ sub canonpath {
        $path =~ s/\[[^\]\.]+\.-\./\[/g;        # [foo.-.       ==> [
        $path =~ s/\.[^\]\.]+\.-\]/\]/g;        # .foo.-]       ==> ]
        $path =~ s/\[[^\]\.]+\.-\]/\[000000\]/g;# [foo.-]       ==> [000000]
-       $path =~ s/\[\]//;                      # []            ==>
+       $path =~ s/\[\]// unless $path eq '[]'; # []            ==>
        return $path;
     }
 }
@@ -85,9 +85,10 @@ cases (e.g. elements other than the first being absolute filespecs).
 =cut
 
 sub catdir {
-    my ($self,@dirs) = @_;
-    my $dir = pop @dirs;
-    @dirs = grep($_,@dirs);
+    my $self = shift;
+    my $dir = pop;
+    my @dirs = grep {defined() && length()} @_;
+
     my $rslt;
     if (@dirs) {
        my $path = (@dirs == 1 ? $dirs[0] : $self->catdir(@dirs));
@@ -118,9 +119,10 @@ VMS-syntax file specification.
 =cut
 
 sub catfile {
-    my ($self,@files) = @_;
-    my $file = $self->canonpath(pop @files);
-    @files = grep($_,@files);
+    my $self = shift;
+    my $file = $self->canonpath(pop());
+    my @files = grep {defined() && length()} @_;
+
     my $rslt;
     if (@files) {
        my $path = (@files == 1 ? $files[0] : $self->catdir(@files));
@@ -131,7 +133,7 @@ sub catfile {
        }
        else {
            $rslt = $self->eliminate_macros($spath);
-           $rslt = vmsify($rslt.($rslt ? '/' : '').unixify($file));
+           $rslt = vmsify($rslt.((defined $rslt) && ($rslt ne '') ? '/' : '').unixify($file));
        }
     }
     else { $rslt = (defined($file) && length($file)) ? vmsify($file) : ''; }
@@ -335,8 +337,10 @@ sub abs2rel {
 
     # Now, remove all leading components that are the same
     my @pathchunks = $self->splitdir( $path_directories );
+    my $pathchunks = @pathchunks;
     unshift(@pathchunks,'000000') unless $pathchunks[0] eq '000000';
     my @basechunks = $self->splitdir( $base_directories );
+    my $basechunks = @basechunks;
     unshift(@basechunks,'000000') unless $basechunks[0] eq '000000';
 
     while ( @pathchunks && 
@@ -347,11 +351,15 @@ sub abs2rel {
         shift @basechunks ;
     }
 
-    return $self->curdir unless @pathchunks || @basechunks;
-
     # @basechunks now contains the directories to climb out of,
     # @pathchunks now has the directories to descend in to.
-    $path_directories = join '.', ('-' x @basechunks, @pathchunks) ;
+    if ((@basechunks > 0) || ($basechunks != $pathchunks)) {
+      $path_directories = join '.', ('-' x @basechunks, @pathchunks) ;
+    }
+    else {
+      $path_directories = join '.', @pathchunks;
+    }
+    $path_directories = '['.$path_directories.']';
     return $self->canonpath( $self->catpath( '', $path_directories, $path_file ) ) ;
 }
 
@@ -419,7 +427,7 @@ sub rel2abs {
 # patch the ones in ExtUtils::MM_VMS instead.
 sub eliminate_macros {
     my($self,$path) = @_;
-    return '' unless $path;
+    return '' unless (defined $path) && ($path ne '');
     $self = {} unless ref $self;
 
     if ($path =~ /\s/) {