File::Spec & NetWare
[p5sagit/p5-mst-13.2.git] / lib / File / Spec.pm
CommitLineData
270d1e39 1package File::Spec;
2
270d1e39 3use strict;
f168a5e7 4our(@ISA, $VERSION);
270d1e39 5
88d01e8d 6$VERSION = 0.83 ;
270d1e39 7
cbc7acb0 8my %module = (MacOS => 'Mac',
9 MSWin32 => 'Win32',
10 os2 => 'OS2',
fa6a1c44 11 VMS => 'VMS',
ecf68df6 12 epoc => 'Epoc',
ffa8448b 13 NetWare => 'Win32', # Yes, File::Spec::Win32 works on NetWare.
ecf68df6 14 cygwin => 'Cygwin');
15
cbc7acb0 16
17my $module = $module{$^O} || 'Unix';
ecf68df6 18
cbc7acb0 19require "File/Spec/$module.pm";
20@ISA = ("File::Spec::$module");
270d1e39 21
221;
ae1c33a1 23
270d1e39 24__END__
25
26=head1 NAME
27
28File::Spec - portably perform operations on file names
29
30=head1 SYNOPSIS
31
5c609535 32 use File::Spec;
270d1e39 33
5c609535 34 $x=File::Spec->catfile('a', 'b', 'c');
270d1e39 35
5c609535 36which returns 'a/b/c' under Unix. Or:
37
38 use File::Spec::Functions;
39
40 $x = catfile('a', 'b', 'c');
270d1e39 41
42=head1 DESCRIPTION
43
44This module is designed to support operations commonly performed on file
45specifications (usually called "file names", but not to be confused with the
46contents of a file, or Perl's file handles), such as concatenating several
47directory and file names into a single path, or determining whether a path
48is rooted. It is based on code directly taken from MakeMaker 5.17, code
49written by Andreas KE<ouml>nig, Andy Dougherty, Charles Bailey, Ilya
50Zakharevich, Paul Schinder, and others.
51
52Since these functions are different for most operating systems, each set of
53OS specific routines is available in a separate module, including:
54
55 File::Spec::Unix
56 File::Spec::Mac
57 File::Spec::OS2
58 File::Spec::Win32
59 File::Spec::VMS
60
61The module appropriate for the current OS is automatically loaded by
5c609535 62File::Spec. Since some modules (like VMS) make use of facilities available
63only under that OS, it may not be possible to load all modules under all
64operating systems.
270d1e39 65
2586ba89 66Since File::Spec is object oriented, subroutines should not be called directly,
270d1e39 67as in:
68
69 File::Spec::catfile('a','b');
5c609535 70
270d1e39 71but rather as class methods:
72
73 File::Spec->catfile('a','b');
74
5c609535 75For simple uses, L<File::Spec::Functions> provides convenient functional
76forms of these methods.
77
ae1c33a1 78=head1 METHODS
79
80=over 2
81
5813de03 82=item canonpath
ae1c33a1 83
84No physical check on the filesystem, but a logical cleanup of a
85path.
86
87 $cpath = File::Spec->canonpath( $path ) ;
88
5813de03 89=item catdir
ae1c33a1 90
91Concatenate two or more directory names to form a complete path ending
92with a directory. But remove the trailing slash from the resulting
93string, because it doesn't look good, isn't necessary and confuses
94OS2. Of course, if this is the root directory, don't cut off the
95trailing slash :-)
96
97 $path = File::Spec->catdir( @directories );
98
99=item catfile
100
101Concatenate one or more directory names and a filename to form a
102complete path ending with a filename
103
104 $path = File::Spec->catfile( @directories, $filename );
105
106=item curdir
107
108Returns a string representation of the current directory.
109
110 $curdir = File::Spec->curdir();
111
112=item devnull
113
114Returns a string representation of the null device.
115
116 $devnull = File::Spec->devnull();
117
118=item rootdir
119
120Returns a string representation of the root directory.
121
122 $rootdir = File::Spec->rootdir();
123
124=item tmpdir
125
126Returns a string representation of the first writable directory from a
127list of possible temporary directories. Returns "" if no writable
128temporary directories are found. The list of directories checked
129depends on the platform; e.g. File::Spec::Unix checks $ENV{TMPDIR} and
130/tmp.
131
132 $tmpdir = File::Spec->tmpdir();
133
134=item updir
135
136Returns a string representation of the parent directory.
137
138 $updir = File::Spec->updir();
139
140=item no_upwards
141
142Given a list of file names, strip out those that refer to a parent
143directory. (Does not strip symlinks, only '.', '..', and equivalents.)
144
145 @paths = File::Spec->no_upwards( @paths );
146
147=item case_tolerant
148
149Returns a true or false value indicating, respectively, that alphabetic
150is not or is significant when comparing file specifications.
151
152 $is_case_tolerant = File::Spec->case_tolerant();
153
154=item file_name_is_absolute
155
156Takes as argument a path and returns true if it is an absolute path.
157
158 $is_absolute = File::Spec->file_name_is_absolute( $path );
159
2586ba89 160This does not consult the local filesystem on Unix, Win32, OS/2, or
161Mac OS (Classic). It does consult the working environment for VMS
162(see L<File::Spec::VMS/file_name_is_absolute>).
ae1c33a1 163
164=item path
165
166Takes no argument, returns the environment variable PATH as an array.
167
168 @PATH = File::Spec->path();
169
170=item join
171
172join is the same as catfile.
173
174=item splitpath
175
176Splits a path in to volume, directory, and filename portions. On systems
177with no concept of volume, returns undef for volume.
178
179 ($volume,$directories,$file) = File::Spec->splitpath( $path );
180 ($volume,$directories,$file) = File::Spec->splitpath( $path, $no_file );
181
182For systems with no syntax differentiating filenames from directories,
183assumes that the last file is a path unless $no_file is true or a
184trailing separator or /. or /.. is present. On Unix this means that $no_file
185true makes this return ( '', $path, '' ).
186
187The directory portion may or may not be returned with a trailing '/'.
188
189The results can be passed to L</catpath()> to get back a path equivalent to
190(usually identical to) the original path.
191
192=item splitdir
193
194The opposite of L</catdir()>.
195
196 @dirs = File::Spec->splitdir( $directories );
197
198$directories must be only the directory portion of the path on systems
199that have the concept of a volume or that have path syntax that differentiates
200files from directories.
201
202Unlike just splitting the directories on the separator, empty
203directory names (C<''>) can be returned, because these are significant
2586ba89 204on some OSs.
ae1c33a1 205
59605c55 206=item catpath()
ae1c33a1 207
208Takes volume, directory and file portions and returns an entire path. Under
209Unix, $volume is ignored, and directory and file are catenated. A '/' is
210inserted if need be. On other OSs, $volume is significant.
211
212 $full_path = File::Spec->catpath( $volume, $directory, $file );
213
214=item abs2rel
215
216Takes a destination path and an optional base path returns a relative path
217from the base path to the destination path:
218
219 $rel_path = File::Spec->abs2rel( $path ) ;
220 $rel_path = File::Spec->abs2rel( $path, $base ) ;
221
59605c55 222If $base is not present or '', then L<cwd()|Cwd> is used. If $base is relative,
ae1c33a1 223then it is converted to absolute form using L</rel2abs()>. This means that it
59605c55 224is taken to be relative to L<cwd()|Cwd>.
ae1c33a1 225
226On systems with the concept of a volume, this assumes that both paths
227are on the $destination volume, and ignores the $base volume.
228
229On systems that have a grammar that indicates filenames, this ignores the
230$base filename as well. Otherwise all path components are assumed to be
231directories.
232
233If $path is relative, it is converted to absolute form using L</rel2abs()>.
59605c55 234This means that it is taken to be relative to L<cwd()|Cwd>.
ae1c33a1 235
2586ba89 236No checks against the filesystem are made. On VMS, there is
ae1c33a1 237interaction with the working environment, as logicals and
238macros are expanded.
239
240Based on code written by Shigio Yamaguchi.
241
59605c55 242=item rel2abs()
ae1c33a1 243
244Converts a relative path to an absolute path.
245
246 $abs_path = File::Spec->rel2abs( $path ) ;
247 $abs_path = File::Spec->rel2abs( $path, $base ) ;
248
59605c55 249If $base is not present or '', then L<cwd()|Cwd> is used. If $base is relative,
ae1c33a1 250then it is converted to absolute form using L</rel2abs()>. This means that it
59605c55 251is taken to be relative to L<cwd()|Cwd>.
ae1c33a1 252
253On systems with the concept of a volume, this assumes that both paths
254are on the $base volume, and ignores the $path volume.
255
256On systems that have a grammar that indicates filenames, this ignores the
257$base filename as well. Otherwise all path components are assumed to be
258directories.
259
260If $path is absolute, it is cleaned up and returned using L</canonpath()>.
261
2586ba89 262No checks against the filesystem are made. On VMS, there is
ae1c33a1 263interaction with the working environment, as logicals and
264macros are expanded.
265
266Based on code written by Shigio Yamaguchi.
267
268=back
269
270For further information, please see L<File::Spec::Unix>,
271L<File::Spec::Mac>, L<File::Spec::OS2>, L<File::Spec::Win32>, or
272L<File::Spec::VMS>.
270d1e39 273
274=head1 SEE ALSO
275
ae1c33a1 276L<File::Spec::Unix>, L<File::Spec::Mac>, L<File::Spec::OS2>,
277L<File::Spec::Win32>, L<File::Spec::VMS>, L<File::Spec::Functions>,
278L<ExtUtils::MakeMaker>
270d1e39 279
280=head1 AUTHORS
281
ae1c33a1 282Kenneth Albanowski <kjahds@kjahds.com>, Andy Dougherty
283<doughera@lafcol.lafayette.edu>, Andreas KE<ouml>nig
2586ba89 284<A.Koenig@franz.ww.TU-Berlin.DE>, Tim Bunce <Tim.Bunce@ig.co.uk.
285VMS support by Charles Bailey <bailey@newman.upenn.edu>.
286OS/2 support by Ilya Zakharevich <ilya@math.ohio-state.edu>.
287Mac support by Paul Schinder <schinder@pobox.com>, and Thomas Wegner
288<wegner_thomas@yahoo.com>. abs2rel() and rel2abs() written by Shigio
289Yamaguchi <shigio@tamacom.com>, modified by Barrie Slaymaker
290<barries@slaysys.com>. splitpath(), splitdir(), catpath() and
291catdir() by Barrie Slaymaker.