• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

lib/File/H28-Sep-2020-2,230943

t/H28-Sep-2020-650493

.perltidyrcH A D11-Mar-2018124 1817

ChangesH A D28-Sep-202012.2 KiB367286

LICENSEH A D11-Mar-201820.1 KiB399324

MANIFESTH A D28-Sep-2020631 2726

MANIFEST.SKIPH A D28-Sep-2020329 3534

META.jsonH A D28-Sep-20202.2 KiB8382

META.ymlH A D28-Sep-2020958 3736

Makefile.PLH A D28-Sep-20204.9 KiB136123

README.mdH A D11-Mar-201813.4 KiB385258

README.md

1# NAME
2
3File::HomeDir - Find your home and other directories on any platform
4
5# SYNOPSIS
6
7    use File::HomeDir;
8
9    # Modern Interface (Current User)
10    $home     = File::HomeDir->my_home;
11    $desktop  = File::HomeDir->my_desktop;
12    $docs     = File::HomeDir->my_documents;
13    $music    = File::HomeDir->my_music;
14    $pics     = File::HomeDir->my_pictures;
15    $videos   = File::HomeDir->my_videos;
16    $data     = File::HomeDir->my_data;
17    $dist     = File::HomeDir->my_dist_data('File-HomeDir');
18    $dist     = File::HomeDir->my_dist_config('File-HomeDir');
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# DESCRIPTION
30
31**File::HomeDir** is a module for locating the directories that are "owned"
32by a user (typically your user) and to solve the various issues that arise
33trying to find them consistently across a wide variety of platforms.
34
35The end result is a single API that can find your resources on any platform,
36making it relatively trivial to create Perl software that works elegantly
37and correctly no matter where you run it.
38
39## Platform Neutrality
40
41In the Unix world, many different types of data can be mixed together
42in your home directory (although on some Unix platforms this is no longer
43the case, particularly for "desktop"-oriented platforms).
44
45On some non-Unix platforms, separate directories are allocated for
46different types of data and have been for a long time.
47
48When writing applications on top of **File::HomeDir**, you should thus
49always try to use the most specific method you can. User documents should
50be saved in `my_documents`, data that supports an application but isn't
51normally editing by the user directory should go into `my_data`.
52
53On platforms that do not make any distinction, all these different
54methods will harmlessly degrade to the main home directory, but on
55platforms that care **File::HomeDir** will always try to Do The Right
56Thing(tm).
57
58# METHODS
59
60Two types of methods are provided. The `my_method` series of methods for
61finding resources for the current user, and the `users_method` (read as
62"user's method") series for finding resources for arbitrary users.
63
64This split is necessary, as on most platforms it is **much** easier to find
65information about the current user compared to other users, and indeed
66on a number you cannot find out information such as `users_desktop` at
67all, due to security restrictions.
68
69All methods will double check (using a `-d` test) that a directory
70actually exists before returning it, so you may trust in the values
71that are returned (subject to the usual caveats of race conditions of
72directories being deleted at the moment between a directory being returned
73and you using it).
74
75However, because in some cases platforms may not support the concept of home
76directories at all, any method may return `undef` (both in scalar and list
77context) to indicate that there is no matching directory on the system.
78
79For example, most untrusted 'nobody'-type users do not have a home
80directory. So any modules that are used in a CGI application that
81at some level of recursion use your code, will result in calls to
82File::HomeDir returning undef, even for a basic home() call.
83
84## my\_home
85
86The `my_home` method takes no arguments and returns the main home/profile
87directory for the current user.
88
89If the distinction is important to you, the term "current" refers to the
90real user, and not the effective user.
91
92This is also the case for all of the other "my" methods.
93
94Returns the directory path as a string, `undef` if the current user
95does not have a home directory, or dies on error.
96
97## my\_desktop
98
99The `my_desktop` method takes no arguments and returns the "desktop"
100directory for the current user.
101
102Due to the diversity and complexity of implementations required to deal with
103implementing the required functionality fully and completely, the
104`my_desktop` method may or may not be implemented on each platform.
105
106That said, I am extremely interested in code to implement `my_desktop` on
107Unix, as long as it is capable of dealing (as the Windows implementation
108does) with internationalisation. It should also avoid false positive
109results by making sure it only returns the appropriate directories for the
110appropriate platforms.
111
112Returns the directory path as a string, `undef` if the current user
113does not have a desktop directory, or dies on error.
114
115## my\_documents
116
117The `my_documents` method takes no arguments and returns the directory (for
118the current user) where the user's documents are stored.
119
120Returns the directory path as a string, `undef` if the current user
121does not have a documents directory, or dies on error.
122
123## my\_music
124
125The `my_music` method takes no arguments and returns the directory
126where the current user's music is stored.
127
128No bias is made to any particular music type or music program, rather the
129concept of a directory to hold the user's music is made at the level of the
130underlying operating system or (at least) desktop environment.
131
132Returns the directory path as a string, `undef` if the current user
133does not have a suitable directory, or dies on error.
134
135## my\_pictures
136
137The `my_pictures` method takes no arguments and returns the directory
138where the current user's pictures are stored.
139
140No bias is made to any particular picture type or picture program, rather the
141concept of a directory to hold the user's pictures is made at the level of the
142underlying operating system or (at least) desktop environment.
143
144Returns the directory path as a string, `undef` if the current user
145does not have a suitable directory, or dies on error.
146
147## my\_videos
148
149The `my_videos` method takes no arguments and returns the directory
150where the current user's videos are stored.
151
152No bias is made to any particular video type or video program, rather the
153concept of a directory to hold the user's videos is made at the level of the
154underlying operating system or (at least) desktop environment.
155
156Returns the directory path as a string, `undef` if the current user
157does not have a suitable directory, or dies on error.
158
159## my\_data
160
161The `my_data` method takes no arguments and returns the directory where
162local applications should store their internal data for the current
163user.
164
165Generally an application would create a subdirectory such as `.foo`,
166beneath this directory, and store its data there. By creating your
167directory this way, you get an accurate result on the maximum number of
168platforms. But see the documentation about `my_dist_config()` or
169`my_dist_data()` below.
170
171For example, on Unix you get `~/.foo` and on Win32 you get
172`~/Local Settings/Application Data/.foo`
173
174Returns the directory path as a string, `undef` if the current user
175does not have a data directory, or dies on error.
176
177## my\_dist\_config
178
179    File::HomeDir->my_dist_config( $dist [, \%params] );
180
181    # For example...
182
183    File::HomeDir->my_dist_config( 'File-HomeDir' );
184    File::HomeDir->my_dist_config( 'File-HomeDir', { create => 1 } );
185
186The `my_dist_config` method takes a distribution name as argument and
187returns an application-specific directory where they should store their
188internal configuration.
189
190The base directory will be either `my_config` if the platform supports
191it, or `my_documents` otherwise. The subdirectory itself will be
192`BASE/Perl/Dist-Name`. If the base directory is the user's homedir,
193`my_dist_config` will be in `~/.perl/Dist-Name` (and thus be hidden on
194all Unixes).
195
196The optional last argument is a hash reference to tweak the method
197behaviour. The following hash keys are recognized:
198
199- create
200
201    Passing a true value to this key will force the creation of the
202    directory if it doesn't exist (remember that `File::HomeDir`'s policy
203    is to return `undef` if the directory doesn't exist).
204
205    Defaults to false, meaning no automatic creation of directory.
206
207## my\_dist\_data
208
209    File::HomeDir->my_dist_data( $dist [, \%params] );
210
211    # For example...
212
213    File::HomeDir->my_dist_data( 'File-HomeDir' );
214    File::HomeDir->my_dist_data( 'File-HomeDir', { create => 1 } );
215
216The `my_dist_data` method takes a distribution name as argument and
217returns an application-specific directory where they should store their
218internal data.
219
220This directory will be of course a subdirectory of `my_data`. Platforms
221supporting data-specific directories will use
222`DATA_DIR/perl/dist/Dist-Name` following the common
223"DATA/vendor/application" pattern. If the `my_data` directory is the
224user's homedir, `my_dist_data` will be in `~/.perl/dist/Dist-Name`
225(and thus be hidden on all Unixes).
226
227The optional last argument is a hash reference to tweak the method
228behaviour. The following hash keys are recognized:
229
230- create
231
232    Passing a true value to this key will force the creation of the
233    directory if it doesn't exist (remember that `File::HomeDir`'s policy
234    is to return `undef` if the directory doesn't exist).
235
236    Defaults to false, meaning no automatic creation of directory.
237
238## users\_home
239
240    $home = File::HomeDir->users_home('foo');
241
242The `users_home` method takes a single param and is used to locate the
243parent home/profile directory for an identified user on the system.
244
245While most of the time this identifier would be some form of user name,
246it is permitted to vary per-platform to support user ids or UUIDs as
247applicable for that platform.
248
249Returns the directory path as a string, `undef` if that user
250does not have a home directory, or dies on error.
251
252## users\_documents
253
254    $docs = File::HomeDir->users_documents('foo');
255
256Returns the directory path as a string, `undef` if that user
257does not have a documents directory, or dies on error.
258
259## users\_data
260
261    $data = File::HomeDir->users_data('foo');
262
263Returns the directory path as a string, `undef` if that user
264does not have a data directory, or dies on error.
265
266## users\_desktop
267
268    $docs = File::HomeDir->users_desktop('foo');
269
270Returns the directory path as a string, `undef` if that user
271does not have a desktop directory, or dies on error.
272
273## users\_music
274
275    $docs = File::HomeDir->users_music('foo');
276
277Returns the directory path as a string, `undef` if that user
278does not have a music directory, or dies on error.
279
280## users\_pictures
281
282    $docs = File::HomeDir->users_pictures('foo');
283
284Returns the directory path as a string, `undef` if that user
285does not have a pictures directory, or dies on error.
286
287## users\_videos
288
289    $docs = File::HomeDir->users_videos('foo');
290
291Returns the directory path as a string, `undef` if that user
292does not have a videos directory, or dies on error.
293
294# FUNCTIONS
295
296## home
297
298    use File::HomeDir;
299    $home = home();
300    $home = home('foo');
301    $home = File::HomeDir::home();
302    $home = File::HomeDir::home('foo');
303
304The `home` function is exported by default and is provided for
305compatibility with legacy applications. In new applications, you should
306use the newer method-based interface above.
307
308Returns the directory path to a named user's home/profile directory.
309
310If provided no param, returns the directory path to the current user's
311home/profile directory.
312
313# TO DO
314
315- Add more granularity to Unix, and add support to VMS and other
316esoteric platforms, so we can consider going core.
317- Add consistent support for users\_\* methods
318
319# SUPPORT
320
321This module is stored in an Open Repository at the following address.
322
323[http://svn.ali.as/cpan/trunk/File-HomeDir](http://svn.ali.as/cpan/trunk/File-HomeDir)
324
325Write access to the repository is made available automatically to any
326published CPAN author, and to most other volunteers on request.
327
328If you are able to submit your bug report in the form of new (failing)
329unit tests, or can apply your fix directly instead of submitting a patch,
330you are **strongly** encouraged to do so as the author currently maintains
331over 100 modules and it can take some time to deal with non-Critical bug
332reports or patches.
333
334This will guarantee that your issue will be addressed in the next
335release of the module.
336
337If you cannot provide a direct test or fix, or don't have time to do so,
338then regular bug reports are still accepted and appreciated via the CPAN
339bug tracker.
340
341[http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-HomeDir](http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-HomeDir)
342
343For other issues, for commercial enhancement or support, or to have your
344write access enabled for the repository, contact the author at the email
345address above.
346
347# ACKNOWLEDGEMENTS
348
349The biggest acknowledgement goes to Chris Nandor, who wielded his
350legendary Mac-fu and turned my initial fairly ordinary Darwin
351implementation into something that actually worked properly everywhere,
352and then donated a Mac OS X license to allow it to be maintained properly.
353
354# AUTHORS
355
356Adam Kennedy <adamk@cpan.org>
357
358Sean M. Burke <sburke@cpan.org>
359
360Chris Nandor <cnandor@cpan.org>
361
362Stephen Steneker <stennie@cpan.org>
363
364# SEE ALSO
365
366[File::ShareDir](https://metacpan.org/pod/File::ShareDir), [File::HomeDir::Win32](https://metacpan.org/pod/File::HomeDir::Win32) (legacy)
367
368# COPYRIGHT
369
370Copyright 2005 - 2012 Adam Kennedy.
371
372Some parts copyright 2000 Sean M. Burke.
373
374Some parts copyright 2006 Chris Nandor.
375
376Some parts copyright 2006 Stephen Steneker.
377
378Some parts copyright 2009-2011 Jérôme Quelin.
379
380This program is free software; you can redistribute
381it and/or modify it under the same terms as Perl itself.
382
383The full text of the license can be found in the
384LICENSE file included with this module.
385