File: README

package info (click to toggle)
libfile-homedir-perl 0.86-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 220 kB
  • ctags: 187
  • sloc: perl: 1,907; makefile: 42
file content (335 lines) | stat: -rw-r--r-- 13,392 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
NAME
    File::HomeDir - Find your home and other directories, on any platform

SYNOPSIS
      use File::HomeDir;
      
  # Modern Interface (Current User)
      $home    = File::HomeDir->my_home;
      $desktop = File::HomeDir->my_desktop;
      $docs    = File::HomeDir->my_documents;
      $music   = File::HomeDir->my_music;
      $pics    = File::HomeDir->my_pictures;
      $videos  = File::HomeDir->my_videos;
      $data    = File::HomeDir->my_data;
      
  # Modern Interface (Other Users)
      $home    = File::HomeDir->users_home('foo');
      $desktop = File::HomeDir->users_desktop('foo');
      $docs    = File::HomeDir->users_documents('foo');
      $music   = File::HomeDir->users_music('foo');
      $pics    = File::HomeDir->users_pictures('foo');
      $video   = File::HomeDir->users_videos('foo');
      $data    = File::HomeDir->users_data('foo');
      
  # Legacy Interfaces
      print "My dir is ", home(), " and root's is ", home('root'), "\n";
      print "My dir is $~{''} and root's is $~{root}\n";
      # These both print the same thing, something like:
      #  "My dir is /home/user/mojo and root's is /"

DESCRIPTION
    File::HomeDir is a module for dealing with issues relating to the
    location of directories that are "owned" by a user, primarily your user,
    and to solve these issues consistently across a wide variety of
    platforms.

    Thus, a single API is presented that can find your resources on any
    platform.

    This module provides two main interfaces.

    The first is a modern File::Spec-style interface with a consistent OO
    API and different implementation modules to support various platforms.
    You are strongly recommended to use this interface.

    The second interface is for legacy support of the original 0.07
    interface that exported a "home()" function by default and tied the "%~"
    variable.

    It is generally not recommended that you use this interface, but due to
    back-compatibility reasons they will remain supported until at least
    2010.

    After this date, the home() function will remain, but we will consider
    deprecating the (namespace-polluting) "%~" tied hash, to be removed by
    2015 (maintaining the general Perl convention of a 10 year support
    period for legacy APIs potentially or actually in common use).

  Platform Neutrality
    In the Unix world, many different types of data can be mixed together in
    your home directory (although on some Unix platforms this is no longer
    the case, particularly for "desktop"-oriented platforms).

    On some non-Unix platforms, seperate directories are allocated for
    different types of data and have been for a long time.

    When writing applications on top of File::HomeDir, you should thus
    always try to use the most specific method you can. User documents
    should be saved in "my_documents", data that supports an application but
    isn't normally editing by the user directory should go into "my_data".

    On platforms that do not make any distinction, all these different
    methods will harmlessly degrade to the main home directory, but on
    platforms that care File::HomeDir will always try to Do The Right
    Thing(tm).

METHODS
    Two types of methods are provided. The "my_method" series of methods for
    finding resources for the current user, and the "users_method" (read as
    "user's method") series for finding resources for arbitrary users.

    This split is necesary, as on most platforms it is much easier to find
    information about the current user compared to other users, and indeed
    on a number you cannot find out information such as "users_desktop" at
    all, due to security restrictions.

    All methods will double check (using a "-d" test) that a directory
    actually exists before returning it, so you may trust in the values that
    are returned (subject to the usual caveats of race conditions of
    directories being deleted at the moment between a directory being
    returned and you using it).

    However, because in some cases platforms may not support the concept of
    home directories at all, any method may return "undef" (both in scalar
    and list context) to indicate that there is no matching directory on the
    system.

    For example, most untrusted 'nobody'-type users do not have a home
    directory. So any modules that are used in a CGI application that at
    some level of recursion use your code, will result in calls to
    File::HomeDir returning undef, even for a basic home() call.

  my_home
    The "my_home" method takes no arguments and returns the main
    home/profile directory for the current user.

    If the distinction is important to you, the term "current" refers to the
    real user, and not the effective user.

    This is also the case for all of the other "my" methods.

    Returns the directory path as a string, "undef" if the current user does
    not have a home directory, or dies on error.

  my_desktop
    The "my_desktop" method takes no arguments and returns the "desktop"
    directory for the current user.

    Due to the diversity and complexity of implementions required to deal
    with implementing the required functionality fully and completely, for
    the moment "my_desktop" is not going to be implemented.

    That said, I am extremely interested in code to implement "my_desktop"
    on Unix, as long as it is capable of dealing (as the Windows
    implementation does) with internationalisation. It should also avoid
    false positive results by making sure it only returns the appropriate
    directories for the appropriate platforms.

    Returns the directory path as a string, "undef" if the current user does
    not have a desktop directory, or dies on error.

  my_documents
    The "my_documents" method takes no arguments and returns the directory
    (for the current user) where the user's documents are stored.

    Returns the directory path as a string, "undef" if the current user does
    not have a documents directory, or dies on error.

  my_music
    The "my_music" method takes no arguments and returns the directory where
    the current user's music is stored.

    No bias is made to any particular music type or music program, rather
    the concept of a directory to hold the user's music is made at the level
    of the underlying operating system or (at least) desktop environment.

    Returns the directory path as a string, "undef" if the current user does
    not have a suitable directory, or dies on error.

  my_pictures
    The "my_pictures" method takes no arguments and returns the directory
    where the current user's pictures are stored.

    No bias is made to any particular picture type or picture program,
    rather the concept of a directory to hold the user's pictures is made at
    the level of the underlying operating system or (at least) desktop
    environment.

    Returns the directory path as a string, "undef" if the current user does
    not have a suitable directory, or dies on error.

  my_videos
    The "my_videos" method takes no arguments and returns the directory
    where the current user's videos are stored.

    No bias is made to any particular video type or video program, rather
    the concept of a directory to hold the user's videos is made at the
    level of the underlying operating system or (at least) desktop
    environment.

    Returns the directory path as a string, "undef" if the current user does
    not have a suitable directory, or dies on error.

  my_data
    The "my_data" method takes no arguments and returns the directory where
    local applications should stored their internal data for the current
    user.

    Generally an application would create a subdirectory such as ".foo",
    beneath this directory, and store its data there. By creating your
    directory this way, you get an accurate result on the maximum number of
    platforms.

    For example, on Unix you get "~/.foo" and on Win32 you get "~/Local
    Settings/Application Data/.foo"

    Returns the directory path as a string, "undef" if the current user does
    not have a data directory, or dies on error.

  users_home
      $home = File::HomeDir->users_home('foo');

    The "users_home" method takes a single param and is used to locate the
    parent home/profile directory for an identified user on the system.

    While most of the time this identifier would be some form of user name,
    it is permitted to vary per-platform to support user ids or UUIDs as
    applicable for that platform.

    Returns the directory path as a string, "undef" if that user does not
    have a home directory, or dies on error.

  users_documents
      $docs = File::HomeDir->users_documents('foo');

    Returns the directory path as a string, "undef" if that user does not
    have a documents directory, or dies on error.

  users_data
      $data = File::HomeDir->users_data('foo');

    Returns the directory path as a string, "undef" if that user does not
    have a data directory, or dies on error.

FUNCTIONS
  home
      use File::HomeDir;
      $home = home();
      $home = home('foo');
      $home = File::HomeDir::home();
      $home = File::HomeDir::home('foo');

    The "home" function is exported by default and is provided for
    compatibility with legacy applications. In new applications, you should
    use the newer method-based interface above.

    Returns the directory path to a named user's home/profile directory.

    If provided no param, returns the directory path to the current user's
    home/profile directory.

TIED INTERFACE
  %~
      $home = $~{""};
      $home = $~{undef};
      $home = $~{$user};
      $home = $~{username};
      print "... $~{''} ...";
      print "... $~{$user} ...";
      print "... $~{username} ...";

    This calls "home($user)" or "home('username')" -- except that if you ask
    for $~{some_user} and there is no such user, it will die.

    Note that this is especially useful in double-quotish strings, like:

         print "Jojo's .newsrc is ", -s "$~{jojo}/.newsrc", "b long!\n";
          # (helpfully dies if there is no user 'jojo')

    If you want to avoid the fatal errors, first test the value of
    "home('jojo')", which will return undef (instead of dying) in case of
    there being no such user.

    Note, however, that if the hash key is "" or undef (whether thru being a
    literal "", or a scalar whose value is empty-string or undef), then this
    returns zero-argument "home()", i.e., your home directory:

    Further, please note that because the "%~" hash compulsorily modifies a
    hash outside of it's namespace, and presents an overly simplistic
    approach to home directories, it is likely to ultimately be removed.

    The interface is currently expected to be formally deprecated from 2010
    (but no earlier) and removed from 2015 (but no earlier). If very heavy
    use is found in the wild, these plans may be pushed back.

TO DO
    *   Become generally clearer on situations in which a user might not
        have a particular resource.

    *   Add more granularity to Unix, and add support to VMS and other
        esoteric platforms, so we can consider going core.

    *   Add consistent support for users_* methods

SUPPORT
    This module is stored in an Open Repository at the following address.

    <http://svn.ali.as/cpan/trunk/File-HomeDir>

    Write access to the repository is made available automatically to any
    published CPAN author, and to most other volunteers on request.

    If you are able to submit your bug report in the form of new (failing)
    unit tests, or can apply your fix directly instead of submitting a
    patch, you are strongly encouraged to do so as the author currently
    maintains over 100 modules and it can take some time to deal with
    non-Critical bug reports or patches.

    This will guarantee that your issue will be addressed in the next
    release of the module.

    If you cannot provide a direct test or fix, or don't have time to do so,
    then regular bug reports are still accepted and appreciated via the CPAN
    bug tracker.

    <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-HomeDir>

    For other issues, for commercial enhancement or support, or to have your
    write access enabled for the repository, contact the author at the email
    address above.

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

AUTHORS
    Adam Kennedy <adamk@cpan.org>

    Sean M. Burke <sburke@cpan.org>

    Chris Nandor <cnandor@cpan.org>

    Stephen Steneker <stennie@cpan.org>

SEE ALSO
    File::ShareDir, File::HomeDir::Win32 (legacy)

COPYRIGHT
    Copyright 2005 - 2009 Adam Kennedy.

    Some parts copyright 2000 Sean M. Burke.

    Some parts copyright 2006 Chris Nandor.

    Some parts copyright 2006 Stephen Steneker.

    This program is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.

    The full text of the license can be found in the LICENSE file included
    with this module.