Config::Tree - Access various configuration as a single Unix filesystem-like tree


Config-Tree documentation  | view source Contained in the Config-Tree distribution.

Index


NAME

Top

Config::Tree - Access various configuration as a single Unix filesystem-like tree

VERSION

Top

Version 0.04

SYNOPSIS

Top

 # in /etc/myapp.yaml:
 foo:
   bar: 1
 baz: 2

 # in ~/.myapp.yaml:
 foo:
   bar: 3
   quux: 4

 # in myapp.pl:
 use Config::Tree;
 my $conf = get_config();
 printf "/foo/bar = %s\n", $conf->get('/foo/bar');
 $conf->cd('/foo');
 printf "/foo/baz = %s\n", $conf->get('baz');
 printf "/quux = %s\n", $conf->get('../quux');

 # in shell:
 % perl myapp.pl --quux=5
 /foo/bar = 3
 /foo/baz = 2
 /quux = 5

 # See Config::Tree::Multi for more detailed usage. You can customize the
 # location of config files, put config in directories, arrange how values from
 # config files can be replaced/protected/reset by further files/command line
 # options, set/save config values, validate config trees using schema,
 # dynamically load ("mount") of config trees, etc.




DESCRIPTION

Top

Config::Tree (CT) lets you access your various configuration (perl data structure, config files, config dirs, environment variables, command line options, even databases) as a single tree using a Unix filesystem-like interface.

FUNCTIONS

Top

get_config([%opts])

Exportable. Return the singleton Config::Tree::Multi object. The first call to get_config() will create the object, the subsequent calls will just return the created object.

Available options:

If you want more customized behaviour (exact paths of files/dirs, whether config should be read-only or writable, etc) you can create your own Config::Tree object and then set the singleton to it using set_config(). See documentation of, e.g., Config::Tree::Multi for more details on creating custom config tree.

set_config($ct)

Set the singleton config object to $ct, which is a Config::Tree object.

COMPARISON WITH OTHER CONFIG MODULES

Top

There are already a lot of config-related modules on CPAN. Here's the main highlights of this module:

Things that are like what other modules do:

- Loading and merging config values from multiple sources (config files [YAML], config dirs, DBI databases, environment variables, command line options).

Things that are unlike what many other modules do:

- Nested (tree) config, even in command line options.

- Filesystem-like interface: cd(), pushd(), popd(), pwd(), get("../relative/path"), get("/abs/path"), mounting config trees to different mount points, etc.

- More flexible merging (merging modes). We can individually mark which config should be protected from being overriden, added/concatenated, or deleted. This is done with Data::PrefixMerge.

- Set/save config values back to storage (config files, directories, and databases).

- Validation (using Data::Schema).

SEE ALSO

Top

Among the many config-related modules on CPAN: App::Options, Getopt::Long.

Config::Tree::Multi, which is the actual class used.

Config::Tree::CmdLine for more information on generating --help message, etc.

AUTHOR

Top

Steven Haryanto, <stevenharyanto at gmail.com>

BUGS

Top

Please report any bugs or feature requests to bug-config-tree at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Config-Tree. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Config::Tree




You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Config-Tree

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Config-Tree

* CPAN Ratings

http://cpanratings.perl.org/d/Config-Tree

* Search CPAN

http://search.cpan.org/dist/Config-Tree/

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


Config-Tree documentation  | view source Contained in the Config-Tree distribution.