akho has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Application-wide configuration
by blue_cowdawg (Monsignor) on Jul 27, 2007 at 18:47 UTC | |
by akho (Hermit) on Jul 27, 2007 at 19:04 UTC | |
|
Re: Application-wide configuration
by ikegami (Patriarch) on Jul 27, 2007 at 18:43 UTC | |
by akho (Hermit) on Jul 27, 2007 at 18:57 UTC | |
by ikegami (Patriarch) on Jul 27, 2007 at 19:04 UTC | |
by akho (Hermit) on Jul 27, 2007 at 19:24 UTC | |
|
Re: Application-wide configuration
by skx (Parson) on Jul 27, 2007 at 19:37 UTC | |
by akho (Hermit) on Jul 27, 2007 at 20:06 UTC | |
by skx (Parson) on Jul 27, 2007 at 22:05 UTC | |
|
Re: Application-wide configuration
by clinton (Priest) on Jul 28, 2007 at 08:49 UTC | |
by akho (Hermit) on Jul 28, 2007 at 09:55 UTC |