Nour::Config
version 0.10
Recursively consumes YAML configuration from the config directory into a hash ref for use in your application.
YAML
config
conf
cfg
you@your_computer:~/code/your_app $ mkdir config you@your_computer:~/code/your_app $ mkdir config/application you@your_computer:~/code/your_app $ mkdir config/database you@your_computer:~/code/your_app $ mkdir config/database/private you@your_computer:~/code/your_app $ mkdir -p config/a/deeply/nested/example
you@your_computer:~/code/your_app $ echo '---' > config/config.yml you@your_computer:~/code/your_app $ echo '---' > config/application/config.yml you@your_computer:~/code/your_app $ echo '---' > config/database/config.yml you@your_computer:~/code/your_app $ echo '---' > config/database/private/config.yml you@your_computer:~/code/your_app $ echo '---' > config/a/deeply/nested/example/neato.yml
use Nour::Config; use Data::Dumper; use feature ':5.10';
then
# automatically detects and reads from a config, conf, or cfg directory my $config = new Nour::Config;
or
my $config = new Nour::Config ( -base => 'config/application' );
my $config = new Nour::Config ( -conf => { hash_key => 'override' } , -base => 'config' );
my $config = new Nour::Config ( this_becomes_a_hash_key => 'config/database' );
finally
say 'cfg', Dumper $config->config; say 'app', Dumper $config->config( 'application' ); say 'db', Dumper $config->config->{database};
But it's even better with Moose if you import the config handle, so you can use config as a handle in your script or application:
use Moose; use Nour::Config; use Data::Dumper; has _config => ( is => 'rw' , isa => 'Nour::Config' , handles => [ qw/config/ ] , required => 1 , lazy => 1 , default => sub { return new Nour::Config ( -base => 'config' ); } ); sub BUILD { my $self = shift; print "\nhello world\n", Dumper( $self->config ), "\n"; }
Returns the configuration accessor, and doubles as a hash ref.
print "\n", Dumper( $self->config( 'application' ) ), "\n"; print "\n", Dumper( $self->config->{application} ), "\n";
Nour Sharabash <amirite@cpan.org>
This software is copyright (c) 2014 by Nour Sharabash.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Nour, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Nour
CPAN shell
perl -MCPAN -e shell install Nour
For more information on module installation, please visit the detailed CPAN module installation guide.