Skip to content

Add my_config() to Darwin drivers#10

Open
mjgardner wants to merge 1 commit intoperl5-utils:masterfrom
mjgardner:darwin-my-config
Open

Add my_config() to Darwin drivers#10
mjgardner wants to merge 1 commit intoperl5-utils:masterfrom
mjgardner:darwin-my-config

Conversation

@mjgardner
Copy link
Copy Markdown

Problem

On macOS, my_dist_config() falls back to my_documents() because neither File::HomeDir::Darwin nor File::HomeDir::Darwin::Cocoa implements my_config(). From my_dist_config():

my $config =
    $IMPLEMENTED_BY->can('my_config')
  ? $IMPLEMENTED_BY->my_config
  : $IMPLEMENTED_BY->my_documents;

my_documents() returns ~/Documents, which on corporate machines may be redirected to OneDrive or other cloud sync locations. This makes my_dist_config() unreliable for its intended purpose on macOS.

The FreeDesktop driver already implements my_config() (returning $XDG_CONFIG_HOME), so Linux/BSD work correctly.

Solution

Add my_config() to the Darwin drivers, returning ~/Library/Application Support — the same path as my_data().

This is Apple's recommended location for application configuration and data. ~/Library/Preferences is reserved for CFPreferences/NSUserDefaults plists and isn't suitable for arbitrary config files (YAML, JSON, INI, etc.).

Changes

  • File::HomeDir::Darwin — add my_config() (pure Perl)
  • File::HomeDir::Darwin::Cocoa — add my_config() (via NSApplicationSupportDirectory)
  • File::HomeDir — add my_config() dispatcher method and export
  • t/11_darwin.t — add test for my_config()
  • t/13_darwin_cocoa.t — add test for my_config()

All existing tests continue to pass (97 total on macOS, up from 95).

On macOS, ~/Library/Application Support is Apple's recommended location
for both application configuration and data files. ~/Library/Preferences
is reserved for CFPreferences/NSUserDefaults plists and is not suitable
for arbitrary config files.

Without my_config(), my_dist_config() falls back to my_documents(),
which can resolve to unexpected locations (e.g., OneDrive-redirected
~/Documents on corporate machines). This makes my_dist_config()
unreliable on macOS for its intended purpose.

Changes:
- Add my_config() to File::HomeDir::Darwin (pure Perl fallback)
- Add my_config() to File::HomeDir::Darwin::Cocoa (Cocoa API)
- Add my_config() dispatcher to File::HomeDir
- Add my_config to @EXPORT_OK
- Add tests for my_config in t/11_darwin.t and t/13_darwin_cocoa.t

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant