NAME
CGI::Application::Plugin::ConfigAny - Add Config::Any Support to CGI::Application
VERSION
Version 0.01
SYNOPSIS
In your CGI::Application-based module:
use base 'CGI::Application';
use CGI::Application::Plugin::ConfigAny;
sub cgiapp_init {
my $self = shift;
# Set config file and other options
$self->config->init(
configdir => '/path/to/configfiles',
files => [ 'app.conf' ],
name => 'main',
params => {
## passed to Config::Any->load_files;
## see Config::Any for valid params
}
);
}
Later...
## get a complete config section as a hashref
$self->config->section( 'sectionname' );
## get a single config param
$self->config->param( 'sectionname.paramname' );
DESCRIPTION
This module allows to use Config::Any for config files inside a CGI::Application based application.
This module is "work in progress" and subject to change without warning!
(Config::Any provides a facility for Perl applications and libraries to load configuration data from multiple different file formats. It supports XML, YAML, JSON, Apache-style configuration, Windows INI files, and even Perl code.)
METHODS
init
Initializes the plugin.
$self->config->init(
configdir => '/path/to/configfiles',
files => [ 'app.conf' ],
);
Valid params:
- configdir SCALAR
-
Path where the config files reside in.
- files ARRAY
-
A list of files to load.
- name SCALAR
-
You can use more than one configuration at the same time by using config names. For example:
$self->config->init( name => 'database', files => [ 'db.conf' ], ); $self->config->init( name => 'template', files => [ 'tpl.conf' ], ); ... my $connection_options = $self->config('database')->section('connection'); my $template_config = $self->config('template')->param('file');
- params HASHREF
-
Options to pass to Config::Any->load_files(). See Config::Any for details.
config
This method is exported to your C::A based application as an accessor to the configuration methods.
param
Retrieve a value from your configuration.
Examples:
$self->config->section('mysection')->param('mysetting');
# set the section to 'mysection' before retrieving 'mysetting'
$self->config->param('mysection.mysetting');
# more convenient way to do the same as above
$self->config->param('mysetting');
# if no section name is given, the name of the last section
# named by ->section() or ->param(<section>.<attribute>) syntax
# is used; this may change in future, so don't rely on it!
section
Retrieve a complete section from your configuration, or set the name of the current "default section" for later use with ->param().
my $hash = $self->config->section('mysection');
getall
Get complete configuration as a hashref.
DEBUGGING
This module provides some internal debugging. Any debug messages go to STDOUT, so beware of enabling debugging when running in a web environment. (This will end up with "Internal Server Error"s in most cases.)
There are two ways to enable the debug mode:
- In the module
-
Find line
$CGI::Application::Plugin::ConfigAny::DEBUG = 0;
and set it to any "true" value. ("1", "TRUE", ... )
- From outside the module
-
Add this line before calling
new
:$CGI::Application::Plugin::ConfigAny::DEBUG = 1;
AUTHOR
Bianka Martinovic, <Bianka.Martinovic at materna.de>
BUGS
None I'am aware of, but as I said above, this is still under development.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc CGI::Application::Plugin::ConfigAny
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
http://cpanratings.perl.org/d/CGI-Application-Plugin-ConfigAny
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=CGI-Application-Plugin-ConfigAny
Search CPAN
http://search.cpan.org/dist/CGI-Application-Plugin-ConfigAny
DEPENDENCIES
ACKNOWLEDGEMENTS
This module was slightly inspired by CGI::Application::Plugin::Context
. See http://search.cpan.org/perldoc?CGI::Application::Plugin::Config::Context for details.
COPYRIGHT & LICENSE
Copyright 2008 Bianka Martinovic, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.