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         $dist     = File::HomeDir->my_dist_data('File-HomeDir');
20         $dist     = File::HomeDir->my_dist_config('File-HomeDir');
21
22         # Modern Interface (Other Users)
23         $home    = File::HomeDir->users_home('foo');
24         $desktop = File::HomeDir->users_desktop('foo');
25         $docs    = File::HomeDir->users_documents('foo');
26         $music   = File::HomeDir->users_music('foo');
27         $pics    = File::HomeDir->users_pictures('foo');
28         $video   = File::HomeDir->users_videos('foo');
29         $data    = File::HomeDir->users_data('foo');
30

DESCRIPTION

32       File::HomeDir is a module for locating the directories that are "owned"
33       by a user (typically your user) and to solve the various issues that
34       arise trying to find them consistently across a wide variety of
35       platforms.
36
37       The end result is a single API that can find your resources on any
38       platform, making it relatively trivial to create Perl software that
39       works elegantly and correctly no matter where you run it.
40
41   Platform Neutrality
42       In the Unix world, many different types of data can be mixed together
43       in your home directory (although on some Unix platforms this is no
44       longer the case, particularly for "desktop"-oriented platforms).
45
46       On some non-Unix platforms, separate directories are allocated for
47       different types of data and have been for a long time.
48
49       When writing applications on top of File::HomeDir, you should thus
50       always try to use the most specific method you can. User documents
51       should be saved in "my_documents", data that supports an application
52       but isn't normally editing by the user directory should go into
53       "my_data".
54
55       On platforms that do not make any distinction, all these different
56       methods will harmlessly degrade to the main home directory, but on
57       platforms that care File::HomeDir will always try to Do The Right
58       Thing(tm).
59

METHODS

61       Two types of methods are provided. The "my_method" series of methods
62       for finding resources for the current user, and the "users_method"
63       (read as "user's method") series for finding resources for arbitrary
64       users.
65
66       This split is necessary, as on most platforms it is much easier to find
67       information about the current user compared to other users, and indeed
68       on a number you cannot find out information such as "users_desktop" at
69       all, due to security restrictions.
70
71       All methods will double check (using a "-d" test) that a directory
72       actually exists before returning it, so you may trust in the values
73       that are returned (subject to the usual caveats of race conditions of
74       directories being deleted at the moment between a directory being
75       returned and you using it).
76
77       However, because in some cases platforms may not support the concept of
78       home directories at all, any method may return "undef" (both in scalar
79       and list context) to indicate that there is no matching directory on
80       the system.
81
82       For example, most untrusted 'nobody'-type users do not have a home
83       directory. So any modules that are used in a CGI application that at
84       some level of recursion use your code, will result in calls to
85       File::HomeDir returning undef, even for a basic home() call.
86
87   my_home
88       The "my_home" method takes no arguments and returns the main
89       home/profile directory for the current user.
90
91       If the distinction is important to you, the term "current" refers to
92       the real user, and not the effective user.
93
94       This is also the case for all of the other "my" methods.
95
96       Returns the directory path as a string, "undef" if the current user
97       does not have a home directory, or dies on error.
98
99   my_desktop
100       The "my_desktop" method takes no arguments and returns the "desktop"
101       directory for the current user.
102
103       Due to the diversity and complexity of implementations required to deal
104       with implementing the required functionality fully and completely, the
105       "my_desktop" method may or may not be implemented on each platform.
106
107       That said, I am extremely interested in code to implement "my_desktop"
108       on Unix, as long as it is capable of dealing (as the Windows
109       implementation does) with internationalization. It should also avoid
110       false positive results by making sure it only returns the appropriate
111       directories for the appropriate platforms.
112
113       Returns the directory path as a string, "undef" if the current user
114       does not have a desktop directory, or dies on error.
115
116   my_documents
117       The "my_documents" method takes no arguments and returns the directory
118       (for the current user) where the user's documents are stored.
119
120       Returns the directory path as a string, "undef" if the current user
121       does not have a documents directory, or dies on error.
122
123   my_music
124       The "my_music" method takes no arguments and returns the directory
125       where the current user's music is stored.
126
127       No bias is made to any particular music type or music program, rather
128       the concept of a directory to hold the user's music is made at the
129       level of the underlying operating system or (at least) desktop
130       environment.
131
132       Returns the directory path as a string, "undef" if the current user
133       does not have a suitable directory, or dies on error.
134
135   my_pictures
136       The "my_pictures" method takes no arguments and returns the directory
137       where the current user's pictures are stored.
138
139       No bias is made to any particular picture type or picture program,
140       rather the concept of a directory to hold the user's pictures is made
141       at the level of the underlying operating system or (at least) desktop
142       environment.
143
144       Returns the directory path as a string, "undef" if the current user
145       does not have a suitable directory, or dies on error.
146
147   my_videos
148       The "my_videos" method takes no arguments and returns the directory
149       where the current user's videos are stored.
150
151       No bias is made to any particular video type or video program, rather
152       the concept of a directory to hold the user's videos is made at the
153       level of the underlying operating system or (at least) desktop
154       environment.
155
156       Returns the directory path as a string, "undef" if the current user
157       does not have a suitable directory, or dies on error.
158
159   my_data
160       The "my_data" method takes no arguments and returns the directory where
161       local applications should store their internal data for the current
162       user.
163
164       Generally an application would create a subdirectory such as ".foo",
165       beneath this directory, and store its data there. By creating your
166       directory this way, you get an accurate result on the maximum number of
167       platforms. But see the documentation about "my_dist_config()" or
168       "my_dist_data()" below.
169
170       For example, on Unix you get "~/.foo" and on Win32 you get "~/Local
171       Settings/Application Data/.foo"
172
173       Returns the directory path as a string, "undef" if the current user
174       does not have a data directory, or dies on error.
175
176   my_dist_config
177         File::HomeDir->my_dist_config( $dist [, \%params] );
178
179         # For example...
180
181         File::HomeDir->my_dist_config( 'File-HomeDir' );
182         File::HomeDir->my_dist_config( 'File-HomeDir', { create => 1 } );
183
184       The "my_dist_config" method takes a distribution name as argument and
185       returns an application-specific directory where they should store their
186       internal configuration.
187
188       The base directory will be either "my_config" if the platform supports
189       it, or "my_documents" otherwise. The subdirectory itself will be
190       "BASE/Perl/Dist-Name". If the base directory is the user's home
191       directory, "my_dist_config" will be in "~/.perl/Dist-Name" (and thus be
192       hidden on all Unixes).
193
194       The optional last argument is a hash reference to tweak the method
195       behaviour. The following hash keys are recognized:
196
197       •   create
198
199           Passing a true value to this key will force the creation of the
200           directory if it doesn't exist (remember that "File::HomeDir"'s
201           policy is to return "undef" if the directory doesn't exist).
202
203           Defaults to false, meaning no automatic creation of directory.
204
205   my_dist_data
206         File::HomeDir->my_dist_data( $dist [, \%params] );
207
208         # For example...
209
210         File::HomeDir->my_dist_data( 'File-HomeDir' );
211         File::HomeDir->my_dist_data( 'File-HomeDir', { create => 1 } );
212
213       The "my_dist_data" method takes a distribution name as argument and
214       returns an application-specific directory where they should store their
215       internal data.
216
217       This directory will be of course a subdirectory of "my_data". Platforms
218       supporting data-specific directories will use
219       "DATA_DIR/perl/dist/Dist-Name" following the common
220       "DATA/vendor/application" pattern. If the "my_data" directory is the
221       user's home directory, "my_dist_data" will be in
222       "~/.perl/dist/Dist-Name" (and thus be hidden on all Unixes).
223
224       The optional last argument is a hash reference to tweak the method
225       behaviour. The following hash keys are recognized:
226
227       •   create
228
229           Passing a true value to this key will force the creation of the
230           directory if it doesn't exist (remember that "File::HomeDir"'s
231           policy is to return "undef" if the directory doesn't exist).
232
233           Defaults to false, meaning no automatic creation of directory.
234
235   users_home
236         $home = File::HomeDir->users_home('foo');
237
238       The "users_home" method takes a single parameter and is used to locate
239       the parent home/profile directory for an identified user on the system.
240
241       While most of the time this identifier would be some form of user name,
242       it is permitted to vary per-platform to support user ids or UUIDs as
243       applicable for that platform.
244
245       Returns the directory path as a string, "undef" if that user does not
246       have a home directory, or dies on error.
247
248   users_documents
249         $docs = File::HomeDir->users_documents('foo');
250
251       Returns the directory path as a string, "undef" if that user does not
252       have a documents directory, or dies on error.
253
254   users_data
255         $data = File::HomeDir->users_data('foo');
256
257       Returns the directory path as a string, "undef" if that user does not
258       have a data directory, or dies on error.
259
260   users_desktop
261         $docs = File::HomeDir->users_desktop('foo');
262
263       Returns the directory path as a string, "undef" if that user does not
264       have a desktop directory, or dies on error.
265
266   users_music
267         $docs = File::HomeDir->users_music('foo');
268
269       Returns the directory path as a string, "undef" if that user does not
270       have a music directory, or dies on error.
271
272   users_pictures
273         $docs = File::HomeDir->users_pictures('foo');
274
275       Returns the directory path as a string, "undef" if that user does not
276       have a pictures directory, or dies on error.
277
278   users_videos
279         $docs = File::HomeDir->users_videos('foo');
280
281       Returns the directory path as a string, "undef" if that user does not
282       have a videos directory, or dies on error.
283

FUNCTIONS

285   home
286         use File::HomeDir;
287         $home = home();
288         $home = home('foo');
289         $home = File::HomeDir::home();
290         $home = File::HomeDir::home('foo');
291
292       The "home" function is exported by default and is provided for
293       compatibility with legacy applications. In new applications, you should
294       use the newer method-based interface above.
295
296       Returns the directory path to a named user's home/profile directory.
297
298       If provided no parameter, returns the directory path to the current
299       user's home/profile directory.
300

TO DO

302       •   Add more granularity to Unix, and add support to VMS and other
303           esoteric platforms, so we can consider going core.
304
305       •   Add consistent support for users_* methods
306

SUPPORT

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

ACKNOWLEDGEMENTS

335       The biggest acknowledgement goes to Chris Nandor, who wielded his
336       legendary Mac-fu and turned my initial fairly ordinary Darwin
337       implementation into something that actually worked properly everywhere,
338       and then donated a Mac OS X license to allow it to be maintained
339       properly.
340

AUTHORS

342       Adam Kennedy <adamk@cpan.org>
343
344       Sean M. Burke <sburke@cpan.org>
345
346       Chris Nandor <cnandor@cpan.org>
347
348       Stephen Steneker <stennie@cpan.org>
349

SEE ALSO

351       File::ShareDir, File::HomeDir::Win32 (legacy)
352
354       Copyright 2005 - 2012 Adam Kennedy.
355
356       Copyright 2017 - 2020 Jens Rehsack
357
358       Some parts copyright 2000 Sean M. Burke.
359
360       Some parts copyright 2006 Chris Nandor.
361
362       Some parts copyright 2006 Stephen Steneker.
363
364       Some parts copyright 2009-2011 Jérôme Quelin.
365
366       This program is free software; you can redistribute it and/or modify it
367       under the same terms as Perl itself.
368
369       The full text of the license can be found in the LICENSE file included
370       with this module.
371
372
373
374perl v5.32.1                      2021-01-27                  File::HomeDir(3)
Impressum