Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/File/HomeDir.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ BEGIN
my_pictures
my_videos
my_data
my_config
my_dist_config
my_dist_data
users_home
Expand Down Expand Up @@ -153,6 +154,13 @@ sub my_data
: Carp::croak("The my_data 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_dist_data
{
my $params = ref $_[-1] eq 'HASH' ? pop : {};
Expand Down
7 changes: 7 additions & 0 deletions lib/File/HomeDir/Darwin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ sub my_data
$class->_my_home('Library/Application Support');
}

sub my_config
{
my $class = shift;
$class->_my_home('Library/Application Support');
}

sub my_music
{
my $class = shift;
Expand Down Expand Up @@ -142,6 +148,7 @@ always be used via L<File::HomeDir>.
$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
$config = File::HomeDir->my_config; # /Users/mylogin/Library/Application Support

=head1 COPYRIGHT

Expand Down
12 changes: 12 additions & 0 deletions lib/File/HomeDir/Darwin/Cocoa.pm
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ sub my_data
|| $class->SUPER::my_data;
}

# Apple recommends ~/Library/Application Support for both config and data.
# ~/Library/Preferences is reserved for CFPreferences/NSUserDefaults plists.
sub my_config
{
my $class = shift;

require Mac::SystemDirectory;
eval { $class->_find_folder(Mac::SystemDirectory::NSApplicationSupportDirectory()) }
|| $class->SUPER::my_config;
}

# from 10.6
sub my_music
{
Expand Down Expand Up @@ -147,6 +158,7 @@ is not installed, L<File::HomeDir> will fall back to L<File::HomeDir::Darwin>.
$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
$config = File::HomeDir->my_config; # /Users/mylogin/Library/Application Support

=head1 COPYRIGHT

Expand Down
10 changes: 9 additions & 1 deletion t/11_darwin.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if ($File::HomeDir::IMPLEMENTED_BY->isa('File::HomeDir::Darwin'))
{
# Force pure perl since it should work everywhere
$File::HomeDir::IMPLEMENTED_BY = 'File::HomeDir::Darwin';
plan(tests => 9);
plan(tests => 10);
}
else
{
Expand Down Expand Up @@ -87,4 +87,12 @@ SCOPE:
skip("Have data directory", 1) if defined $data;
is_deeply([File::HomeDir->my_data], [undef], "Returns undef in list context",);
}

SKIP:
{
my $config = File::HomeDir->my_config;
skip("No config directory", 1) unless defined $config;
like($config, qr/Application Support/,
'my_config returns ~/Library/Application Support on macOS');
}
}
10 changes: 9 additions & 1 deletion t/13_darwin_cocoa.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if ($File::HomeDir::IMPLEMENTED_BY->isa('File::HomeDir::Darwin')
# Force Cocoa if you have Mac::SystemDirectory
require File::HomeDir::Darwin::Cocoa;
$File::HomeDir::IMPLEMENTED_BY = 'File::HomeDir::Darwin::Cocoa';
plan(tests => 5);
plan(tests => 6);
}
else
{
Expand Down Expand Up @@ -70,4 +70,12 @@ SCOPE:
skip("No application support directory", 1) unless defined $data;
like($data, qr/Application Support/);
}

SKIP:
{
my $config = File::HomeDir->my_config;
skip("No config directory", 1) unless defined $config;
like($config, qr/Application Support/,
'my_config returns ~/Library/Application Support on macOS');
}
}