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

NAME

6       File::HomeDir - Find your home and other directories, on any platform
7

SYNOPSIS

9         use File::HomeDir;
10
11         # Modern Interface (Current User)
12         $home    = File::HomeDir->my_home;
13         $desktop = File::HomeDir->my_desktop;
14         $docs    = File::HomeDir->my_documents;
15         $music   = File::HomeDir->my_music;
16         $pics    = File::HomeDir->my_pictures;
17         $videos  = File::HomeDir->my_videos;
18         $data    = File::HomeDir->my_data;
19
20         # Modern Interface (Other Users)
21         $home    = File::HomeDir->users_home('foo');
22         $desktop = File::HomeDir->users_desktop('foo');
23         $docs    = File::HomeDir->users_documents('foo');
24         $music   = File::HomeDir->users_music('foo');
25         $pics    = File::HomeDir->users_pictures('foo');
26         $video   = File::HomeDir->users_videos('foo');
27         $data    = File::HomeDir->users_data('foo');
28
29         # Legacy Interfaces
30         print "My dir is ", home(), " and root's is ", home('root'), "\n";
31         print "My dir is $~{''} and root's is $~{root}\n";
32         # These both print the same thing, something like:
33         #  "My dir is /home/user/mojo and root's is /"
34

DESCRIPTION

36       File::HomeDir is a module for dealing with issues relating to the loca‐
37       tion of directories that are "owned" by a user, primarily your user,
38       and to solve these issues consistently across a wide variety of plat‐
39       forms.
40
41       Thus, a single API is presented that can find your resources on any
42       platform.
43
44       This module provides two main interfaces.
45
46       The first is a modern File::Spec-style interface with a consistent OO
47       API and different implementation modules to support various platforms.
48       You are strongly recommended to use this interface.
49
50       The second interface is for legacy support of the original 0.07 inter‐
51       face that exported a "home()" function by default and tied the "%~"
52       variable.
53
54       It is generally not recommended that you use this interface, but due to
55       back-compatibility reasons they will remain supported until at least
56       2010.
57
58       After this date, the home() function will remain, but we will consider
59       deprecating the (namespace-polluting) "%~" tied hash, to be removed by
60       2015 (maintaining the general Perl convention of a 10 year support
61       period for legacy APIs potentially or actually in common use).
62
63       Platform Neutrality
64
65       In the Unix world, many different types of data can be mixed together
66       in your home directory (although on some Unix platforms this is no
67       longer the case, particularly for "desktop"-oriented platforms).
68
69       On some non-Unix platforms, seperate directories are allocated for dif‐
70       ferent types of data and have been for a long time.
71
72       When writing applications on top of File::HomeDir, you should thus
73       always try to use the most specific method you can. User documents
74       should be saved in "my_documents", data that supports an application
75       but isn't normally editing by the user directory should go into
76       "my_data".
77
78       On platforms that do not make any distinction, all these different
79       methods will harmlessly degrade to the main home directory, but on
80       platforms that care File::HomeDir will always try to Do The Right
81       Thing(tm).
82

METHODS

84       Two types of methods are provided. The "my_method" series of methods
85       for finding resources for the current user, and the "users_method"
86       (read as "user's method") series for finding resources for arbitrary
87       users.
88
89       This split is necesary, as on most platforms it is much easier to find
90       information about the current user compared to other users, and indeed
91       on a number you cannot find out information such as "users_desktop" at
92       all, due to security restrictions.
93
94       All methods will double check (using a "-d" test) that a directory
95       actually exists before returning it, so you may trust in the values
96       that are returned (subject to the usual caveats of race conditions of
97       directories being deleted at the moment between a directory being
98       returned and you using it).
99
100       However, because in some cases platforms may not support the concept of
101       home directories at all, any method may return "undef" (both in scalar
102       and list context) to indicate that there is no matching directory on
103       the system.
104
105       For example, most untrusted 'nobody'-type users do not have a home
106       directory. So any modules that are used in a CGI application that at
107       some level of recursion use your code, will result in calls to
108       File::HomeDir returning undef, even for a basic home() call.
109
110       my_home
111
112       The "my_home" method takes no arguments and returns the main home/pro‐
113       file directory for the current user.
114
115       If the distinction is important to you, the term "current" refers to
116       the real user, and not the effective user.
117
118       This is also the case for all of the other "my" methods.
119
120       Returns the directory path as a string, "undef" if the current user
121       does not have a home directory, or dies on error.
122
123       my_desktop
124
125       The "my_desktop" method takes no arguments and returns the "desktop"
126       directory for the current user.
127
128       Due to the diversity and complexity of implementions required to deal
129       with implementing the required functionality fully and completely, for
130       the moment "my_desktop" is not going to be implemented.
131
132       That said, I am extremely interested in code to implement "my_desktop"
133       on Unix, as long as it is capable of dealing (as the Windows implemen‐
134       tation does) with internationalisation. It should also avoid false pos‐
135       itive results by making sure it only returns the appropriate directo‐
136       ries for the appropriate platforms.
137
138       Returns the directory path as a string, "undef" if the current user
139       does not have a desktop directory, or dies on error.
140
141       my_documents
142
143       The "my_documents" method takes no arguments and returns the directory
144       (for the current user) where the user's documents are stored.
145
146       Returns the directory path as a string, "undef" if the current user
147       does not have a documents directory, or dies on error.
148
149       my_music
150
151       The "my_music" method takes no arguments and returns the directory
152       where the current user's music is stored.
153
154       No bias is made to any particular music type or music program, rather
155       the concept of a directory to hold the user's music is made at the
156       level of the underlying operating system or (at least) desktop environ‐
157       ment.
158
159       Returns the directory path as a string, "undef" if the current user
160       does not have a suitable directory, or dies on error.
161
162       my_pictures
163
164       The "my_pictures" method takes no arguments and returns the directory
165       where the current user's pictures are stored.
166
167       No bias is made to any particular picture type or picture program,
168       rather the concept of a directory to hold the user's pictures is made
169       at the level of the underlying operating system or (at least) desktop
170       environment.
171
172       Returns the directory path as a string, "undef" if the current user
173       does not have a suitable directory, or dies on error.
174
175       my_videos
176
177       The "my_videos" method takes no arguments and returns the directory
178       where the current user's videos are stored.
179
180       No bias is made to any particular video type or video program, rather
181       the concept of a directory to hold the user's videos is made at the
182       level of the underlying operating system or (at least) desktop environ‐
183       ment.
184
185       Returns the directory path as a string, "undef" if the current user
186       does not have a suitable directory, or dies on error.
187
188       my_data
189
190       The "my_data" takes no arguments and returns the directory where local
191       applications should stored their internal data for the current user.
192
193       Generally an application would create a subdirectory such as ".foo",
194       beneath this directory, and store its data there. By creating your
195       directory this way, you get an accurate result on the maximum number of
196       platforms.
197
198       For example, on Unix you get "~/.foo" and on Win32 you get "~/Local
199       Settings/Application Data/.foo"
200
201       Returns the directory path as a string, "undef" if the current user
202       does not have a data directory, or dies on error.
203
204       users_home
205
206         $home = File::HomeDir->users_home('foo');
207
208       The "users_home" method takes a single param and is used to locate the
209       parent home/profile directory for an identified user on the system.
210
211       While most of the time this identifier would be some form of user name,
212       it is permitted to vary per-platform to support user ids or UUIDs as
213       applicable for that platform.
214
215       Returns the directory path as a string, "undef" if that user does not
216       have a home directory, or dies on error.
217
218       users_documents
219
220         $docs = File::HomeDir->users_documents('foo');
221
222       Returns the directory path as a string, "undef" if that user does not
223       have a documents directory, or dies on error.
224
225       users_data
226
227         $data = File::HomeDir->users_data('foo');
228
229       Returns the directory path as a string, "undef" if that user does not
230       have a data directory, or dies on error.
231

FUNCTIONS

233       home
234
235         use File::HomeDir;
236         $home = home();
237         $home = home('foo');
238         $home = File::HomeDir::home();
239         $home = File::HomeDir::home('foo');
240
241       The "home" function is exported by default and is provided for compati‐
242       bility with legacy applications. In new applications, you should use
243       the newer method-based interface above.
244
245       Returns the directory path to a named user's home/profile directory.
246
247       If provided no param, returns the directory path to the current user's
248       home/profile directory.
249

TIED INTERFACE

251       %~
252
253         $home = $~{""};
254         $home = $~{undef};
255         $home = $~{$user};
256         $home = $~{username};
257         print "... $~{''} ...";
258         print "... $~{$user} ...";
259         print "... $~{username} ...";
260
261       This calls "home($user)" or "home('username')" -- except that if you
262       ask for $~{some_user} and there is no such user, it will die.
263
264       Note that this is especially useful in double-quotish strings, like:
265
266            print "Jojo's .newsrc is ", -s "$~{jojo}/.newsrc", "b long!\n";
267             # (helpfully dies if there is no user 'jojo')
268
269       If you want to avoid the fatal errors, first test the value of
270       "home('jojo')", which will return undef (instead of dying) in case of
271       there being no such user.
272
273       Note, however, that if the hash key is "" or undef (whether thru being
274       a literal "", or a scalar whose value is empty-string or undef), then
275       this returns zero-argument "home()", i.e., your home directory:
276
277       Further, please note that because the %~ hash compulsorily modifies a
278       hash outside of it's namespace, and presents an overly simplistic
279       approach to home directories, it is likely to ultimately be removed.
280
281       The interface is currently expected to be formally deprecated from 2010
282       (but no earlier) and removed from 2015 (but no earlier). If very heavy
283       use is found in the wild, these plans may be pushed back.
284

TO DO

286       * Become generally clearer on situations in which a user might not have
287       a particular resource.
288       * Merge remaining edge case code in File::HomeDir::Win32
289       * Add more granularity to Unix, and add support to VMS and other eso‐
290       teric platforms, so we can consider going core.
291       * Add consistent support for users_* methods
292

SUPPORT

294       This module is stored in an Open Repository at the following address.
295
296       <http://svn.phase-n.com/svn/cpan/trunk/File-HomeDir>
297
298       Write access to the repository is made available automatically to any
299       published CPAN author, and to most other volunteers on request.
300
301       If you are able to submit your bug report in the form of new (failing)
302       unit tests, or can apply your fix directly instead of submitting a
303       patch, you are strongly encouraged to do so as the author currently
304       maintains over 100 modules and it can take some time to deal with non-
305       Critical bug reports or patches.
306
307       This will guarentee that your issue will be addressed in the next
308       release of the module.
309
310       If you cannot provide a direct test or fix, or don't have time to do
311       so, then regular bug reports are still accepted and appreciated via the
312       CPAN bug tracker.
313
314       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-HomeDir>
315
316       For other issues, for commercial enhancement or support, or to have
317       your write access enabled for the repository, contact the author at the
318       email address above.
319

ACKNOWLEDGEMENTS

321       The biggest acknowledgement must go to Chris Nandor, who wielded his
322       legendary Mac-fu and turned my initial fairly ordinary Darwin implemen‐
323       tation into something that actually worked properly everywhere, and
324       then donated a Mac OS X license to allow it to be maintained properly.
325

AUTHORS

327       Adam Kennedy <adamk@cpan.org>
328
329       Sean M. Burke <sburke@cpan.org>
330
331       Chris Nandor <cnandor@cpan.org>
332
333       Stephen Steneker <stennie@cpan.org>
334

SEE ALSO

336       File::ShareDir, File::HomeDir::Win32 (legacy)
337
339       Copyright 2005, 2006 Adam Kennedy.
340
341       Some parts copyright 2000 Sean M. Burke.
342
343       Some parts copyright 2006 Chris Nandor.
344
345       Some parts copyright 2006 Stephen Steneker.
346
347       This program is free software; you can redistribute it and/or modify it
348       under the same terms as Perl itself.
349
350       The full text of the license can be found in the LICENSE file included
351       with this module.
352
353
354
355perl v5.8.8                       2007-02-08                  File::HomeDir(3)
Impressum