Commit | Line | Data |
---|---|---|
270d1e39 | 1 | package File::Spec::Win32; |
2 | ||
cbc7acb0 | 3 | use strict; |
4 | use vars qw(@ISA); | |
5 | require File::Spec::Unix; | |
6 | @ISA = qw(File::Spec::Unix); | |
7 | ||
270d1e39 | 8 | =head1 NAME |
9 | ||
10 | File::Spec::Win32 - methods for Win32 file specs | |
11 | ||
12 | =head1 SYNOPSIS | |
13 | ||
cbc7acb0 | 14 | require File::Spec::Win32; # Done internally by File::Spec if needed |
270d1e39 | 15 | |
16 | =head1 DESCRIPTION | |
17 | ||
18 | See File::Spec::Unix for a documentation of the methods provided | |
19 | there. This package overrides the implementation of these methods, not | |
20 | the semantics. | |
21 | ||
22 | =over | |
23 | ||
cbc7acb0 | 24 | =item devnull |
270d1e39 | 25 | |
cbc7acb0 | 26 | Returns a string representation of the null device. |
270d1e39 | 27 | |
cbc7acb0 | 28 | =cut |
270d1e39 | 29 | |
cbc7acb0 | 30 | sub devnull { |
31 | return "nul"; | |
32 | } | |
270d1e39 | 33 | |
cbc7acb0 | 34 | =item tmpdir |
270d1e39 | 35 | |
cbc7acb0 | 36 | Returns a string representation of the first existing directory |
37 | from the following list: | |
270d1e39 | 38 | |
cbc7acb0 | 39 | $ENV{TMPDIR} |
40 | $ENV{TEMP} | |
41 | $ENV{TMP} | |
42 | /tmp | |
43 | / | |
44 | ||
45 | =cut | |
270d1e39 | 46 | |
cbc7acb0 | 47 | my $tmpdir; |
48 | sub tmpdir { | |
49 | return $tmpdir if defined $tmpdir; | |
270d1e39 | 50 | my $self = shift; |
cbc7acb0 | 51 | foreach (@ENV{qw(TMPDIR TEMP TMP)}, qw(/tmp /)) { |
52 | next unless defined && -d; | |
53 | $tmpdir = $_; | |
54 | last; | |
270d1e39 | 55 | } |
cbc7acb0 | 56 | $tmpdir = '' unless defined $tmpdir; |
57 | $tmpdir = $self->canonpath($tmpdir); | |
58 | return $tmpdir; | |
59 | } | |
60 | ||
61 | sub file_name_is_absolute { | |
62 | my ($self,$file) = @_; | |
63 | return scalar($file =~ m{^([a-z]:)?[\\/]}i); | |
270d1e39 | 64 | } |
65 | ||
66 | =item catfile | |
67 | ||
68 | Concatenate one or more directory names and a filename to form a | |
69 | complete path ending with a filename | |
70 | ||
71 | =cut | |
72 | ||
73 | sub catfile { | |
cbc7acb0 | 74 | my $self = shift; |
270d1e39 | 75 | my $file = pop @_; |
76 | return $file unless @_; | |
77 | my $dir = $self->catdir(@_); | |
cbc7acb0 | 78 | $dir .= "\\" unless substr($dir,-1) eq "\\"; |
270d1e39 | 79 | return $dir.$file; |
80 | } | |
81 | ||
82 | sub path { | |
83 | local $^W = 1; | |
270d1e39 | 84 | my $path = $ENV{'PATH'} || $ENV{'Path'} || $ENV{'path'}; |
85 | my @path = split(';',$path); | |
cbc7acb0 | 86 | foreach (@path) { $_ = '.' if $_ eq '' } |
87 | return @path; | |
270d1e39 | 88 | } |
89 | ||
90 | =item canonpath | |
91 | ||
92 | No physical check on the filesystem, but a logical cleanup of a | |
93 | path. On UNIX eliminated successive slashes and successive "/.". | |
94 | ||
95 | =cut | |
96 | ||
97 | sub canonpath { | |
cbc7acb0 | 98 | my ($self,$path) = @_; |
270d1e39 | 99 | $path =~ s/^([a-z]:)/\u$1/; |
100 | $path =~ s|/|\\|g; | |
cbc7acb0 | 101 | $path =~ s|([^\\])\\+|\1\\|g; # xx////xx -> xx/xx |
102 | $path =~ s|(\\\.)+\\|\\|g; # xx/././xx -> xx/xx | |
270d1e39 | 103 | $path =~ s|^(\.\\)+|| unless $path eq ".\\"; # ./xx -> xx |
cbc7acb0 | 104 | $path =~ s|\\$|| |
105 | unless $path =~ m#^([A-Z]:)?\\#; # xx/ -> xx | |
106 | return $path; | |
270d1e39 | 107 | } |
108 | ||
270d1e39 | 109 | =back |
110 | ||
cbc7acb0 | 111 | =head1 SEE ALSO |
112 | ||
113 | L<File::Spec> | |
270d1e39 | 114 | |
cbc7acb0 | 115 | =cut |
116 | ||
117 | 1; |