Johan Lindström > File-Corresponding > File::Corresponding::Config::Find

Download:
File-Corresponding-0.003.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Source  

NAME ^

File::Corresponding::Config::Find -- Locate config files (e.g. per user)

SYNOPSIS ^

  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;

DESCRIPTION ^

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.

COMMENT ^

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.

D'oh!

But now it's written, and it works, so it stays.

ATTRIBUTES ^

preferred_dirs : ArrayRef[Path::Class]

METHODS ^

user_config($config_file_name, $preferred_dirs = []) : Path::Class::File $found_file_name | undef

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.

syntax highlighting: