I currently use a special class that keeps the configuration in a class variable.
use strict; package Config::Once; use Config::Auto; our $Config; sub init { my ($inv, $config_path) = @_; my $class = ref ($inv) || $inv; my $config_varname = $class . '::Config'; no strict 'refs'; $$config_varname = Config::Auto::parse( $config_path ); return $$config_varname; } sub cfg { my ($inv, $param) = @_; my $class = ref ($inv) || $inv; my $config_varname = $class . '::Config'; no strict 'refs'; return $$config_varname->{$param} if (defined $param); return $$config_varname; } 1;
Then every application subclasses it:
use strict; package MyApp::Config; use base qw/ Config::Once /; 1;
and the modules can do MyApp::Config->cfg('smth').
Is this the right way to do it? Is something like that (or a better solution) available from CPAN?
In reply to Application-wide configuration by akho
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |