1File::Spec::Mac(3)    User Contributed Perl Documentation   File::Spec::Mac(3)
2
3
4

NAME

6       File::Spec::Mac - File::Spec for Mac OS (Classic)
7

SYNOPSIS

9        require File::Spec::Mac; # Done internally by File::Spec if needed
10

DESCRIPTION

12       Methods for manipulating file specifications.
13

METHODS

15       canonpath
16         On Mac OS, there's nothing to be done. Returns what it's given.
17
18       catdir()
19         Concatenate two or more directory names to form a path separated by
20         colons (":") ending with a directory. Resulting paths are relative by
21         default, but can be forced to be absolute (but avoid this, see
22         below). Automatically puts a trailing ":" on the end of the complete
23         path, because that's what's done in MacPerl's environment and helps
24         to distinguish a file path from a directory path.
25
26         IMPORTANT NOTE: Beginning with version 1.3 of this module, the
27         resulting path is relative by default and not absolute. This decision
28         was made due to portability reasons. Since "File::Spec->catdir()"
29         returns relative paths on all other operating systems, it will now
30         also follow this convention on Mac OS. Note that this may break some
31         existing scripts.
32
33         The intended purpose of this routine is to concatenate directory
34         names.  But because of the nature of Macintosh paths, some additional
35         possibilities are allowed to make using this routine give reasonable
36         results for some common situations. In other words, you are also
37         allowed to concatenate paths instead of directory names (strictly
38         speaking, a string like ":a" is a path, but not a name, since it
39         contains a punctuation character ":").
40
41         So, beside calls like
42
43             catdir("a") = ":a:"
44             catdir("a","b") = ":a:b:"
45             catdir() = ""                    (special case)
46
47         calls like the following
48
49             catdir(":a:") = ":a:"
50             catdir(":a","b") = ":a:b:"
51             catdir(":a:","b") = ":a:b:"
52             catdir(":a:",":b:") = ":a:b:"
53             catdir(":") = ":"
54
55         are allowed.
56
57         Here are the rules that are used in catdir(); note that we try to be
58         as compatible as possible to Unix:
59
60         1.
61           The resulting path is relative by default, i.e. the resulting path
62           will have a leading colon.
63
64         2.
65           A trailing colon is added automatically to the resulting path, to
66           denote a directory.
67
68         3.
69           Generally, each argument has one leading ":" and one trailing ":"
70           removed (if any). They are then joined together by a ":". Special
71           treatment applies for arguments denoting updir paths like "::lib:",
72           see (4), or arguments consisting solely of colons ("colon paths"),
73           see (5).
74
75         4.
76           When an updir path like ":::lib::" is passed as argument, the
77           number of directories to climb up is handled correctly, not
78           removing leading or trailing colons when necessary. E.g.
79
80               catdir(":::a","::b","c")    = ":::a::b:c:"
81               catdir(":::a::","::b","c")  = ":::a:::b:c:"
82
83         5.
84           Adding a colon ":" or empty string "" to a path at any position
85           doesn't alter the path, i.e. these arguments are ignored. (When a
86           "" is passed as the first argument, it has a special meaning, see
87           (6)). This way, a colon ":" is handled like a "." (curdir) on Unix,
88           while an empty string "" is generally ignored (see "canonpath()" in
89           File::Spec::Unix ). Likewise, a "::" is handled like a ".."
90           (updir), and a ":::" is handled like a "../.." etc.  E.g.
91
92               catdir("a",":",":","b")   = ":a:b:"
93               catdir("a",":","::",":b") = ":a::b:"
94
95         6.
96           If the first argument is an empty string "" or is a volume name,
97           i.e. matches the pattern /^[^:]+:/, the resulting path is absolute.
98
99         7.
100           Passing an empty string "" as the first argument to catdir() is
101           like passing"File::Spec->rootdir()" as the first argument, i.e.
102
103               catdir("","a","b")          is the same as
104
105               catdir(rootdir(),"a","b").
106
107           This is true on Unix, where "catdir("","a","b")" yields "/a/b" and
108           rootdir() is "/". Note that rootdir() on Mac OS is the startup
109           volume, which is the closest in concept to Unix' "/". This should
110           help to run existing scripts originally written for Unix.
111
112         8.
113           For absolute paths, some cleanup is done, to ensure that the volume
114           name isn't immediately followed by updirs. This is invalid, because
115           this would go beyond "root". Generally, these cases are handled
116           like their Unix counterparts:
117
118            Unix:
119               Unix->catdir("","")                 =  "/"
120               Unix->catdir("",".")                =  "/"
121               Unix->catdir("","..")               =  "/"        # can't go
122                                                                 # beyond root
123               Unix->catdir("",".","..","..","a")  =  "/a"
124            Mac:
125               Mac->catdir("","")                  =  rootdir()  # (e.g. "HD:")
126               Mac->catdir("",":")                 =  rootdir()
127               Mac->catdir("","::")                =  rootdir()  # can't go
128                                                                 # beyond root
129               Mac->catdir("",":","::","::","a")   =  rootdir() . "a:"
130                                                               # (e.g. "HD:a:")
131
132           However, this approach is limited to the first arguments following
133           "root" (again, see "canonpath()" in File::Spec::Unix. If there are
134           more arguments that move up the directory tree, an invalid path
135           going beyond root can be created.
136
137         As you've seen, you can force catdir() to create an absolute path by
138         passing either an empty string or a path that begins with a volume
139         name as the first argument. However, you are strongly encouraged not
140         to do so, since this is done only for backward compatibility. Newer
141         versions of File::Spec come with a method called catpath() (see
142         below), that is designed to offer a portable solution for the
143         creation of absolute paths.  It takes volume, directory and file
144         portions and returns an entire path. While catdir() is still suitable
145         for the concatenation of directory names, you are encouraged to use
146         catpath() to concatenate volume names and directory paths. E.g.
147
148             $dir      = File::Spec->catdir("tmp","sources");
149             $abs_path = File::Spec->catpath("MacintoshHD:", $dir,"");
150
151         yields
152
153             "MacintoshHD:tmp:sources:" .
154
155       catfile
156         Concatenate one or more directory names and a filename to form a
157         complete path ending with a filename. Resulting paths are relative by
158         default, but can be forced to be absolute (but avoid this).
159
160         IMPORTANT NOTE: Beginning with version 1.3 of this module, the
161         resulting path is relative by default and not absolute. This decision
162         was made due to portability reasons. Since "File::Spec->catfile()"
163         returns relative paths on all other operating systems, it will now
164         also follow this convention on Mac OS.  Note that this may break some
165         existing scripts.
166
167         The last argument is always considered to be the file portion. Since
168         catfile() uses catdir() (see above) for the concatenation of the
169         directory portions (if any), the following with regard to relative
170         and absolute paths is true:
171
172             catfile("")     = ""
173             catfile("file") = "file"
174
175         but
176
177             catfile("","")        = rootdir()         # (e.g. "HD:")
178             catfile("","file")    = rootdir() . file  # (e.g. "HD:file")
179             catfile("HD:","file") = "HD:file"
180
181         This means that catdir() is called only when there are two or more
182         arguments, as one might expect.
183
184         Note that the leading ":" is removed from the filename, so that
185
186             catfile("a","b","file")  = ":a:b:file"    and
187
188             catfile("a","b",":file") = ":a:b:file"
189
190         give the same answer.
191
192         To concatenate volume names, directory paths and filenames, you are
193         encouraged to use catpath() (see below).
194
195       curdir
196         Returns a string representing the current directory. On Mac OS, this
197         is ":".
198
199       devnull
200         Returns a string representing the null device. On Mac OS, this is
201         "Dev:Null".
202
203       rootdir
204         Returns the empty string.  Mac OS has no real root directory.
205
206       tmpdir
207         Returns the contents of $ENV{TMPDIR}, if that directory exits or the
208         current working directory otherwise. Under MacPerl, $ENV{TMPDIR} will
209         contain a path like "MacintoshHD:Temporary Items:", which is a hidden
210         directory on your startup volume.
211
212       updir
213         Returns a string representing the parent directory. On Mac OS, this
214         is "::".
215
216       file_name_is_absolute
217         Takes as argument a path and returns true, if it is an absolute path.
218         If the path has a leading ":", it's a relative path. Otherwise, it's
219         an absolute path, unless the path doesn't contain any colons, i.e.
220         it's a name like "a". In this particular case, the path is considered
221         to be relative (i.e. it is considered to be a filename). Use ":" in
222         the appropriate place in the path if you want to distinguish
223         unambiguously. As a special case, the filename '' is always
224         considered to be absolute. Note that with version 1.2 of
225         File::Spec::Mac, this does no longer consult the local filesystem.
226
227         E.g.
228
229             File::Spec->file_name_is_absolute("a");         # false (relative)
230             File::Spec->file_name_is_absolute(":a:b:");     # false (relative)
231             File::Spec->file_name_is_absolute("MacintoshHD:");
232                                                             # true (absolute)
233             File::Spec->file_name_is_absolute("");          # true (absolute)
234
235       path
236         Returns the null list for the MacPerl application, since the concept
237         is usually meaningless under Mac OS. But if you're using the MacPerl
238         tool under MPW, it gives back $ENV{Commands} suitably split, as is
239         done in :lib:ExtUtils:MM_Mac.pm.
240
241       splitpath
242             ($volume,$directories,$file) = File::Spec->splitpath( $path );
243             ($volume,$directories,$file) = File::Spec->splitpath( $path,
244                                                                   $no_file );
245
246         Splits a path into volume, directory, and filename portions.
247
248         On Mac OS, assumes that the last part of the path is a filename
249         unless $no_file is true or a trailing separator ":" is present.
250
251         The volume portion is always returned with a trailing ":". The
252         directory portion is always returned with a leading (to denote a
253         relative path) and a trailing ":" (to denote a directory). The file
254         portion is always returned without a leading ":".  Empty portions are
255         returned as empty string ''.
256
257         The results can be passed to catpath() to get back a path equivalent
258         to (usually identical to) the original path.
259
260       splitdir
261         The opposite of catdir().
262
263             @dirs = File::Spec->splitdir( $directories );
264
265         $directories should be only the directory portion of the path on
266         systems that have the concept of a volume or that have path syntax
267         that differentiates files from directories. Consider using
268         splitpath() otherwise.
269
270         Unlike just splitting the directories on the separator, empty
271         directory names ("") can be returned. Since catdir() on Mac OS always
272         appends a trailing colon to distinguish a directory path from a file
273         path, a single trailing colon will be ignored, i.e. there's no empty
274         directory name after it.
275
276         Hence, on Mac OS, both
277
278             File::Spec->splitdir( ":a:b::c:" );    and
279             File::Spec->splitdir( ":a:b::c" );
280
281         yield:
282
283             ( "a", "b", "::", "c")
284
285         while
286
287             File::Spec->splitdir( ":a:b::c::" );
288
289         yields:
290
291             ( "a", "b", "::", "c", "::")
292
293       catpath
294             $path = File::Spec->catpath($volume,$directory,$file);
295
296         Takes volume, directory and file portions and returns an entire path.
297         On Mac OS, $volume, $directory and $file are concatenated.  A ':' is
298         inserted if need be. You may pass an empty string for each portion.
299         If all portions are empty, the empty string is returned. If $volume
300         is empty, the result will be a relative path, beginning with a ':'.
301         If $volume and $directory are empty, a leading ":" (if any) is
302         removed form $file and the remainder is returned. If $file is empty,
303         the resulting path will have a trailing ':'.
304
305       abs2rel
306         Takes a destination path and an optional base path and returns a
307         relative path from the base path to the destination path:
308
309             $rel_path = File::Spec->abs2rel( $path ) ;
310             $rel_path = File::Spec->abs2rel( $path, $base ) ;
311
312         Note that both paths are assumed to have a notation that
313         distinguishes a directory path (with trailing ':') from a file path
314         (without trailing ':').
315
316         If $base is not present or '', then the current working directory is
317         used.  If $base is relative, then it is converted to absolute form
318         using rel2abs().  This means that it is taken to be relative to the
319         current working directory.
320
321         If $path and $base appear to be on two different volumes, we will not
322         attempt to resolve the two paths, and we will instead simply return
323         $path.  Note that previous versions of this module ignored the volume
324         of $base, which resulted in garbage results part of the time.
325
326         If $base doesn't have a trailing colon, the last element of $base is
327         assumed to be a filename.  This filename is ignored.  Otherwise all
328         path components are assumed to be directories.
329
330         If $path is relative, it is converted to absolute form using
331         rel2abs().  This means that it is taken to be relative to the current
332         working directory.
333
334         Based on code written by Shigio Yamaguchi.
335
336       rel2abs
337         Converts a relative path to an absolute path:
338
339             $abs_path = File::Spec->rel2abs( $path ) ;
340             $abs_path = File::Spec->rel2abs( $path, $base ) ;
341
342         Note that both paths are assumed to have a notation that
343         distinguishes a directory path (with trailing ':') from a file path
344         (without trailing ':').
345
346         If $base is not present or '', then $base is set to the current
347         working directory. If $base is relative, then it is converted to
348         absolute form using rel2abs(). This means that it is taken to be
349         relative to the current working directory.
350
351         If $base doesn't have a trailing colon, the last element of $base is
352         assumed to be a filename.  This filename is ignored.  Otherwise all
353         path components are assumed to be directories.
354
355         If $path is already absolute, it is returned and $base is ignored.
356
357         Based on code written by Shigio Yamaguchi.
358

AUTHORS

360       See the authors list in File::Spec. Mac OS support by Paul Schinder
361       <schinder@pobox.com> and Thomas Wegner <wegner_thomas@yahoo.com>.
362
364       Copyright (c) 2004 by the Perl 5 Porters.  All rights reserved.
365
366       This program is free software; you can redistribute it and/or modify it
367       under the same terms as Perl itself.
368

SEE ALSO

370       See File::Spec and File::Spec::Unix.  This package overrides the
371       implementation of these methods, not the semantics.
372
373
374
375perl v5.36.0                      2023-01-20                File::Spec::Mac(3)
Impressum