1 package File::Spec::Unix;
5 use File::Basename qw(basename dirname fileparse);
8 use vars qw(@ISA $Is_Mac $Is_OS2 $Is_VMS $Is_Win32);
11 Exporter::import('File::Spec', '$Verbose');
13 $Is_OS2 = $^O eq 'os2';
14 $Is_Mac = $^O eq 'MacOS';
15 $Is_Win32 = $^O eq 'MSWin32';
17 if ($Is_VMS = $^O eq 'VMS') {
18 require VMS::Filespec;
19 import VMS::Filespec qw( &vmsify );
24 File::Spec::Unix - methods used by File::Spec
28 C<require File::Spec::Unix;>
32 Methods for manipulating file specifications.
40 No physical check on the filesystem, but a logical cleanup of a
41 path. On UNIX eliminated successive slashes and successive "/.".
47 $path =~ s|/+|/|g ; # xx////xx -> xx/xx
48 $path =~ s|(/\.)+/|/|g ; # xx/././xx -> xx/xx
49 $path =~ s|^(\./)+|| unless $path eq "./"; # ./xx -> xx
50 $path =~ s|/$|| unless $path eq "/"; # xx/ -> xx
56 Concatenate two or more directory names to form a complete path ending
57 with a directory. But remove the trailing slash from the resulting
58 string, because it doesn't look good, isn't necessary and confuses
59 OS2. Of course, if this is the root directory, don't cut off the
70 # append a slash to each argument unless it has one there
71 $_ .= "/" if $_ eq '' or substr($_,-1) ne "/";
73 my $result = join('', @args);
74 # remove a trailing slash unless we are root
75 substr($result,-1) = ""
76 if length($result) > 1 && substr($result,-1) eq "/";
82 Concatenate one or more directory names and a filename to form a
83 complete path ending with a filename
90 return $file unless @_;
91 my $dir = $self->catdir(@_);
93 $_ .= "/" unless substr($_,length($_)-1,1) eq "/";
100 Returns a string representing of the current directory. "." on UNIX.
110 Returns a string representing of the root directory. "/" on UNIX.
120 Returns a string representing of the parent directory. ".." on UNIX.
130 Given a list of file names, strip out those that refer to a parent
131 directory. (Does not strip symlinks, only '.', '..', and equivalents.)
137 return grep(!/^\.{1,2}$/, @_);
140 =item file_name_is_absolute
142 Takes as argument a path and returns true, if it is an absolute path.
146 sub file_name_is_absolute {
147 my($self,$file) = @_;
153 Takes no argument, returns the environment variable PATH as an array.
160 my $path = $ENV{PATH};
161 my @path = split $path_sep, $path;
162 foreach(@path) { $_ = '.' if $_ eq '' }
168 join is the same as catfile.
173 my($self) = shift @_;
184 my($self,$name) = shift @_;