1 package File::Spec::Mac;
7 use vars qw(@ISA $VERSION $Is_Mac);
11 @ISA = qw(File::Spec::Unix);
12 $Is_Mac = $^O eq 'MacOS';
14 Exporter::import('File::Spec', '$Verbose');
19 File::Spec::Mac - File::Spec for MacOS
23 C<require File::Spec::Mac;>
27 Methods for manipulating file specifications.
35 On MacOS, there's nothing to be done. Returns what it's given.
46 Concatenate two or more directory names to form a complete path ending with
47 a directory. Put a trailing : on the end of the complete path if there
48 isn't one, because that's what's done in MacPerl's environment.
50 The fundamental requirement of this routine is that
52 File::Spec->catdir(split(":",$path)) eq $path
54 But because of the nature of Macintosh paths, some additional
55 possibilities are allowed to make using this routine give resonable results
56 for some common situations. Here are the rules that are used. Each
57 argument has its trailing ":" removed. Each argument, except the first,
58 has its leading ":" removed. They are then joined together by a ":".
62 File::Spec->catdir("a","b") = "a:b:"
63 File::Spec->catdir("a:",":b") = "a:b:"
64 File::Spec->catdir("a:","b") = "a:b:"
65 File::Spec->catdir("a",":b") = "a:b"
66 File::Spec->catdir("a","","b") = "a::b"
70 To get a relative path (one beginning with :), begin the first argument with :
71 or put a "" as the first argument.
73 If you don't want to worry about these rules, never allow a ":" on the ends
74 of any of the arguments except at the beginning of the first.
76 Under MacPerl, there is an additional ambiguity. Does the user intend that
78 File::Spec->catfile("LWP","Protocol","http.pm")
80 be relative or absolute? There's no way of telling except by checking for the
81 existance of LWP: or :LWP, and even there he may mean a dismounted volume or
82 a relative path in a different directory (like in @INC). So those checks
83 aren't done here. This routine will treat this as absolute.
93 my $result = shift @args;
105 Concatenate one or more directory names and a filename to form a
106 complete path ending with a filename. Since this uses catdir, the
107 same caveats apply. Note that the leading : is removed from the filename,
110 File::Spec->catfile($ENV{HOME},"file");
114 File::Spec->catfile($ENV{HOME},":file");
116 give the same answer, as one might expect.
123 return $file unless @_;
124 my $dir = $self->catdir(@_);
131 Returns a string representing of the current directory.
141 Returns a string representing the root directory. Under MacPerl,
142 returns the name of the startup volume, since that's the closest in
143 concept, although other volumes aren't rooted there. On any other
144 platform returns '', since there's no common way to indicate "root
145 directory" across all Macs.
151 # There's no real root directory on MacOS. If you're using MacPerl,
152 # the name of the startup volume is returned, since that's the closest in
153 # concept. On other platforms, simply return '', because nothing better
158 my $system = Mac::Files::FindFolder(&Mac::Files::kOnSystemDisk,
159 &Mac::Files::kSystemFolderType);
160 $system =~ s/:.*$/:/;
169 Returns a string representing the parent directory.
177 =item file_name_is_absolute
179 Takes as argument a path and returns true, if it is an absolute path. In
180 the case where a name can be either relative or absolute (for example, a
181 folder named "HD" in the current working directory on a drive named "HD"),
182 relative wins. Use ":" in the appropriate place in the path if you want to
183 distinguish unambiguously.
187 sub file_name_is_absolute {
188 my($self,$file) = @_;
190 return ($file !~ m/^:/);
192 return (! -e ":$file");
198 Returns the null list for the MacPerl application, since the concept is
199 usually meaningless under MacOS. But if you're using the MacPerl tool under
200 MPW, it gives back $ENV{Commands} suitably split, as is done in
201 :lib:ExtUtils:MM_Mac.pm.
207 # The concept is meaningless under the MacPerl application.
208 # Under MPW, it has a meaning.
212 if(exists $ENV{Commands}) {
213 @path = split /,/,$ENV{Commands};