source: for-distributions/trunk/bin/windows/perl/lib/File/Spec.pm@ 14489

Last change on this file since 14489 was 14489, checked in by oranfry, 17 years ago

upgrading to perl 5.8

File size: 9.9 KB
Line 
1package File::Spec;
2
3use strict;
4use vars qw(@ISA $VERSION);
5
6$VERSION = '3.12';
7$VERSION = eval $VERSION;
8
9my %module = (MacOS => 'Mac',
10 MSWin32 => 'Win32',
11 os2 => 'OS2',
12 VMS => 'VMS',
13 epoc => 'Epoc',
14 NetWare => 'Win32', # Yes, File::Spec::Win32 works on NetWare.
15 symbian => 'Win32', # Yes, File::Spec::Win32 works on symbian.
16 dos => 'OS2', # Yes, File::Spec::OS2 works on DJGPP.
17 cygwin => 'Cygwin');
18
19
20my $module = $module{$^O} || 'Unix';
21
22require "File/Spec/$module.pm";
23@ISA = ("File::Spec::$module");
24
251;
26
27__END__
28
29=head1 NAME
30
31File::Spec - portably perform operations on file names
32
33=head1 SYNOPSIS
34
35 use File::Spec;
36
37 $x=File::Spec->catfile('a', 'b', 'c');
38
39which returns 'a/b/c' under Unix. Or:
40
41 use File::Spec::Functions;
42
43 $x = catfile('a', 'b', 'c');
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
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.
68
69Since File::Spec is object oriented, subroutines should not be called directly,
70as in:
71
72 File::Spec::catfile('a','b');
73
74but rather as class methods:
75
76 File::Spec->catfile('a','b');
77
78For simple uses, L<File::Spec::Functions> provides convenient functional
79forms of these methods.
80
81=head1 METHODS
82
83=over 2
84
85=item canonpath
86
87No physical check on the filesystem, but a logical cleanup of a
88path.
89
90 $cpath = File::Spec->canonpath( $path ) ;
91
92Note that this does *not* collapse F<x/../y> sections into F<y>. This
93is by design. If F</foo> on your system is a symlink to F</bar/baz>,
94then F</foo/../quux> is actually F</bar/quux>, not F</quux> as a naive
95F<../>-removal would give you. If you want to do this kind of
96processing, you probably want C<Cwd>'s C<realpath()> function to
97actually traverse the filesystem cleaning up paths like this.
98
99=item catdir
100
101Concatenate two or more directory names to form a complete path ending
102with a directory. But remove the trailing slash from the resulting
103string, because it doesn't look good, isn't necessary and confuses
104OS/2. Of course, if this is the root directory, don't cut off the
105trailing slash :-)
106
107 $path = File::Spec->catdir( @directories );
108
109=item catfile
110
111Concatenate one or more directory names and a filename to form a
112complete path ending with a filename
113
114 $path = File::Spec->catfile( @directories, $filename );
115
116=item curdir
117
118Returns a string representation of the current directory.
119
120 $curdir = File::Spec->curdir();
121
122=item devnull
123
124Returns a string representation of the null device.
125
126 $devnull = File::Spec->devnull();
127
128=item rootdir
129
130Returns a string representation of the root directory.
131
132 $rootdir = File::Spec->rootdir();
133
134=item tmpdir
135
136Returns a string representation of the first writable directory from a
137list of possible temporary directories. Returns the current directory
138if no writable temporary directories are found. The list of directories
139checked depends on the platform; e.g. File::Spec::Unix checks C<$ENV{TMPDIR}>
140(unless taint is on) and F</tmp>.
141
142 $tmpdir = File::Spec->tmpdir();
143
144=item updir
145
146Returns a string representation of the parent directory.
147
148 $updir = File::Spec->updir();
149
150=item no_upwards
151
152Given a list of file names, strip out those that refer to a parent
153directory. (Does not strip symlinks, only '.', '..', and equivalents.)
154
155 @paths = File::Spec->no_upwards( @paths );
156
157=item case_tolerant
158
159Returns a true or false value indicating, respectively, that alphabetic
160case is not or is significant when comparing file specifications.
161
162 $is_case_tolerant = File::Spec->case_tolerant();
163
164=item file_name_is_absolute
165
166Takes as its argument a path, and returns true if it is an absolute path.
167
168 $is_absolute = File::Spec->file_name_is_absolute( $path );
169
170This does not consult the local filesystem on Unix, Win32, OS/2, or
171Mac OS (Classic). It does consult the working environment for VMS
172(see L<File::Spec::VMS/file_name_is_absolute>).
173
174=item path
175
176Takes no argument. Returns the environment variable C<PATH> (or the local
177platform's equivalent) as a list.
178
179 @PATH = File::Spec->path();
180
181=item join
182
183join is the same as catfile.
184
185=item splitpath
186
187Splits a path in to volume, directory, and filename portions. On systems
188with no concept of volume, returns '' for volume.
189
190 ($volume,$directories,$file) = File::Spec->splitpath( $path );
191 ($volume,$directories,$file) = File::Spec->splitpath( $path, $no_file );
192
193For systems with no syntax differentiating filenames from directories,
194assumes that the last file is a path unless C<$no_file> is true or a
195trailing separator or F</.> or F</..> is present. On Unix, this means that C<$no_file>
196true makes this return ( '', $path, '' ).
197
198The directory portion may or may not be returned with a trailing '/'.
199
200The results can be passed to L</catpath()> to get back a path equivalent to
201(usually identical to) the original path.
202
203=item splitdir
204
205The opposite of L</catdir()>.
206
207 @dirs = File::Spec->splitdir( $directories );
208
209C<$directories> must be only the directory portion of the path on systems
210that have the concept of a volume or that have path syntax that differentiates
211files from directories.
212
213Unlike just splitting the directories on the separator, empty
214directory names (C<''>) can be returned, because these are significant
215on some OSes.
216
217=item catpath()
218
219Takes volume, directory and file portions and returns an entire path. Under
220Unix, C<$volume> is ignored, and directory and file are concatenated. A '/' is
221inserted if need be. On other OSes, C<$volume> is significant.
222
223 $full_path = File::Spec->catpath( $volume, $directory, $file );
224
225=item abs2rel
226
227Takes a destination path and an optional base path returns a relative path
228from the base path to the destination path:
229
230 $rel_path = File::Spec->abs2rel( $path ) ;
231 $rel_path = File::Spec->abs2rel( $path, $base ) ;
232
233If C<$base> is not present or '', then L<cwd()|Cwd> is used. If C<$base> is
234relative, then it is converted to absolute form using
235L</rel2abs()>. This means that it is taken to be relative to
236L<cwd()|Cwd>.
237
238On systems with the concept of volume, if C<$path> and C<$base> appear to be
239on two different volumes, we will not attempt to resolve the two
240paths, and we will instead simply return C<$path>. Note that previous
241versions of this module ignored the volume of C<$base>, which resulted in
242garbage results part of the time.
243
244On systems that have a grammar that indicates filenames, this ignores the
245C<$base> filename as well. Otherwise all path components are assumed to be
246directories.
247
248If C<$path> is relative, it is converted to absolute form using L</rel2abs()>.
249This means that it is taken to be relative to L<cwd()|Cwd>.
250
251No checks against the filesystem are made. On VMS, there is
252interaction with the working environment, as logicals and
253macros are expanded.
254
255Based on code written by Shigio Yamaguchi.
256
257=item rel2abs()
258
259Converts a relative path to an absolute path.
260
261 $abs_path = File::Spec->rel2abs( $path ) ;
262 $abs_path = File::Spec->rel2abs( $path, $base ) ;
263
264If C<$base> is not present or '', then L<cwd()|Cwd> is used. If C<$base> is relative,
265then it is converted to absolute form using L</rel2abs()>. This means that it
266is taken to be relative to L<cwd()|Cwd>.
267
268On systems with the concept of volume, if C<$path> and C<$base> appear to be
269on two different volumes, we will not attempt to resolve the two
270paths, and we will instead simply return C<$path>. Note that previous
271versions of this module ignored the volume of C<$base>, which resulted in
272garbage results part of the time.
273
274On systems that have a grammar that indicates filenames, this ignores the
275C<$base> filename as well. Otherwise all path components are assumed to be
276directories.
277
278If C<$path> is absolute, it is cleaned up and returned using L</canonpath()>.
279
280No checks against the filesystem are made. On VMS, there is
281interaction with the working environment, as logicals and
282macros are expanded.
283
284Based on code written by Shigio Yamaguchi.
285
286=back
287
288For further information, please see L<File::Spec::Unix>,
289L<File::Spec::Mac>, L<File::Spec::OS2>, L<File::Spec::Win32>, or
290L<File::Spec::VMS>.
291
292=head1 SEE ALSO
293
294L<File::Spec::Unix>, L<File::Spec::Mac>, L<File::Spec::OS2>,
295L<File::Spec::Win32>, L<File::Spec::VMS>, L<File::Spec::Functions>,
296L<ExtUtils::MakeMaker>
297
298=head1 AUTHOR
299
300Currently maintained by Ken Williams C<< <[email protected]> >>.
301
302The vast majority of the code was written by
303Kenneth Albanowski C<< <[email protected]> >>,
304Andy Dougherty C<< <[email protected]> >>,
305Andreas KE<ouml>nig C<< <[email protected]> >>,
306Tim Bunce C<< <[email protected]> >>.
307VMS support by Charles Bailey C<< <[email protected]> >>.
308OS/2 support by Ilya Zakharevich C<< <[email protected]> >>.
309Mac support by Paul Schinder C<< <[email protected]> >>, and
310Thomas Wegner C<< <[email protected]> >>.
311abs2rel() and rel2abs() written by Shigio Yamaguchi C<< <[email protected]> >>,
312modified by Barrie Slaymaker C<< <[email protected]> >>.
313splitpath(), splitdir(), catpath() and catdir() by Barrie Slaymaker.
314
315=head1 COPYRIGHT
316
317Copyright (c) 2004 by the Perl 5 Porters. All rights reserved.
318
319This program is free software; you can redistribute it and/or modify
320it under the same terms as Perl itself.
321
322=cut
Note: See TracBrowser for help on using the repository browser.