view release on metacpan or search on metacpan
- More special casing in tests to deal with stripped down non-root
Mac environments (mostly to make BINGOS' automated testing pass)
0.93 2010-09-15
- Production release, no changes from 0.92_05
0.92_05 2010-09-13
- use Mac::SystemDirectory for each Darwin based MacOS. (REHSACK)
0.92_04 2010-09-10
- Be less strict about desktop and others on FreeDesktop (ADAMK)
0.92_03 2010-09-06
- Adding experimental support for my_dist_config() (JQUELIN)
- Adding diag comment on which drivers gets used (ADAMK)
0.92_02 2010-06-28
- Updating to Module::Install 1.00 (ADAMK)
- Add a bit more docs, and tweak the existing stuff a bit (ADAMK)
- Deprecated the %~ interface. It will continue to exist as an
undocumented legacy interface until 2015, warnings will be
# 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;
$dist = File::HomeDir->my_dist_data('File-HomeDir');
$dist = File::HomeDir->my_dist_config('File-HomeDir');
# 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');
# DESCRIPTION
**File::HomeDir** is a module for locating the directories that are "owned"
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.
The end result is a single API 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.
## 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, separate 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
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 necessary, 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
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 implementations required to deal with
implementing the required functionality fully and completely, the
`my_desktop` method may or may not be implemented on each platform.
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 store their internal data for the current
user.
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.
## users\_desktop
$docs = File::HomeDir->users_desktop('foo');
Returns the directory path as a string, `undef` if that user
does not have a desktop directory, or dies on error.
## users\_music
$docs = File::HomeDir->users_music('foo');
Returns the directory path as a string, `undef` if that user
does not have a music directory, or dies on error.
## users\_pictures
lib/File/HomeDir.pm view on Meta::CPAN
BEGIN
{
$VERSION = '1.006';
# Inherit manually
require Exporter;
@EXPORT = qw{home};
@EXPORT_OK = qw{
home
my_home
my_desktop
my_documents
my_music
my_pictures
my_videos
my_data
my_dist_config
my_dist_data
users_home
users_desktop
users_documents
users_music
users_pictures
users_videos
users_data
};
}
# Inlined Params::Util functions
sub _CLASS ($) ## no critic qw(SubroutinePrototypes)
lib/File/HomeDir.pm view on Meta::CPAN
$IMPLEMENTED_BY = 'File::HomeDir::Darwin';
}
}
elsif ($^O eq 'MacOS')
{
# Legacy Mac OS
$IMPLEMENTED_BY = 'File::HomeDir::MacOS9';
}
elsif (File::Which::which('xdg-user-dir'))
{
# freedesktop unixes
$IMPLEMENTED_BY = 'File::HomeDir::FreeDesktop';
}
else
{
# Default to Unix semantics
$IMPLEMENTED_BY = 'File::HomeDir::Unix';
}
unless (_DRIVER($IMPLEMENTED_BY, 'File::HomeDir::Driver'))
{
lib/File/HomeDir.pm view on Meta::CPAN
}
#####################################################################
# Current User Methods
sub my_home
{
$IMPLEMENTED_BY->my_home;
}
sub my_desktop
{
$IMPLEMENTED_BY->can('my_desktop')
? $IMPLEMENTED_BY->my_desktop
: Carp::croak("The my_desktop method is not implemented on this platform");
}
sub my_documents
{
$IMPLEMENTED_BY->can('my_documents')
? $IMPLEMENTED_BY->my_documents
: Carp::croak("The my_documents method is not implemented on this platform");
}
sub my_music
lib/File/HomeDir.pm view on Meta::CPAN
#####################################################################
# General User Methods
sub users_home
{
$IMPLEMENTED_BY->can('users_home')
? $IMPLEMENTED_BY->users_home($_[-1])
: Carp::croak("The users_home method is not implemented on this platform");
}
sub users_desktop
{
$IMPLEMENTED_BY->can('users_desktop')
? $IMPLEMENTED_BY->users_desktop($_[-1])
: Carp::croak("The users_desktop method is not implemented on this platform");
}
sub users_documents
{
$IMPLEMENTED_BY->can('users_documents')
? $IMPLEMENTED_BY->users_documents($_[-1])
: Carp::croak("The users_documents method is not implemented on this platform");
}
sub users_music
lib/File/HomeDir.pm view on Meta::CPAN
<a href='https://coveralls.io/github/perl5-utils/File-HomeDir?branch=master'><img src='https://coveralls.io/repos/github/perl5-utils/File-HomeDir/badge.svg?branch=master' alt='Coverage Status'/></a>
=end html
=head1 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;
$dist = File::HomeDir->my_dist_data('File-HomeDir');
$dist = File::HomeDir->my_dist_config('File-HomeDir');
# 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');
=head1 DESCRIPTION
B<File::HomeDir> is a module for locating the directories that are "owned"
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.
The end result is a single API 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.
=head2 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, separate directories are allocated for
different types of data and have been for a long time.
When writing applications on top of B<File::HomeDir>, you should thus
always try to use the most specific method you can. User documents should
be saved in C<my_documents>, data that supports an application but isn't
normally editing by the user directory should go into C<my_data>.
On platforms that do not make any distinction, all these different
lib/File/HomeDir.pm view on Meta::CPAN
Thing(tm).
=head1 METHODS
Two types of methods are provided. The C<my_method> series of methods for
finding resources for the current user, and the C<users_method> (read as
"user's method") series for finding resources for arbitrary users.
This split is necessary, as on most platforms it is B<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 C<users_desktop> at
all, due to security restrictions.
All methods will double check (using a C<-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 C<undef> (both in scalar and list
lib/File/HomeDir.pm view on Meta::CPAN
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, C<undef> if the current user
does not have a home directory, or dies on error.
=head2 my_desktop
The C<my_desktop> method takes no arguments and returns the "desktop"
directory for the current user.
Due to the diversity and complexity of implementations required to deal with
implementing the required functionality fully and completely, the
C<my_desktop> method may or may not be implemented on each platform.
That said, I am extremely interested in code to implement C<my_desktop> 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.
Returns the directory path as a string, C<undef> if the current user
does not have a desktop directory, or dies on error.
=head2 my_documents
The C<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, C<undef> if the current user
does not have a documents directory, or dies on error.
=head2 my_music
The C<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, C<undef> if the current user
does not have a suitable directory, or dies on error.
=head2 my_pictures
The C<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, C<undef> if the current user
does not have a suitable directory, or dies on error.
=head2 my_videos
The C<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, C<undef> if the current user
does not have a suitable directory, or dies on error.
=head2 my_data
The C<my_data> method takes no arguments and returns the directory where
local applications should store their internal data for the current
user.
lib/File/HomeDir.pm view on Meta::CPAN
Returns the directory path as a string, C<undef> if that user
does not have a documents directory, or dies on error.
=head2 users_data
$data = File::HomeDir->users_data('foo');
Returns the directory path as a string, C<undef> if that user
does not have a data directory, or dies on error.
=head2 users_desktop
$docs = File::HomeDir->users_desktop('foo');
Returns the directory path as a string, C<undef> if that user
does not have a desktop directory, or dies on error.
=head2 users_music
$docs = File::HomeDir->users_music('foo');
Returns the directory path as a string, C<undef> if that user
does not have a music directory, or dies on error.
=head2 users_pictures
lib/File/HomeDir/Darwin.pm view on Meta::CPAN
{
# Make sure that symlinks resolve to directories.
return undef unless -l $folder;
my $dir = readlink $folder or return;
return undef unless -d $dir;
}
return Cwd::abs_path($folder);
}
sub my_desktop
{
my $class = shift;
$class->_my_home('Desktop');
}
sub my_documents
{
my $class = shift;
$class->_my_home('Documents');
}
lib/File/HomeDir/Darwin.pm view on Meta::CPAN
#####################################################################
# Arbitrary User Methods
sub users_home
{
my $class = shift;
my $home = $class->SUPER::users_home(@_);
return defined $home ? Cwd::abs_path($home) : undef;
}
sub users_desktop
{
my ($class, $name) = @_;
return undef if $name eq 'root';
$class->_to_user($class->my_desktop, $name);
}
sub users_documents
{
my ($class, $name) = @_;
return undef if $name eq 'root';
$class->_to_user($class->my_documents, $name);
}
sub users_data
lib/File/HomeDir/Darwin.pm view on Meta::CPAN
common user directories in pure perl, by just using C<$ENV{HOME}>
without Carbon nor Cocoa API calls. In normal usage this module will
always be used via L<File::HomeDir>.
=head1 SYNOPSIS
use File::HomeDir;
# Find directories for the current user
$home = File::HomeDir->my_home; # /Users/mylogin
$desktop = File::HomeDir->my_desktop; # /Users/mylogin/Desktop
$docs = File::HomeDir->my_documents; # /Users/mylogin/Documents
$music = File::HomeDir->my_music; # /Users/mylogin/Music
$pics = File::HomeDir->my_pictures; # /Users/mylogin/Pictures
$videos = File::HomeDir->my_videos; # /Users/mylogin/Movies
$data = File::HomeDir->my_data; # /Users/mylogin/Library/Application Support
=head1 COPYRIGHT
Copyright 2009 - 2011 Adam Kennedy.
lib/File/HomeDir/Darwin/Carbon.pm view on Meta::CPAN
sub _guess_determined_home
{
my $class = shift;
require Mac::Files;
my $home = $class->_find_folder(Mac::Files::kCurrentUserFolderType(),);
$home ||= $class->SUPER::_guess_determined_home($@);
return $home;
}
sub my_desktop
{
my $class = shift;
require Mac::Files;
$class->_find_folder(Mac::Files::kDesktopFolderType(),);
}
sub my_documents
{
my $class = shift;
lib/File/HomeDir/Darwin/Carbon.pm view on Meta::CPAN
sub users_home
{
my $class = shift;
my $home = $class->SUPER::users_home(@_);
return defined $home ? Cwd::abs_path($home) : undef;
}
# in theory this can be done, but for now, let's cheat, since the
# rest is Hard
sub users_desktop
{
my ($class, $name) = @_;
return undef if $name eq 'root';
$class->_to_user($class->my_desktop, $name);
}
sub users_documents
{
my ($class, $name) = @_;
return undef if $name eq 'root';
$class->_to_user($class->my_documents, $name);
}
sub users_data
lib/File/HomeDir/Darwin/Carbon.pm view on Meta::CPAN
not work with 64-bit perls, on such systems, File::HomeDir will try
L<File::HomeDir::Darwin::Cocoa> and then fall back to the (pure Perl)
L<File::HomeDir::Darwin>.
=head1 SYNOPSIS
use File::HomeDir;
# Find directories for the current user
$home = File::HomeDir->my_home; # /Users/mylogin
$desktop = File::HomeDir->my_desktop; # /Users/mylogin/Desktop
$docs = File::HomeDir->my_documents; # /Users/mylogin/Documents
$music = File::HomeDir->my_music; # /Users/mylogin/Music
$pics = File::HomeDir->my_pictures; # /Users/mylogin/Pictures
$videos = File::HomeDir->my_videos; # /Users/mylogin/Movies
$data = File::HomeDir->my_data; # /Users/mylogin/Library/Application Support
=head1 TODO
=over 4
lib/File/HomeDir/Darwin/Cocoa.pm view on Meta::CPAN
{
my $class = shift;
require Mac::SystemDirectory;
my $home = Mac::SystemDirectory::HomeDirectory();
$home ||= $class->SUPER::_guess_determined_home($@);
return $home;
}
# from 10.4
sub my_desktop
{
my $class = shift;
require Mac::SystemDirectory;
eval { $class->_find_folder(Mac::SystemDirectory::NSDesktopDirectory()) }
|| $class->SUPER::my_desktop;
}
# from 10.2
sub my_documents
{
my $class = shift;
require Mac::SystemDirectory;
eval { $class->_find_folder(Mac::SystemDirectory::NSDocumentDirectory()) }
|| $class->SUPER::my_documents;
lib/File/HomeDir/Darwin/Cocoa.pm view on Meta::CPAN
Because this module requires L<Mac::SystemDirectory>, if the module
is not installed, L<File::HomeDir> will fall back to L<File::HomeDir::Darwin>.
=head1 SYNOPSIS
use File::HomeDir;
# Find directories for the current user
$home = File::HomeDir->my_home; # /Users/mylogin
$desktop = File::HomeDir->my_desktop; # /Users/mylogin/Desktop
$docs = File::HomeDir->my_documents; # /Users/mylogin/Documents
$music = File::HomeDir->my_music; # /Users/mylogin/Music
$pics = File::HomeDir->my_pictures; # /Users/mylogin/Pictures
$videos = File::HomeDir->my_videos; # /Users/mylogin/Movies
$data = File::HomeDir->my_data; # /Users/mylogin/Library/Application Support
=head1 COPYRIGHT
Copyright 2009 - 2011 Adam Kennedy.
lib/File/HomeDir/FreeDesktop.pm view on Meta::CPAN
package File::HomeDir::FreeDesktop;
# Specific functionality for unixes running free desktops
# compatible with (but not using) File-BaseDir-0.03
# See POD at the end of the file for more documentation.
use 5.008003;
use strict;
use warnings;
use Carp ();
use File::Spec ();
use File::Which ();
lib/File/HomeDir/FreeDesktop.pm view on Meta::CPAN
sub _my
{
# No quoting because input is hard-coded and only comes from this module
my $thingy = qx($xdgprog $_[1]);
chomp $thingy;
return $thingy;
}
# Simple stuff
sub my_desktop { shift->_my('DESKTOP') }
sub my_documents { shift->_my('DOCUMENTS') }
sub my_music { shift->_my('MUSIC') }
sub my_pictures { shift->_my('PICTURES') }
sub my_videos { shift->_my('VIDEOS') }
sub my_data
{
$ENV{XDG_DATA_HOME}
or File::Spec->catdir(shift->my_home, qw{ .local share });
}
lib/File/HomeDir/FreeDesktop.pm view on Meta::CPAN
sub my_cache
{
$ENV{XDG_CACHE_HOME}
|| File::Spec->catdir(shift->my_home, qw{ .cache });
}
#####################################################################
# General User Methods
sub users_desktop { Carp::croak('The users_desktop method is not available on an XDG based system.'); }
sub users_documents { Carp::croak('The users_documents method is not available on an XDG based system.'); }
sub users_music { Carp::croak('The users_music method is not available on an XDG based system.'); }
sub users_pictures { Carp::croak('The users_pictures method is not available on an XDG based system.'); }
sub users_videos { Carp::croak('The users_videos method is not available on an XDG based system.'); }
sub users_data { Carp::croak('The users_data method is not available on an XDG based system.'); }
1;
=pod
lib/File/HomeDir/FreeDesktop.pm view on Meta::CPAN
=head1 DESCRIPTION
This module provides implementations for determining common user
directories. In normal usage this module will always be
used via L<File::HomeDir>.
This module can operate only when the command C<xdg-user-dir> is available
and executable, which is typically achieved by installed a package named
C<xdg-user-dirs> or similar.
One can find the latest spec at L<https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html>.
=head1 SYNOPSIS
use File::HomeDir;
# Find directories for the current user
$home = File::HomeDir->my_home; # /home/mylogin
$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;
$config = File::HomeDir->my_config;
# Some undocumented ones, expect they don't work - use with caution
$download = File::HomeDir->my_download;
$publicshare = File::HomeDir->my_publicshare;
lib/File/HomeDir/MacOS9.pm view on Meta::CPAN
my $class = shift;
# Try for $ENV{HOME} if we have it
if (defined $ENV{HOME})
{
return $ENV{HOME};
}
### DESPERATION SETS IN
# We could use the desktop
SCOPE:
{
## no critic qw(RequireInitializationForLocalVars, RequireCheckingReturnValueOfEval)
local $@;
eval {
my $home = $class->my_desktop;
return $home if $home and -d $home;
};
}
# Desperation on any platform
SCOPE:
{
# On some platforms getpwuid dies if called at all
local $SIG{'__DIE__'} = '';
my $home = (getpwuid($<))[7];
return $home if $home and -d $home;
}
Carp::croak("Could not locate current user's home directory");
}
sub my_desktop
{
my $class = shift;
# Find the desktop via Mac::Files
local $SIG{'__DIE__'} = '';
require Mac::Files;
my $home = Mac::Files::FindFolder(Mac::Files::kOnSystemDisk(), Mac::Files::kDesktopFolderType(),);
return $home if $home and -d $home;
Carp::croak("Could not locate current user's desktop");
}
#####################################################################
# General User Methods
sub users_home
{
my ($class, $name) = @_;
SCOPE:
lib/File/HomeDir/MacOS9.pm view on Meta::CPAN
=head1 NAME
File::HomeDir::MacOS9 - Find your home and other directories on legacy Macintosh systems
=head1 SYNOPSIS
use File::HomeDir;
# Find directories for the current user
$home = File::HomeDir->my_home;
$desktop = File::HomeDir->my_desktop;
=head1 DESCRIPTION
This module provides implementations for determining common user
directories on legacy Mac hosts. In normal usage this module will always be
used via L<File::HomeDir>.
This module is no longer actively maintained, and is included only for
extreme back-compatibility.
Only the C<my_home> and C<my_desktop> methods are supported.
=head1 SUPPORT
See the support section the main L<File::HomeDir> module.
=head1 AUTHORS
Adam Kennedy E<lt>adamk@cpan.orgE<gt>
Sean M. Burke E<lt>sburke@cpan.orgE<gt>
lib/File/HomeDir/Test.pm view on Meta::CPAN
# Special magic use in test scripts
sub import
{
my $class = shift;
Carp::croak "Attempted to initialise File::HomeDir::Test trice" if %DIR;
# Fill the test directories
my $BASE = File::Temp::tempdir(CLEANUP => 1);
%DIR = map { $_ => File::Spec->catdir($BASE, $_) } qw{
my_home
my_desktop
my_documents
my_data
my_music
my_pictures
my_videos
};
# Hijack HOME to the home directory
$ENV{HOME} = $DIR{my_home}; ## no critic qw(LocalizedPunctuationVars)
lib/File/HomeDir/Test.pm view on Meta::CPAN
#####################################################################
# Current User Methods
sub my_home
{
mkdir($DIR{my_home}, oct(755)) unless -d $DIR{my_home};
return $DIR{my_home};
}
sub my_desktop
{
mkdir($DIR{my_desktop}, oct(755)) unless -d $DIR{my_desktop};
return $DIR{my_desktop};
}
sub my_documents
{
mkdir($DIR{my_documents}, oct(755)) unless -f $DIR{my_documents};
return $DIR{my_documents};
}
sub my_data
{
lib/File/HomeDir/Unix.pm view on Meta::CPAN
sub _guess_home
{
my $class = shift;
my $home = $class->_guess_env_home($@);
$home ||= $class->_guess_determined_home($@);
return $home;
}
# On unix by default, everything is under the same folder
sub my_desktop
{
shift->my_home;
}
sub my_documents
{
shift->my_home;
}
sub my_data
lib/File/HomeDir/Unix.pm view on Meta::CPAN
SCOPE:
{
my $home = (getpwnam($name))[7];
return $home if $home and -d $home;
}
return undef;
}
sub users_desktop
{
shift->users_home(@_);
}
sub users_documents
{
shift->users_home(@_);
}
sub users_data
lib/File/HomeDir/Unix.pm view on Meta::CPAN
=head1 NAME
File::HomeDir::Unix - Find your home and other directories on legacy Unix
=head1 SYNOPSIS
use File::HomeDir;
# Find directories for the current user
$home = File::HomeDir->my_home; # /home/mylogin
$desktop = File::HomeDir->my_desktop; # All of these will...
$docs = File::HomeDir->my_documents; # ...default to home...
$music = File::HomeDir->my_music; # ...directory
$pics = File::HomeDir->my_pictures; #
$videos = File::HomeDir->my_videos; #
$data = File::HomeDir->my_data; #
=head1 DESCRIPTION
This module provides implementations for determining common user
directories. In normal usage this module will always be
lib/File/HomeDir/Windows.pm view on Meta::CPAN
# Some Windows use something like $ENV{HOME}
if (exists $ENV{HOMEDRIVE} and exists $ENV{HOMEPATH} and $ENV{HOMEDRIVE} and $ENV{HOMEPATH})
{
return File::Spec->catpath($ENV{HOMEDRIVE}, $ENV{HOMEPATH}, '',);
}
return undef;
}
sub my_desktop
{
my $class = shift;
# The most correct way to find the desktop
SCOPE:
{
require Win32;
my $dir = Win32::GetFolderPath(Win32::CSIDL_DESKTOP(), CREATE);
return $dir if $dir and $class->_d($dir);
}
# MSWindows sets WINDIR, MS WinNT sets USERPROFILE.
foreach my $e ('USERPROFILE', 'WINDIR')
{
next unless $ENV{$e};
my $desktop = File::Spec->catdir($ENV{$e}, 'Desktop');
return $desktop if $desktop and $class->_d($desktop);
}
# As a last resort, try some hard-wired values
foreach my $fixed (
# The reason there are both types of slash here is because
# this set of paths has been kept from the original version
# of File::HomeDir::Win32 (before it was rewritten).
# I can only assume this is Cygwin-related stuff.
"C:\\windows\\desktop",
"C:\\win95\\desktop",
"C:/win95/desktop",
"C:/windows/desktop",
)
{
return $fixed if $class->_d($fixed);
}
return undef;
}
sub my_documents
{
lib/File/HomeDir/Windows.pm view on Meta::CPAN
=head1 NAME
File::HomeDir::Windows - Find your home and other directories on Windows
=head1 SYNOPSIS
use File::HomeDir;
# Find directories for the current user (eg. using Windows XP Professional)
$home = File::HomeDir->my_home; # C:\Documents and Settings\mylogin
$desktop = File::HomeDir->my_desktop; # C:\Documents and Settings\mylogin\Desktop
$docs = File::HomeDir->my_documents; # C:\Documents and Settings\mylogin\My Documents
$music = File::HomeDir->my_music; # C:\Documents and Settings\mylogin\My Documents\My Music
$pics = File::HomeDir->my_pictures; # C:\Documents and Settings\mylogin\My Documents\My Pictures
$videos = File::HomeDir->my_videos; # C:\Documents and Settings\mylogin\My Documents\My Video
$data = File::HomeDir->my_data; # C:\Documents and Settings\mylogin\Local Settings\Application Data
=head1 DESCRIPTION
This module provides Windows-specific implementations for determining
common user directories. In normal usage this module will always be
t/02_main.t view on Meta::CPAN
my $dir = shift or return;
return 1 if -d $dir;
return unless -l $dir;
$dir = readlink $dir or return;
return -d $dir;
}
#####################################################################
# Environment Detection and Plan
# For what scenarios can we be sure that we have desktop/documents
my $NO_GETPWUID = 0;
my $HAVEHOME = 0;
my $HAVEDESKTOP = 0;
my $HAVEMUSIC = 0;
my $HAVEPICTURES = 0;
my $HAVEVIDEOS = 0;
my $HAVEDOCUMENTS = 0;
my $HAVEOTHERS = 0;
# Various cases of things we should try to test for
t/02_main.t view on Meta::CPAN
$HAVEHOME = 0;
$HAVEDESKTOP = 0;
$HAVEMUSIC = 0;
$HAVEPICTURES = 0;
$HAVEVIDEOS = 0;
$HAVEOTHERS = 0;
}
elsif ($^O eq 'darwin')
{
# "Unixes with proper desktops" special cases
diag("\$<: $< -- \$(: $(");
if ($ENV{AUTOMATED_TESTING})
{
# Automated testers on Mac (notably BINGOS) will often have
# super stripped down testing users.
$HAVEHOME = 1;
$HAVEDESKTOP = 1;
$HAVEMUSIC = 0;
$HAVEPICTURES = 0;
$HAVEVIDEOS = 0;
t/02_main.t view on Meta::CPAN
$HAVEMUSIC = 0;
$HAVEPICTURES = 0;
$HAVEVIDEOS = 0;
$HAVEDOCUMENTS = 0;
$HAVEOTHERS = 0;
}
}
elsif ($File::HomeDir::IMPLEMENTED_BY eq 'File::HomeDir::FreeDesktop')
{
# On FreeDesktop we can't trust people to have a desktop (annoyingly)
$HAVEHOME = 1;
$HAVEDESKTOP = 0;
$HAVEMUSIC = 0;
$HAVEVIDEOS = 0;
$HAVEPICTURES = 0;
$HAVEDOCUMENTS = 0;
$HAVEOTHERS = 0;
}
else
t/02_main.t view on Meta::CPAN
#####################################################################
# Test invalid uses
eval { home(undef); };
like($@, qr{Can\'t use undef as a username}, 'home(undef)');
#####################################################################
# API Test
# Check the methods all exist
foreach (qw{ home desktop documents music pictures videos data })
{
can_ok('File::HomeDir', "my_$_");
can_ok('File::HomeDir', "users_$_");
}
#####################################################################
# Main Tests
# Find this user's homedir
my $home = home();
t/02_main.t view on Meta::CPAN
my $my_videos = File::HomeDir->my_videos;
my $my_videos2 = File::HomeDir::my_videos();
is($my_videos, $my_videos2, 'Different APIs give the same results');
ok(!!($my_videos and is_dir $my_videos), 'Our videos directory exists');
ok(!!($my_videos2 and is_dir $my_videos2), 'Our videos directory exists');
}
# Desktop cannot be assumed in all environments
SKIP:
{
skip("Cannot assume existence of desktop", 3) unless $HAVEDESKTOP;
# Find this user's desktop data
my $my_desktop = File::HomeDir->my_desktop;
my $my_desktop2 = File::HomeDir::my_desktop();
is($my_desktop, $my_desktop2, 'Different APIs give the same results');
ok(!!($my_desktop and is_dir $my_desktop), 'Our desktop directory exists');
ok(!!($my_desktop2 and is_dir $my_desktop2), 'Our desktop directory exists');
}
# Find this user's local data
SKIP:
{
skip("Cannot assume existence of application data", 3) unless $HAVEOTHERS;
my $my_data = File::HomeDir->my_data;
my $my_data2 = File::HomeDir::my_data();
is($my_data, $my_data2, 'Different APIs give the same results');
ok(!!($my_data and is_dir $my_data), 'Found our local data directory');
t/10_test.t view on Meta::CPAN
use File::HomeDir;
# Is the test driver enabled?
is($File::HomeDir::Test::ENABLED, 1, 'File::HomeDir::Test is enabled');
is($File::HomeDir::IMPLEMENTED_BY, 'File::HomeDir::Test', 'IMPLEMENTED_BY is correct');
# Was everything hijacked correctly?
foreach my $method (
qw{
my_home
my_desktop
my_documents
my_data
my_music
my_pictures
my_videos
}
)
{
my $dir = File::HomeDir->$method();
ok($dir, "$method: Got a directory");