App-Rad-Plugin-ConfigLoader
view release on metacpan or search on metacpan
lib/App/Rad/Plugin/ConfigLoader.pm view on Meta::CPAN
package App::Rad::Plugin::ConfigLoader;
use strict;
use warnings;
use Config::Any;
our $VERSION = '0.01';
sub load_config {
my ($c, @filepaths) = (@_);
my $cfg = Config::Any->load_files({
'files' => \@filepaths,
'use_ext' => 1
});
foreach ( @{$cfg} ) {
my ($filename, $config) = %{$_};
$c->debug("loaded configuration from file '$filename'.");
# I could just fiddle with the internals to make this
# a little quicker, but let's stick to the API :)
foreach my $key (keys %{$config}) {
$c->config->{$key} = $config->{$key};
}
}
}
42;
__END__
=head1 NAME
App::Rad::Plugin::ConfigLoader - Load config files of various types
=head1 VERSION
Version 0.01
=head1 SYNOPSIS
use App::Rad qw(ConfigLoader);
That's it. Now you can use the usual C<< $c->load_config() >> method to load your application's configuration file in any format supported by Config::Any (Apache-like, JSON, YAML, XML, Windows INI, etc).
$c->load_config('somefile.yml');
Then just access its items through the regular C<< $c->config >> hash.
=head1 DESCRIPTION
Although C<< App::Rad >>'s standard C<< $c->load_config() >> method intends to be intuitive and somewhat flexible for simple configuration files, you may need something more sofisticated or standardized for your applications.
This module extends L<App::Rad>'s functionality by letting you use C<< Config::Any >> to load configuration files of various types transparently.
Please refer to L<Config::Any> for more information on acepted file formats.
=head2 Loading configuration files
This plugin overrides C<< App::Rad >>'s standard C<< $c->load_config >> methodto support different file formats according to their file extension while providing the same syntax.
=head3 $c->load_config( FILE [,FILE2, FILE3, ...] )
Different files can have different extensions and they all should load transparently in order to be accessed via C<< $c->config >>.
=head1 AUTHOR
Breno G. de Oliveira, C<< <garu at cpan.org> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-app-rad-plugin-configloader at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-Rad-Plugin-ConfigLoader>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc App::Rad::Plugin::ConfigLoader
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=App-Rad-Plugin-ConfigLoader>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/App-Rad-Plugin-ConfigLoader>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/App-Rad-Plugin-ConfigLoader>
=item * Search CPAN
L<http://search.cpan.org/dist/App-Rad-Plugin-ConfigLoader/>
=back
=head1 ACKNOWLEDGEMENTS
Many thanks to Joel Bernstein, Brian Cassidy and everyone who helped in the Config::Any module.
=head1 SEE ALSO
L<App::Rad>, L<Config::Any>.
=head1 COPYRIGHT & LICENSE
Copyright 2009 Breno G. de Oliveira, all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself. See L<perlartistic>.
( run in 2.676 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )