File::Temp tests were failing in Cygwin if $ENV{TMPDIR}
[p5sagit/p5-mst-13.2.git] / lib / File / Spec / Cygwin.pm
1 package File::Spec::Cygwin;
2
3 use strict;
4 use vars qw(@ISA $VERSION);
5 require File::Spec::Unix;
6
7 $VERSION = '1.0';
8
9 @ISA = qw(File::Spec::Unix);
10
11 sub canonpath {
12     my($self,$path) = @_;
13     $path =~ s|\\|/|g;
14     return $self->SUPER::canonpath($path);
15 }
16
17 sub file_name_is_absolute {
18     my ($self,$file) = @_;
19     return 1 if $file =~ m{^([a-z]:)?[\\/]}is; # C:/test
20     return $self->SUPER::file_name_is_absolute($file);
21 }
22
23 my $tmpdir;
24 sub tmpdir {
25     return $tmpdir if defined $tmpdir;
26     my @dirlist = ($ENV{TMPDIR}, "/tmp", 'C:/temp');
27     {
28         no strict 'refs';
29         if (${"\cTAINT"}) { # Check for taint mode on perl >= 5.8.0
30             require Scalar::Util;
31             shift @dirlist if Scalar::Util::tainted($ENV{TMPDIR});
32         }
33     }
34     foreach (@dirlist) {
35         next unless defined && -d && -w _;
36         $tmpdir = $_;
37         last;
38     }
39     $tmpdir = '' unless defined $tmpdir;
40     return $tmpdir;
41 }
42
43 1;
44 __END__
45
46 =head1 NAME
47
48 File::Spec::Cygwin - methods for Cygwin file specs
49
50 =head1 SYNOPSIS
51
52  require File::Spec::Cygwin; # Done internally by File::Spec if needed
53
54 =head1 DESCRIPTION
55
56 See File::Spec::Unix for a documentation of the methods provided
57 there. This package overrides the implementation of these methods, not
58 the semantics.
59
60 This module is still in beta.  Cygwin-knowledgeable folks are invited
61 to offer patches and suggestions.