[Config-loader] Config::Loader design

Clinton Gormley clint at traveljury.com
Sat May 2 18:41:04 GMT 2009


Hiya Rob

I'm just back from holiday and have been reading the CL emails in
reverse order :)


> Config::Loader::Plugin::
> Config::Loader::Stack # Each read configuration gets pushed onto this
> Config::Loader::Read::
> Config::Loader::Read::Any (... using Config::Any)
> Config::Loader::Read::General (... using Config::General)
> 
> my $loader = Config::Loader->new
> $loader->setup_reader('Any' => { ... Any setup (name, _local suffix,
> look at $ENV, etc)... })
> $loader->setup_reader('General')
> $loader->setup_parser('Substitute') # Does C::P::ConfigLoader style
> substituting
> 
> $loader->read({ ... A hash containing default values ... })
> $loader->read( 'any:path/to/config/directory' )
> $loader->read( 'path/to/general-style.cnf' )
> $loader->read( 'general:unknown-extension.txt' )
> 
> my $config = $loader->load # Does parsing and merging

I would have approached this in a different way:

My thoughts were:

$config = Config::Loader->new({...} or [...]);

where the hash ref or array ref would allow you to specify your above
examples, but without having to call each step separately.

so, eg:
  - a scalar would represent either a filename or a dirname, the other
    settings for loading a dir or file would be the module defaults
  - a hash ref would allow you to specify particular differences from
    the default
  - an array ref would contain a list of scalars or hash refs (as above)
    which would be loaded in sequence

But actually, maybe they don't need to be exclusive at all. My method
could be used for (optional) initial setup, and your method for any
later changes.

what do you think?

clint


> 
> The idea with the above being that Config::Loader as-is is just an
> API. Projects can define the MyApplication::Config package which
> provides a customized loader.
> Config::Loader::Simple is a pre-packaged Config::Loader that works out
> of the box.
> 
> Configuration loading goes through the following:
> 
> $config->load
>      1.  The read phase # Using ::Any, ::General, etc.
>      2. The merge phase # Each read config can be given a weight when
>         it is pushed on the stack. The default weight is 0
>      3. The parse/filter phase # C::P::ConfigLoader-style substitution
> Finally, return a collapsed hash back to the user which is the result
> of 1, 2, and 3
> 
> 
> Rob
> 
> _______________________________________________
> Config-loader mailing list
> Config-loader at lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/config-loader




More information about the Config-loader mailing list