Config::YAML::Modern - Modern YAML-based config loader from file or directory.
Version 0.36
Config::YAML::Modern created to get dial with yaml-based configuration.
Its possible to load single file, or all files in one directory (without recursion search).
Data from many files was be merged properly (almost), also filename was be converted to top-level hash keys.
Filename like 'file.data.yaml' was be converted to { file => { data => $file_content } }.
Also module provide perfect dive() interface form Data::Diver.
It may be used like
my $file_content = $conf_object->dive(qw/file data/);
Simply usage for file load
use Config::YAML::Modern; my $config = Config::YAML::Modern->new(); my $filename = 'test.yaml'; $config->load_file($filename); my $data = $config->config();
More complicated for directory-based loading
my $config2 = Config::YAML::Modern->new( key_conversion => 'ucfirst' ); my $directory = '/etc/my_app/'; # slurp all data to hashref my $data2 = $config2->load_dir($directory)->config(); # but exist more sophisticated path my @list_of_key = (qw/Model Message 0 author/); my $data3 = $config2->dive(@list_of_key); # $data3 == $data2->{Model}{Message}[0]{author}
new( [ list of args ] ) - create Config::YAML::Modern object and return it.
my $config = Config::YAML::Modern->new();
The options currently supported are:
merge_behavior behavior on merge data, see Hash::Merge docs.
merge_behavior
Available values are [LEFT_PRECEDENT, RIGHT_PRECEDENT, STORAGE_PRECEDENT, RETAINMENT_PRECEDENT], 'LEFT_PRECEDENT' by default.
file_suffix File suffix, used in search files in directory for matching. '.yaml' by default.
file_suffix
key_conversion Rule for conversion parts of filename to hash keys.
key_conversion
Available values are [undef, uc, ucfirst, lc, lcfirst]. No conversion - 'undef' by default.
i_dont_use_suffix Set to true if you not use suffix on config files. Suffix is used by default - 'undef'.
i_dont_use_suffix
__force_return_data If setted to true, methods: load_file(), load_dir(), add_hash(), add_file() and add_dir() returns dataset instead of $self, returned by default - 'undef'.
__force_return_data
!!! important - in this case loaded or added data are NOT BE STORED in object, use it well
ignore_empty_file If setted to true method:
ignore_empty_file
- load_file() will return or assign to object empty flat hash without created keys by file name - just {}. - load_dir() will ignore empty files and not been add keys by names of empty files at all - add_file() and add_dir() will ignore empty files and not use it in merge process
By default empty files NOT ignored, value by default - 'undef'.
load_file($filename) - load data from yaml-contained file
$config->load_file($filename);
load_dir($directory) - get files from directory (non-recursive), load data and merge it together
$config2->load_dir($directory);
add_hash($hash_ref, $behavior? ) - add data to object from hash with $behavior resolution, or use default behavior.
my $data3 = $config2->add_hash( $hash_ref, 'RIGHT_PRECEDENT' );
Just wrapper ontop of "merge" in Hash::Merge
add_file($filename, $behavior? ) - add data to object from file with $behavior resolution, or use default behavior.
my $data3 = $config2->add_file( $filename3, 'RIGHT_PRECEDENT' );
add_dir($dir_name, $behavior? ) - add data to object from directory with $behavior resolution, or use default behavior.
my $data3 = $config2->add_dir( $dir_name2, 'RETAINMENT_PRECEDENT' );
dive(@list_of_key) - return data from object by @list_of_key patch resolution, return "undef" if path resolution wrong.
my $data3 = $config2->dive(@list_of_key);
Just wrapper ontop of "Dive" in Data::Diver
dive_die(@list_of_key) - return data from object by @list_of_key patch resolution, and do "die" if path resolution wrong.
my $data3 = $config2->dive_die(@list_of_key);
Just wrapper ontop of "DiveDie" in Data::Diver
config() - return all config data from object
my $data = $config->config();
The old module interface is still available, but its use is discouraged. It will eventually be removed from the module.
file_load($filename) - load data from yaml-contained file
$config->file_load($filename);
dir_load($directory) - get files from directory, load data and merge it together
$config2->dir_load($directory);
hash_add($hash_ref, $behavior? ) - add data to object from hash with $behavior resolution, or use default behavior.
my $data3 = $config2->hash_add( $hash_ref, 'RIGHT_PRECEDENT' );
file_add($filename, $behavior? ) - add data to object from file with $behavior resolution, or use default behavior.
my $data3 = $config2->file_add( $filename3, 'RIGHT_PRECEDENT' );
file_add($dir_name, $behavior? ) - add data to object from directory with $behavior resolution, or use default behavior.
my $data3 = $config2->dir_add( $dir_name2, 'RETAINMENT_PRECEDENT' );
Nothing by default.
Meettya, <meettya at cpan.org>
<meettya at cpan.org>
Please report any bugs or feature requests to bug-config-yaml-modern at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Config-YAML-Modern. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-config-yaml-modern at rt.cpan.org
https://github.com/Meettya/Config-YAML-Modern
You can find documentation for this module with the perldoc command.
perldoc Config::YAML::Modern
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Config-YAML-Modern
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Config-YAML-Modern
CPAN Ratings
http://cpanratings.perl.org/d/Config-YAML-Modern
Search CPAN
http://search.cpan.org/dist/Config-YAML-Modern/
Copyright 2011 Meettya.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Config::YAML::Modern, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Config::YAML::Modern
CPAN shell
perl -MCPAN -e shell install Config::YAML::Modern
For more information on module installation, please visit the detailed CPAN module installation guide.