johnnywang has asked for the wisdom of the Perl Monks concerning the following question:
in later part of the code, I can simply call $config and $logger.use strict; use AppConfig; use Log::Log4perl qw(get_logger); my $config = AppConfig->new()->file("app.properties"); Log::Log4perl->init($config->get("log4perl")); # init log my $logger = get_logger(__PACKAGE__); # or some other name
The problem is when I try to do similar things to modules, who should construct/init the $config and $logger? It seems to be too much to write the above code to all the module, even too much as a base class. Should the caller of the module always pass in the $config and $logger? There is a pattern called "Inversion of Control" which, among other things, advocates that the creator is responsible for providing all environments, including configuration and logging. Does that make sense here? what do you do?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Inversion of control: logging and configuration
by phaylon (Curate) on Feb 22, 2005 at 22:15 UTC | |
|
Re: Inversion of control: logging and configuration
by stvn (Monsignor) on Feb 22, 2005 at 23:24 UTC | |
|
Re: Inversion of control: logging and configuration
by Fendaria (Beadle) on Feb 22, 2005 at 23:25 UTC | |
|
Re: Inversion of control: logging and configuration
by ikegami (Patriarch) on Feb 22, 2005 at 22:18 UTC | |
|
Re: Inversion of control: logging and configuration
by mpeters (Chaplain) on Feb 22, 2005 at 22:22 UTC | |
|
Re: Inversion of control: logging and configuration
by saintmike (Vicar) on Feb 23, 2005 at 18:01 UTC | |
|
Re: Inversion of control: logging and configuration
by Thilosophy (Curate) on Feb 23, 2005 at 00:16 UTC |