package File::Spec::Unix;
use strict;
-our($VERSION);
+use vars qw($VERSION);
$VERSION = '1.4';
=item tmpdir
-Returns a string representation of the first writable directory
-from the following list or "" if none are writable:
+Returns a string representation of the first writable directory from
+the following list or the current directory if none from the list are
+writable:
$ENV{TMPDIR}
/tmp
=cut
my $tmpdir;
-sub tmpdir {
+sub _tmpdir {
return $tmpdir if defined $tmpdir;
- my @dirlist = ($ENV{TMPDIR}, "/tmp");
+ my $self = shift;
+ my @dirlist = @_;
{
no strict 'refs';
if (${"\cTAINT"}) { # Check for taint mode on perl >= 5.8.0
require Scalar::Util;
- shift @dirlist if Scalar::Util::tainted($ENV{TMPDIR});
+ @dirlist = grep { ! Scalar::Util::tainted($_) } @dirlist;
}
}
foreach (@dirlist) {
$tmpdir = $_;
last;
}
- $tmpdir = File::Spec->curdir unless defined $tmpdir;
+ $tmpdir = $self->curdir unless defined $tmpdir;
+ $tmpdir = defined $tmpdir && $self->canonpath($tmpdir);
return $tmpdir;
}
+sub tmpdir {
+ return $tmpdir if defined $tmpdir;
+ my $self = shift;
+ $tmpdir = $self->_tmpdir( $ENV{TMPDIR}, "/tmp" );
+}
+
=item updir
Returns a string representation of the parent directory. ".." on UNIX.
=item catpath()
Takes volume, directory and file portions and returns an entire path. Under
-Unix, $volume is ignored, and directory and file are catenated. A '/' is
+Unix, $volume is ignored, and directory and file are concatenated. A '/' is
inserted if needed (though if the directory portion doesn't start with
'/' it is not added). On other OSs, $volume is significant.