And only one patch attached....
From 3b63ed7034347c63be9cfae3ad7ca46976df1fd9 Mon Sep 17 00:00:00 2001
From: Ioan Rogers <ioanr@cpan.org>
Date: Thu, 19 Apr 2012 18:44:21 -0700
Subject: [PATCH 1/2] Support my_config, my_cache, my_download, my_publicshare
on MacOSX and the top-level
---
lib/File/HomeDir.pm | 77 ++++++++++++++++++++++++++++++++++++++
lib/File/HomeDir/Darwin.pm | 38 +++++++++++++++----
lib/File/HomeDir/Darwin/Cocoa.pm | 60 +++++++++++++++++++++++++----
3 files changed, 161 insertions(+), 14 deletions(-)
diff --git a/lib/File/HomeDir.pm b/lib/File/HomeDir.pm
index 232788f..498fa24 100644
--- a/lib/File/HomeDir.pm
+++ b/lib/File/HomeDir.pm
@@ -21,10 +21,14 @@ BEGIN {
@EXPORT_OK = qw{
home
my_home
+ my_cache
+ my_config
my_desktop
my_documents
+ my_download
my_music
my_pictures
+ my_publicshare
my_videos
my_data
my_dist_config
@@ -93,6 +97,18 @@ sub my_home {
$IMPLEMENTED_BY->my_home;
}
+sub my_cache {
+ $IMPLEMENTED_BY->can('my_cache')
+ ? $IMPLEMENTED_BY->my_cache
+ : Carp::croak("The my_cache method is not implemented on this platform");
+}
+
+sub my_config {
+ $IMPLEMENTED_BY->can('my_config')
+ ? $IMPLEMENTED_BY->my_config
+ : Carp::croak("The my_config method is not implemented on this platform");
+}
+
sub my_desktop {
$IMPLEMENTED_BY->can('my_desktop')
? $IMPLEMENTED_BY->my_desktop
@@ -105,6 +121,12 @@ sub my_documents {
: Carp::croak("The my_documents method is not implemented on this platform");
}
+sub my_download {
+ $IMPLEMENTED_BY->can('my_download')
+ ? $IMPLEMENTED_BY->my_download
+ : Carp::croak("The my_download method is not implemented on this platform");
+}
+
sub my_music {
$IMPLEMENTED_BY->can('my_music')
? $IMPLEMENTED_BY->my_music
@@ -117,6 +139,12 @@ sub my_pictures {
: Carp::croak("The my_pictures method is not implemented on this platform");
}
+sub my_publicshare {
+ $IMPLEMENTED_BY->can('my_publicshare')
+ ? $IMPLEMENTED_BY->my_publicshare
+ : Carp::croak("The my_publicshare method is not implemented on this platform");
+}
+
sub my_videos {
$IMPLEMENTED_BY->can('my_videos')
? $IMPLEMENTED_BY->my_videos
@@ -337,10 +365,14 @@ File::HomeDir - Find your home and other directories on any platform
# Modern Interface (Current User)
$home = File::HomeDir->my_home;
+ $cache = File::HomeDir->my_cache;
+ $conf = File::HomeDir->my_config;
$desktop = File::HomeDir->my_desktop;
$docs = File::HomeDir->my_documents;
+ $download = File::HomeDir->my_download;
$music = File::HomeDir->my_music;
$pics = File::HomeDir->my_pictures;
+ $share = File::HomeDir->my_publicshare;
$videos = File::HomeDir->my_videos;
$data = File::HomeDir->my_data;
$dist = File::HomeDir->my_dist_data('File-HomeDir');
@@ -441,6 +473,31 @@ 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_cache
+
+The C<my_cache> method takes no arguments and returns the "cache"
+directory for the current user.
+
+This is the location of discardable/non-essential files.
+
+The C<my_cache> method may or may not be implemented on each platform.
+
+Returns the directory path as a string, C<undef> if the path does not exist for
+the current user, or dies on error.
+
+=head2 my_config
+
+The C<my_config> method takes no arguments and returns the "config"
+directory for the current user.
+
+This is the location where configuration files are stored and may be the same
+as returned by C<my_data>.
+
+The C<my_config> method may or may not be implemented on each platform.
+
+Returns the directory path as a string, C<undef> if the path does not exist for
+the current user, or dies on error.
+
=head2 my_desktop
The C<my_desktop> method takes no arguments and returns the "desktop"
@@ -467,6 +524,16 @@ 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_download
+
+The C<my_download> method takes no arguments and returns the "download"
+directory for the current user.
+
+The C<my_download> method may or may not be implemented on each platform.
+
+Returns the directory path as a string, C<undef> if the path does not exist for
+the current user, or dies on error.
+
=head2 my_music
The C<my_music> method takes no arguments and returns the directory
@@ -491,6 +558,16 @@ 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_publicshare
+
+The C<my_publicshare> method takes no arguments and returns the "Public shared"
+directory for the current user.
+
+The C<my_publicshare> method may or may not be implemented on each platform.
+
+Returns the directory path as a string, C<undef> if the path does not exist for
+the current user, or dies on error.
+
=head2 my_videos
The C<my_videos> method takes no arguments and returns the directory
diff --git a/lib/File/HomeDir/Darwin.pm b/lib/File/HomeDir/Darwin.pm
index c44e64f..95d3194 100644
--- a/lib/File/HomeDir/Darwin.pm
+++ b/lib/File/HomeDir/Darwin.pm
@@ -48,6 +48,16 @@ sub _my_home {
return Cwd::abs_path($folder);
}
+sub my_cache {
+ my $class = shift;
+ $class->_my_home('Library/Caches');
+}
+
+sub my_config {
+ my $class = shift;
+ $class->my_data;
+}
+
sub my_desktop {
my $class = shift;
$class->_my_home('Desktop');
@@ -58,6 +68,11 @@ sub my_documents {
$class->_my_home('Documents');
}
+sub my_download {
+ my $class = shift;
+ $class->_my_home('Downloads');
+}
+
sub my_data {
my $class = shift;
$class->_my_home('Library/Application Support');
@@ -73,6 +88,11 @@ sub my_pictures {
$class->_my_home('Pictures');
}
+sub my_publicshare {
+ my $class = shift;
+ $class->_my_home('Public');
+}
+
sub my_videos {
my $class = shift;
$class->_my_home('Movies');
@@ -141,12 +161,16 @@ always be used via L<File::HomeDir>.
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
+ $home = File::HomeDir->my_home; # /Users/mylogin
+ $cache = File::HomeDir->my_cache; # /Users/mylogin/Library/Caches
+ $config = File::HomeDir->my_config; # /Users/mylogin/Library/Application Support
+ $desktop = File::HomeDir->my_desktop; # /Users/mylogin/Desktop
+ $docs = File::HomeDir->my_documents; # /Users/mylogin/Documents
+ $dl = File::HomeDir->my_download; # /Users/mylogin/Downloads
+ $music = File::HomeDir->my_music; # /Users/mylogin/Music
+ $pics = File::HomeDir->my_pictures; # /Users/mylogin/Pictures
+ $public = File::HomeDir->my_publicshare; # /Users/mylogin/Public
+ $videos = File::HomeDir->my_videos; # /Users/mylogin/Movies
+ $data = File::HomeDir->my_data; # /Users/mylogin/Library/Application Support
=cut
diff --git a/lib/File/HomeDir/Darwin/Cocoa.pm b/lib/File/HomeDir/Darwin/Cocoa.pm
index d1f15e4..c8ae3c7 100644
--- a/lib/File/HomeDir/Darwin/Cocoa.pm
+++ b/lib/File/HomeDir/Darwin/Cocoa.pm
@@ -39,6 +39,24 @@ sub my_home {
}
# from 10.4
+sub my_cache {
+ my $class = shift;
+
+ require Mac::SystemDirectory;
+ eval {
+ $class->_find_folder(Mac::SystemDirectory::NSCachesDirectory())
+ }
+ ||
+ $class->SUPER::my_cache;
+}
+
+# same as my_data
+sub my_config {
+ my $class = shift;
+ $class->my_data;
+}
+
+# from 10.4
sub my_desktop {
my $class = shift;
@@ -74,6 +92,18 @@ sub my_data {
$class->SUPER::my_data;
}
+# from 10.5
+sub my_download {
+ my $class = shift;
+
+ require Mac::SystemDirectory;
+ eval {
+ $class->_find_folder(Mac::System Directory::NSDownloadsDirectory())
+ }
+ ||
+ $class->SUPER::my_download;
+}
+
# from 10.6
sub my_music {
my $class = shift;
@@ -99,6 +129,18 @@ sub my_pictures {
}
# from 10.6
+sub my_publicshare {
+ my $class = shift;
+
+ require Mac::SystemDirectory;
+ eval {
+ $class->_find_folder(Mac::SystemDirectory::NSPublicDirectory())
+ }
+ ||
+ $class->SUPER::my_publicshare;
+}
+
+# from 10.6
sub my_videos {
my $class = shift;
@@ -154,12 +196,16 @@ is not installed, L<File::HomeDir> will fall back to L<File::HomeDir::Darwin>.
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
+ $home = File::HomeDir->my_home; # /Users/mylogin
+ $cache = File::HomeDir->my_cache; # /Users/mylogin/Library/Caches
+ $config = File::HomeDir->my_config; # /Users/mylogin/Library/Application Support
+ $desktop = File::HomeDir->my_desktop; # /Users/mylogin/Desktop
+ $docs = File::HomeDir->my_documents; # /Users/mylogin/Documents
+ $dl = File::HomeDir->my_download; # /Users/mylogin/Downloads
+ $music = File::HomeDir->my_music; # /Users/mylogin/Music
+ $pics = File::HomeDir->my_pictures; # /Users/mylogin/Pictures
+ $public = File::HomeDir->my_publicshare; # /Users/mylogin/Public
+ $videos = File::HomeDir->my_videos; # /Users/mylogin/Movies
+ $data = File::HomeDir->my_data; # /Users/mylogin/Library/Application Support
=cut
--
1.7.10