1 package File::Spec::Mac;
5 require File::Spec::Unix;
6 @ISA = qw(File::Spec::Unix);
10 File::Spec::Mac - File::Spec for MacOS
14 require File::Spec::Mac; # Done internally by File::Spec if needed
18 Methods for manipulating file specifications.
26 On MacOS, there's nothing to be done. Returns what it's given.
31 my ($self,$path) = @_;
37 Concatenate two or more directory names to form a complete path ending with
38 a directory. Put a trailing : on the end of the complete path if there
39 isn't one, because that's what's done in MacPerl's environment.
41 The fundamental requirement of this routine is that
43 File::Spec->catdir(split(":",$path)) eq $path
45 But because of the nature of Macintosh paths, some additional
46 possibilities are allowed to make using this routine give reasonable results
47 for some common situations. Here are the rules that are used. Each
48 argument has its trailing ":" removed. Each argument, except the first,
49 has its leading ":" removed. They are then joined together by a ":".
53 File::Spec->catdir("a","b") = "a:b:"
54 File::Spec->catdir("a:",":b") = "a:b:"
55 File::Spec->catdir("a:","b") = "a:b:"
56 File::Spec->catdir("a",":b") = "a:b"
57 File::Spec->catdir("a","","b") = "a::b"
61 To get a relative path (one beginning with :), begin the first argument with :
62 or put a "" as the first argument.
64 If you don't want to worry about these rules, never allow a ":" on the ends
65 of any of the arguments except at the beginning of the first.
67 Under MacPerl, there is an additional ambiguity. Does the user intend that
69 File::Spec->catfile("LWP","Protocol","http.pm")
71 be relative or absolute? There's no way of telling except by checking for the
72 existence of LWP: or :LWP, and even there he may mean a dismounted volume or
73 a relative path in a different directory (like in @INC). So those checks
74 aren't done here. This routine will treat this as absolute.
81 my $result = shift @args;
93 Concatenate one or more directory names and a filename to form a
94 complete path ending with a filename. Since this uses catdir, the
95 same caveats apply. Note that the leading : is removed from the filename,
98 File::Spec->catfile($ENV{HOME},"file");
102 File::Spec->catfile($ENV{HOME},":file");
104 give the same answer, as one might expect.
111 return $file unless @_;
112 my $dir = $self->catdir(@_);
119 Returns a string representing the current directory.
129 Returns a string representing the null device.
139 Returns a string representing the root directory. Under MacPerl,
140 returns the name of the startup volume, since that's the closest in
141 concept, although other volumes aren't rooted there.
147 # There's no real root directory on MacOS. The name of the startup
148 # volume is returned, since that's the closest in concept.
151 my $system = Mac::Files::FindFolder(&Mac::Files::kOnSystemDisk,
152 &Mac::Files::kSystemFolderType);
153 $system =~ s/:.*$/:/;
159 Returns a string representation of the first existing directory
160 from the following list or '' if none exist:
168 return $tmpdir if defined $tmpdir;
169 $tmpdir = $ENV{TMPDIR} if -d $ENV{TMPDIR};
170 $tmpdir = '' unless defined $tmpdir;
176 Returns a string representing the parent directory.
184 =item file_name_is_absolute
186 Takes as argument a path and returns true, if it is an absolute path. In
187 the case where a name can be either relative or absolute (for example, a
188 folder named "HD" in the current working directory on a drive named "HD"),
189 relative wins. Use ":" in the appropriate place in the path if you want to
190 distinguish unambiguously.
194 sub file_name_is_absolute {
195 my ($self,$file) = @_;
197 return ($file !~ m/^:/);
199 return (! -e ":$file");
205 Returns the null list for the MacPerl application, since the concept is
206 usually meaningless under MacOS. But if you're using the MacPerl tool under
207 MPW, it gives back $ENV{Commands} suitably split, as is done in
208 :lib:ExtUtils:MM_Mac.pm.
214 # The concept is meaningless under the MacPerl application.
215 # Under MPW, it has a meaning.
217 return unless exists $ENV{Commands};
218 return split(/,/, $ENV{Commands});