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