Skip Menu |

This queue is for tickets about the CGI-Application-Plugin-Config-Any CPAN distribution.

Report information
The Basics
Id: 41745
Status: resolved
Priority: 0/
Queue: CGI-Application-Plugin-Config-Any

People
Owner: blackbird [...] webbird.de
Requestors: arthas [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.13
Fixed in: (no value)



Subject: Options set via $self->config_init() are ignored
I just began using this module and found out that it only works if I initialize it like this: my $app = WebApp->new( PARAMS => { config_dir => '/path/to/configfiles', config_files => [ 'app.conf' ], config_name => 'main', config_params => { ## passed to Config::Any->load_files; ## see Config::Any for valid params } } ); $app->run(); (from my init script). The documentation shows you can also do: # Set config file and other options $self->config_init( config_dir => '/path/to/configfiles', config_files => [ 'app.conf' ], config_name => 'main', config_params => { ## passed to Config::Any->load_files; ## see Config::Any for valid params } ); from within you CGI::Application based module, but it doesn't seem to work at all - that is, parameters passed seems to be ignored.
This works for me: package X; use strict; use base qw/ CGI::Application /; sub setup { my $self = shift; $self->start_mode( 'execute' ); $self->run_modes( 'execute' => 'execute', 'test' => 'test', "AUTOLOAD" => \&_no_such_runmode, ); # Set config file and other options $self->config_init( config_dir => '<Path>', config_files => [ 'config.conf' ], config_name => 'main', ); use Data::Dumper; print join( ' : ', __PACKAGE__, __LINE__ ), qq~\n~, Dumper( $self->config('defaults') ), qq~\n~; } # --- end sub setup --- Content of config.conf: <defaults> bla = blubb </defaults> So the Dumper() prints: { 'bla' => 'blubb' } ...what is exactly what I expected. :) Anyway, if you've already initialized the module in your instance script, later calls to config_init() aren't ignored, but maybe not treated as you expected. If you're not using a 'config_name', 'default' is used internally. Given that you have a config file 'config.conf' with a section 'settings' and another one called 'moreconfig.conf' with also a 'settings' section, the entries of the second config file will neither be overridden nor added to the existing config hash. This is the reason why there is the 'config_name' feature. ;) So, combining these calls will work: (Instance script) my $wwx = MyApp->new( ## this will use 'default' as config_name PARAMS => { config_dir => '<Path>', config_files => [ 'default.yaml' ], config_params => { use_ext => 1, } }, ); $wwx->run(); (in MyApp.pm) sub setup { my $self = shift; ... $self->config_init( config_files => [ 'config.conf' ], config_name => 'main', ); ... } Now, you can use the values of 'config.conf' like this: my $cfg = $self->config_read( name => 'main' ); Please feel free to suggest a behaviour more intuitive if you wish. As this module is still "work in progress", I'm alway pleased to get suggestions. :)
As there were no more replies, I'm closing this now. Please feel free to post your suggestions if you like.