Skip Menu |

This queue is for tickets about the File-HomeDir CPAN distribution.

Report information
The Basics
Id: 76717
Status: rejected
Priority: 0/
Queue: File-HomeDir

People
Owner: Nobody in particular
Requestors: ioanr [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Patch for my_config, my_cache, my_download, my_publicshare
 Hi,

I saw the docs said to just go ahead and commit changes, but this seemed like a lot of changes to just come out of the blue.

This patch adds subs for my_config, my_cache, my_download and my_publicshare to the top level, which previously existed in the FreeDesktop driver only. I've also added them to Darwin and Cocoa.

On MacOSX it seems my_config and my_data are the same, so it's just passed through.

Tests pass on linux and mac snow leopard.

Thanks!
Subject: 0002-Test-new-additions.patch
From 0eec50337e2d99e8c3e5e2b27fcb2419268ad0f3 Mon Sep 17 00:00:00 2001 From: Ioan Rogers <ioanr@cpan.org> Date: Thu, 19 Apr 2012 20:28:16 -0700 Subject: [PATCH 2/2] Test new additions --- t/02_main.t | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/t/02_main.t b/t/02_main.t index df74a77..3251ea7 100644 --- a/t/02_main.t +++ b/t/02_main.t @@ -128,7 +128,7 @@ if ( $^O eq 'MSWin32' ) { $HAVEOTHERS = 1; } -plan tests => 39; +plan tests => 51; @@ -249,6 +249,46 @@ SKIP: { ok( !!($my_desktop2 and is_dir $my_desktop2), 'Our desktop directory exists' ); } +# Find this user's cache +SKIP: { + skip("Cannot assume existance of cache", 3 ) unless $HAVEOTHERS; + my $my_cache = File::HomeDir->my_cache; + my $my_cache2 = File::HomeDir::my_cache(); + is( $my_cache, $my_cache2, 'Different APIs give the same results' ); + ok( !!($my_cache and is_dir $my_cache), 'Our cache directory exists' ); + ok( !!($my_cache2 and is_dir $my_cache2), 'Our cache directory exists' ); +} + +# Find this user's download dir +SKIP: { + skip("Cannot assume existance of download dir", 3 ) unless $HAVEOTHERS; + my $my_dl = File::HomeDir->my_download; + my $my_dl2 = File::HomeDir::my_download(); + is( $my_dl, $my_dl2, 'Different APIs give the same results' ); + ok( !!($my_dl and is_dir $my_dl), 'Our download directory exists' ); + ok( !!($my_dl2 and is_dir $my_dl2), 'Our download directory exists' ); +} + +# Find this user's public share dir +SKIP: { + skip("Cannot assume existance of public share dir", 3 ) unless $HAVEOTHERS; + my $my_pbs = File::HomeDir->my_publicshare; + my $my_pbs2 = File::HomeDir::my_publicshare(); + is( $my_pbs, $my_pbs2, 'Different APIs give the same results' ); + ok( !!($my_pbs and is_dir $my_pbs), 'Our public share directory exists' ); + ok( !!($my_pbs2 and is_dir $my_pbs2), 'Our public share directory exists' ); +} + +# Find this user's config dir +SKIP: { + skip("Cannot assume existance of config dir", 3 ) unless $HAVEOTHERS; + my $my_config = File::HomeDir->my_config; + my $my_config2 = File::HomeDir::my_config(); + is( $my_config, $my_config2, 'Different APIs give the same results' ); + ok( !!($my_config and is_dir $my_config), 'Our config directory exists' ); + ok( !!($my_config2 and is_dir $my_config2), 'Our config directory exists' ); +} + # Find this user's local data SKIP: { skip("Cannot assume existance of application data", 3) unless $HAVEOTHERS; -- 1.7.10
 And only one patch attached....
Subject: 0001-Support-my_config-my_cache-my_download-my_publicshar.patch
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
Oh my ... this is long ago. Would be cool when you do a pull-request.
On Fri, 9 Mar 2018 19:18:17 GMT, REHSACK wrote:
Show quoted text
> Oh my ... this is long ago.
>
> Would be cool when you do a pull-request.

Yikes, I has forgotten all about that.

I've rebased and made the pull request: https://github.com/perl5-utils/File-HomeDir/pull/5

It would be not that difficult to provide a reasonable default implementation for win32 and linux. Still missing.