NAME
Config::YAML::Modern - Modern YAML-based config loader from file or directory.
VERSION
Version 0.36
SYNOPSIS
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}
SUBROUTINES/METHODS
new
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.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.key_conversion
Rule for conversion parts of filename to hash keys.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'.__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'.!!! 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:- 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
load_file($filename) - load data from yaml-contained file
$config->load_file($filename);
load_dir
load_dir($directory) - get files from directory (non-recursive), load data and merge it together
$config2->load_dir($directory);
add_hash
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
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
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
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
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
config() - return all config data from object
my $data = $config->config();
DEPRECATED METHODS
The old module interface is still available, but its use is discouraged. It will eventually be removed from the module.
file_load
file_load($filename) - load data from yaml-contained file
$config->file_load($filename);
dir_load
dir_load($directory) - get files from directory, load data and merge it together
$config2->dir_load($directory);
hash_add
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' );
Just wrapper ontop of "merge" in Hash::Merge
file_add
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' );
dir_add
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' );
EXPORT
Nothing by default.
AUTHOR
Meettya, <meettya at cpan.org>
BUGS
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.
DEVELOPMENT
Repository
https://github.com/Meettya/Config-YAML-Modern
SUPPORT
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)
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
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.