1 package File::Spec::Unix;
7 File::Spec::Unix - methods used by File::Spec
11 require File::Spec::Unix; # Done automatically by File::Spec
15 Methods for manipulating file specifications.
23 No physical check on the filesystem, but a logical cleanup of a
24 path. On UNIX eliminated successive slashes and successive "/.".
29 my ($self,$path) = @_;
30 $path =~ s|/+|/|g; # xx////xx -> xx/xx
31 $path =~ s|(/\.)+/|/|g; # xx/././xx -> xx/xx
32 $path =~ s|^(\./)+|| unless $path eq "./"; # ./xx -> xx
33 $path =~ s|/$|| unless $path eq "/"; # xx/ -> xx
39 Concatenate two or more directory names to form a complete path ending
40 with a directory. But remove the trailing slash from the resulting
41 string, because it doesn't look good, isn't necessary and confuses
42 OS2. Of course, if this is the root directory, don't cut off the
51 # append a slash to each argument unless it has one there
52 $_ .= "/" if $_ eq '' || substr($_,-1) ne "/";
54 return $self->canonpath(join('', @args));
59 Concatenate one or more directory names and a filename to form a
60 complete path ending with a filename
67 return $file unless @_;
68 my $dir = $self->catdir(@_);
69 $dir .= "/" unless substr($dir,-1) eq "/";
75 Returns a string representation of the current directory. "." on UNIX.
85 Returns a string representation of the null device. "/dev/null" on UNIX.
95 Returns a string representation of the root directory. "/" on UNIX.
105 Returns a string representation of the first writable directory
106 from the following list or "" if none are writable:
115 return $tmpdir if defined $tmpdir;
116 foreach ($ENV{TMPDIR}, "/tmp") {
117 next unless defined && -d && -w _;
121 $tmpdir = '' unless defined $tmpdir;
127 Returns a string representation of the parent directory. ".." on UNIX.
137 Given a list of file names, strip out those that refer to a parent
138 directory. (Does not strip symlinks, only '.', '..', and equivalents.)
144 return grep(!/^\.{1,2}$/, @_);
147 =item file_name_is_absolute
149 Takes as argument a path and returns true, if it is an absolute path.
153 sub file_name_is_absolute {
154 my ($self,$file) = @_;
155 return scalar($file =~ m:^/:);
160 Takes no argument, returns the environment variable PATH as an array.
165 my @path = split(':', $ENV{PATH});
166 foreach (@path) { $_ = '.' if $_ eq '' }
172 join is the same as catfile.
178 return $self->catfile(@_);