Config Loader

Recent site activity

Proposed interface

You need to read Proposed functionality before considering this page.

The intention is to:
  • be able to use Config::Loader in default mode with minimal code, and have it do the sane thing
  • be flexible enough to turn Config::Loader to your needs / style
So for instance, you could do:
  • my $c = Config::Loader->new($file);
  • my $c = Config::Loader->new($dir);
  • my $c = Config::Loader->new($file,$dir,$dir,$file); 
  • my $c = Config::Loader->new([$file,$dir,$dir,$file]);
I don't think $file or $dir is always going to be enough information for Config::Loader to act. I would consider a DBI-style DSN or something so that Config::Loader knows the config type, etc.

For example:

    Config::Loader->new( "/path/to/some/config/file" )

How is Config::Loader supposed to know how to load that file? Is it Config::General, JSON, YAML? A CSN would be something like this:

    Config::Loader->new( "config-general:/path/to/some/config/file")

If the file has a reasonable extension, .cnf, .conf, .yml, .yaml, etc. I think Config::Loader should be able to guess it. But the scheme given at the head of the CSN should override it. If it can't guess, then it's a fatal error.

A list or array ref containing scalars would load each dir (recursively) or file  and merge them into a single hash, with the path name (including directory names and file name) as the insertion point into a hash, as Config::Merge does now.

If you wanted to override default behaviour, you would pass in a hash ref.

    my $c = Config::Loader->new({
        add_loaders => { 'conf'    => 'Config::Loader::YAML' },
        load_level  => 'top',
        sources     => [ $file_1, $file_2 ]
    });

Default options could be specified at the top level, but could be overriden with more specific parameters below that (javascript prototype style) :

    my $c = Config::Loader->new({
        add_loaders => { 'conf'    => 'Config::Loader::YAML' },
        load_level  => 'top',
        sources     => [
            $file_1,
            {
                load_level   => 'file',
                source       => $file_2
                post_process => \&code_ref,
            }
        ]
    });

If we consider multiple CSNs as above, they could issue either as strings, or as hashes:

    Config::Loader->new([
        "config-general:/path/to/some/config/file",
        {
            type => 'YAML',         
            file => '/some/other/file',

            precedence => -1,
        },
        ...
    ])

Detailed interface discussion: