.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "File::HomeDir 3pm" .TH File::HomeDir 3pm "2018-05-17" "perl v5.26.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" File::HomeDir \- Find your home and other directories on any platform .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& 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; \& $dist = File::HomeDir\->my_dist_data(\*(AqFile\-HomeDir\*(Aq); \& $dist = File::HomeDir\->my_dist_config(\*(AqFile\-HomeDir\*(Aq); \& \& # Modern Interface (Other Users) \& $home = File::HomeDir\->users_home(\*(Aqfoo\*(Aq); \& $desktop = File::HomeDir\->users_desktop(\*(Aqfoo\*(Aq); \& $docs = File::HomeDir\->users_documents(\*(Aqfoo\*(Aq); \& $music = File::HomeDir\->users_music(\*(Aqfoo\*(Aq); \& $pics = File::HomeDir\->users_pictures(\*(Aqfoo\*(Aq); \& $video = File::HomeDir\->users_videos(\*(Aqfoo\*(Aq); \& $data = File::HomeDir\->users_data(\*(Aqfoo\*(Aq); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\fBFile::HomeDir\fR is a module for locating the directories that are \*(L"owned\*(R" by a user (typically your user) and to solve the various issues that arise trying to find them consistently across a wide variety of platforms. .PP The end result is a single \s-1API\s0 that can find your resources on any platform, making it relatively trivial to create Perl software that works elegantly and correctly no matter where you run it. .SS "Platform Neutrality" .IX Subsection "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 \*(L"desktop\*(R"\-oriented platforms). .PP On some non-Unix platforms, separate directories are allocated for different types of data and have been for a long time. .PP When writing applications on top of \fBFile::HomeDir\fR, you should thus always try to use the most specific method you can. User documents should be saved in \f(CW\*(C`my_documents\*(C'\fR, data that supports an application but isn't normally editing by the user directory should go into \f(CW\*(C`my_data\*(C'\fR. .PP 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 \fBFile::HomeDir\fR will always try to Do The Right Thing(tm). .SH "METHODS" .IX Header "METHODS" Two types of methods are provided. The \f(CW\*(C`my_method\*(C'\fR series of methods for finding resources for the current user, and the \f(CW\*(C`users_method\*(C'\fR (read as \&\*(L"user's method\*(R") series for finding resources for arbitrary users. .PP This split is necessary, as on most platforms it is \fBmuch\fR easier to find information about the current user compared to other users, and indeed on a number you cannot find out information such as \f(CW\*(C`users_desktop\*(C'\fR at all, due to security restrictions. .PP All methods will double check (using a \f(CW\*(C`\-d\*(C'\fR 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). .PP However, because in some cases platforms may not support the concept of home directories at all, any method may return \f(CW\*(C`undef\*(C'\fR (both in scalar and list context) to indicate that there is no matching directory on the system. .PP For example, most untrusted 'nobody'\-type users do not have a home directory. So any modules that are used in a \s-1CGI\s0 application that at some level of recursion use your code, will result in calls to File::HomeDir returning undef, even for a basic \fIhome()\fR call. .SS "my_home" .IX Subsection "my_home" The \f(CW\*(C`my_home\*(C'\fR method takes no arguments and returns the main home/profile directory for the current user. .PP If the distinction is important to you, the term \*(L"current\*(R" refers to the real user, and not the effective user. .PP This is also the case for all of the other \*(L"my\*(R" methods. .PP Returns the directory path as a string, \f(CW\*(C`undef\*(C'\fR if the current user does not have a home directory, or dies on error. .SS "my_desktop" .IX Subsection "my_desktop" The \f(CW\*(C`my_desktop\*(C'\fR method takes no arguments and returns the \*(L"desktop\*(R" directory for the current user. .PP Due to the diversity and complexity of implementations required to deal with implementing the required functionality fully and completely, the \&\f(CW\*(C`my_desktop\*(C'\fR method may or may not be implemented on each platform. .PP That said, I am extremely interested in code to implement \f(CW\*(C`my_desktop\*(C'\fR on Unix, as long as it is capable of dealing (as the Windows implementation does) with internationalization. It should also avoid false positive results by making sure it only returns the appropriate directories for the appropriate platforms. .PP Returns the directory path as a string, \f(CW\*(C`undef\*(C'\fR if the current user does not have a desktop directory, or dies on error. .SS "my_documents" .IX Subsection "my_documents" The \f(CW\*(C`my_documents\*(C'\fR method takes no arguments and returns the directory (for the current user) where the user's documents are stored. .PP Returns the directory path as a string, \f(CW\*(C`undef\*(C'\fR if the current user does not have a documents directory, or dies on error. .SS "my_music" .IX Subsection "my_music" The \f(CW\*(C`my_music\*(C'\fR method takes no arguments and returns the directory where the current user's music is stored. .PP 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. .PP Returns the directory path as a string, \f(CW\*(C`undef\*(C'\fR if the current user does not have a suitable directory, or dies on error. .SS "my_pictures" .IX Subsection "my_pictures" The \f(CW\*(C`my_pictures\*(C'\fR method takes no arguments and returns the directory where the current user's pictures are stored. .PP 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. .PP Returns the directory path as a string, \f(CW\*(C`undef\*(C'\fR if the current user does not have a suitable directory, or dies on error. .SS "my_videos" .IX Subsection "my_videos" The \f(CW\*(C`my_videos\*(C'\fR method takes no arguments and returns the directory where the current user's videos are stored. .PP 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. .PP Returns the directory path as a string, \f(CW\*(C`undef\*(C'\fR if the current user does not have a suitable directory, or dies on error. .SS "my_data" .IX Subsection "my_data" The \f(CW\*(C`my_data\*(C'\fR method takes no arguments and returns the directory where local applications should store their internal data for the current user. .PP Generally an application would create a subdirectory such as \f(CW\*(C`.foo\*(C'\fR, 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. But see the documentation about \f(CW\*(C`my_dist_config()\*(C'\fR or \&\f(CW\*(C`my_dist_data()\*(C'\fR below. .PP For example, on Unix you get \f(CW\*(C`~/.foo\*(C'\fR and on Win32 you get \&\f(CW\*(C`~/Local Settings/Application Data/.foo\*(C'\fR .PP Returns the directory path as a string, \f(CW\*(C`undef\*(C'\fR if the current user does not have a data directory, or dies on error. .SS "my_dist_config" .IX Subsection "my_dist_config" .Vb 1 \& File::HomeDir\->my_dist_config( $dist [, \e%params] ); \& \& # For example... \& \& File::HomeDir\->my_dist_config( \*(AqFile\-HomeDir\*(Aq ); \& File::HomeDir\->my_dist_config( \*(AqFile\-HomeDir\*(Aq, { create => 1 } ); .Ve .PP The \f(CW\*(C`my_dist_config\*(C'\fR method takes a distribution name as argument and returns an application-specific directory where they should store their internal configuration. .PP The base directory will be either \f(CW\*(C`my_config\*(C'\fR if the platform supports it, or \f(CW\*(C`my_documents\*(C'\fR otherwise. The subdirectory itself will be \&\f(CW\*(C`BASE/Perl/Dist\-Name\*(C'\fR. If the base directory is the user's home directory, \&\f(CW\*(C`my_dist_config\*(C'\fR will be in \f(CW\*(C`~/.perl/Dist\-Name\*(C'\fR (and thus be hidden on all Unixes). .PP The optional last argument is a hash reference to tweak the method behaviour. The following hash keys are recognized: .IP "\(bu" 4 create .Sp Passing a true value to this key will force the creation of the directory if it doesn't exist (remember that \f(CW\*(C`File::HomeDir\*(C'\fR's policy is to return \f(CW\*(C`undef\*(C'\fR if the directory doesn't exist). .Sp Defaults to false, meaning no automatic creation of directory. .SS "my_dist_data" .IX Subsection "my_dist_data" .Vb 1 \& File::HomeDir\->my_dist_data( $dist [, \e%params] ); \& \& # For example... \& \& File::HomeDir\->my_dist_data( \*(AqFile\-HomeDir\*(Aq ); \& File::HomeDir\->my_dist_data( \*(AqFile\-HomeDir\*(Aq, { create => 1 } ); .Ve .PP The \f(CW\*(C`my_dist_data\*(C'\fR method takes a distribution name as argument and returns an application-specific directory where they should store their internal data. .PP This directory will be of course a subdirectory of \f(CW\*(C`my_data\*(C'\fR. Platforms supporting data-specific directories will use \&\f(CW\*(C`DATA_DIR/perl/dist/Dist\-Name\*(C'\fR following the common \&\*(L"DATA/vendor/application\*(R" pattern. If the \f(CW\*(C`my_data\*(C'\fR directory is the user's home directory, \f(CW\*(C`my_dist_data\*(C'\fR will be in \f(CW\*(C`~/.perl/dist/Dist\-Name\*(C'\fR (and thus be hidden on all Unixes). .PP The optional last argument is a hash reference to tweak the method behaviour. The following hash keys are recognized: .IP "\(bu" 4 create .Sp Passing a true value to this key will force the creation of the directory if it doesn't exist (remember that \f(CW\*(C`File::HomeDir\*(C'\fR's policy is to return \f(CW\*(C`undef\*(C'\fR if the directory doesn't exist). .Sp Defaults to false, meaning no automatic creation of directory. .SS "users_home" .IX Subsection "users_home" .Vb 1 \& $home = File::HomeDir\->users_home(\*(Aqfoo\*(Aq); .Ve .PP The \f(CW\*(C`users_home\*(C'\fR method takes a single parameter and is used to locate the parent home/profile directory for an identified user on the system. .PP 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. .PP Returns the directory path as a string, \f(CW\*(C`undef\*(C'\fR if that user does not have a home directory, or dies on error. .SS "users_documents" .IX Subsection "users_documents" .Vb 1 \& $docs = File::HomeDir\->users_documents(\*(Aqfoo\*(Aq); .Ve .PP Returns the directory path as a string, \f(CW\*(C`undef\*(C'\fR if that user does not have a documents directory, or dies on error. .SS "users_data" .IX Subsection "users_data" .Vb 1 \& $data = File::HomeDir\->users_data(\*(Aqfoo\*(Aq); .Ve .PP Returns the directory path as a string, \f(CW\*(C`undef\*(C'\fR if that user does not have a data directory, or dies on error. .SS "users_desktop" .IX Subsection "users_desktop" .Vb 1 \& $docs = File::HomeDir\->users_desktop(\*(Aqfoo\*(Aq); .Ve .PP Returns the directory path as a string, \f(CW\*(C`undef\*(C'\fR if that user does not have a desktop directory, or dies on error. .SS "users_music" .IX Subsection "users_music" .Vb 1 \& $docs = File::HomeDir\->users_music(\*(Aqfoo\*(Aq); .Ve .PP Returns the directory path as a string, \f(CW\*(C`undef\*(C'\fR if that user does not have a music directory, or dies on error. .SS "users_pictures" .IX Subsection "users_pictures" .Vb 1 \& $docs = File::HomeDir\->users_pictures(\*(Aqfoo\*(Aq); .Ve .PP Returns the directory path as a string, \f(CW\*(C`undef\*(C'\fR if that user does not have a pictures directory, or dies on error. .SS "users_videos" .IX Subsection "users_videos" .Vb 1 \& $docs = File::HomeDir\->users_videos(\*(Aqfoo\*(Aq); .Ve .PP Returns the directory path as a string, \f(CW\*(C`undef\*(C'\fR if that user does not have a videos directory, or dies on error. .SH "FUNCTIONS" .IX Header "FUNCTIONS" .SS "home" .IX Subsection "home" .Vb 5 \& use File::HomeDir; \& $home = home(); \& $home = home(\*(Aqfoo\*(Aq); \& $home = File::HomeDir::home(); \& $home = File::HomeDir::home(\*(Aqfoo\*(Aq); .Ve .PP The \f(CW\*(C`home\*(C'\fR 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. .PP Returns the directory path to a named user's home/profile directory. .PP If provided no parameter, returns the directory path to the current user's home/profile directory. .SH "TO DO" .IX Header "TO DO" .IP "\(bu" 4 Add more granularity to Unix, and add support to \s-1VMS\s0 and other esoteric platforms, so we can consider going core. .IP "\(bu" 4 Add consistent support for users_* methods .SH "SUPPORT" .IX Header "SUPPORT" This module is stored in an Open Repository at the following address. .PP .PP Write access to the repository is made available automatically to any published \s-1CPAN\s0 author, and to most other volunteers on request. .PP 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 \fBstrongly\fR 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. .PP This will guarantee that your issue will be addressed in the next release of the module. .PP 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 \s-1CPAN\s0 bug tracker. .PP .PP 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. .SH "ACKNOWLEDGEMENTS" .IX Header "ACKNOWLEDGEMENTS" The biggest acknowledgement goes 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 \s-1OS X\s0 license to allow it to be maintained properly. .SH "AUTHORS" .IX Header "AUTHORS" Adam Kennedy .PP Sean M. Burke .PP Chris Nandor .PP Stephen Steneker .SH "SEE ALSO" .IX Header "SEE ALSO" File::ShareDir, File::HomeDir::Win32 (legacy) .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright 2005 \- 2012 Adam Kennedy. .PP Some parts copyright 2000 Sean M. Burke. .PP Some parts copyright 2006 Chris Nandor. .PP Some parts copyright 2006 Stephen Steneker. .PP Some parts copyright 2009\-2011 Jérôme Quelin. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .PP The full text of the license can be found in the \&\s-1LICENSE\s0 file included with this module.