symkat > Config-Layered > Config::Layered

Download:
Config-Layered-0.000003.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.000003   Source  

NAME ^

Config::Layered - Layered config from files, command line, and other sources.

DESCRIPTION ^

Config::Layered aims to make it easy for programmers, operations teams and those who run the programs to have the configuration methods they prefer with one simple interface.

By default options will be taken from the program source code itself, then -- if provided -- a configuration file, and finally command-line options.

SYNOPSIS ^

By default options will be taken from the program source code itself, then merged -- if provided -- with a configuration file, then environment variables in the form of CONFIG_$OPTIONNAME and finally command-line options.

    my $config = Config::Layered->load_config(
        file         => "/etc/myapp",
        default => {
            verbose => 0,
            run             => 1,
            input           => "/tmp/to_process",
            output          => "/tmp/done_processing",
            plugins         => [ qw( process ) ] 
        },
    );

Given the above, the data structure would look like:

    {
        verbose => 0,
        run             => 1,
        input           => "/tmp/to_process",
        output          => "/tmp/done_processing",
        plugins         => [ qw( process ) ] 
    }

Provided a file, /etc/myapp.yml with the line input: /tmp/pending_process the data structure would look like:

    {
        verbose => 0,
        run             => 1,
        input           => "/tmp/pending_process",
        output          => "/tmp/done_processing",
        plugins         => [ qw( process ) ] 
    }

Provided the command line arguments --norun --verbose --output /tmp/completed_process -- in addition to the configuration file above -- the data structure would look like:

    {
        verbose         => 1,
        run             => 0,
        input           => "/tmp/pending_process",
        output          => "/tmp/completed_process",
        plugins         => [ qw( process ) ] 
    }

Provided the environment variable CONFIG_INPUT="/tmp/awaiting_process -- in addition to the configuration file above -- the data structure would look like:

    {
        verbose         => 1,
        run             => 0,
        input           => "/tmp/awaiting_process",
        output          => "/tmp/completed_process",
        plugins         => [ qw( process ) ] 
    }

METHODS ^

load_config

INCLUDED SOURCES ^

Each source provides its own documentation for source-specific options, please see the POD pages for the source you're interested in learning more about

CREATING A SOURCE ^

If you would like to create your own source to provide a configuration method, the following documents the creation of a source. You can also check Config::Layered::Source::ConfigAny for a source that is used by default.

WRITING THE SOURCE CLASS

A source requires at least two methods, new and get_config.

GLOBAL OR SOURCE ARGUMENTS?

Config::Layered will accept any constructor arguments and a source may look at $layered to check them. However, source instance specific arguments are also available. Both should be supported under the following reasoning:

Suppose that I would like to load a global file, but I would also like to merge arguments from a configuration file in my home directory. With only global arguments this isn't possible. With source-specific arguments, this is easily enabled:

    my $config = Config::Layered->get_config( 
        sources => [ 
            'ConfigAny', { file => "/etc/myapp" },
            'ConfigAny', { file => $ENV{"HOME"} . "/.myapp",
        ] ,
    );

Global arguments are useful in the context that writing out the data structure for the default use-cases and single-use sources can be tedious.

AUTHOR ^

CONTRIBUTORS ^

COPYRIGHT ^

Copyright (c) 2012 the Config::Layered "AUTHOR" and "CONTRIBUTORS" as listed above.

LICENSE ^

This library is free software and may be distributed under the same terms as perl itself.

AVAILABILITY ^

The latest version of this software is available at https://github.com/symkat/Config-Layered

syntax highlighting: