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