File::Corresponding::Config::Find -- Locate config files (e.g. per user)
use File::Corresponding::Config::Find; my $my_config = ".myapp"; #Find .myapp in any of the user's home directories my $myapp_config_in_home = File::Corresponding::Config::Find->new()->user_config($my_config) or die; #Find .myapp in the current working directory, or in the user's home directory use Path::Class qw/ dir /; my $myapp_config_in_cwd_or_home = File::Corresponding::Config::Find->new(preferred_dirs => [ dir(".") ])->user_config($my_config) or die;
Locate named config files in the usual places, e.g. the current dir, the user's home directory (cross platform).
First the preferred_dirs are searched, then the user's document directory, data directory, and home directory.
I searched for something like this, couldn't find anything.
So I wrote this module, and named it Config::Find. Which is a name already taken by a CPAN module.
But now it's written, and it works, so it stays.
Find an existing readable file called $config_file_name (e.g. ".myapp") in a) $preferred_dirs, or b) the usual user directories ($HOME etc).
Return the complete file name to the config file, or undef if none was found.