simonodell has asked for the wisdom of the Perl Monks concerning the following question:
does the subroutine "bar" run every time I put use Model::Conf in other packages? If so, and assuming I want the code only to run once at compile time and its result to be accessible in any other package I put use Model::Conf in, would the following be correct;package Model::Conf; use Exporter; use base 'Exporter'; our @EXPORT = qw( $conf ); our $conf = { 'somevar' => 'somevalue' }; $conf->{'foo'} = bar(); sub bar() { return 'bar'; } 1;
The reason I ask is that I want to be able to put use Model::Conf in various other packages without the sub "bar" being run each time and wasting OPCODES on a very tight little MVC 'micro'-framework I am working on for the educational benefit, and I am not sure if the above is the right way to be going or what. Any thoughts? Many thanks.package Model::Conf; use Exporter; use base 'Exporter'; our @EXPORT = qw( $conf ); our $conf = { 'somevar' => 'somevalue' }; $conf->{'foo'} = bar() unless $conf->{'foo'}; sub bar() { return 'bar'; } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: package compiling
by Eliya (Vicar) on Apr 13, 2011 at 16:55 UTC | |
by simonodell (Acolyte) on Apr 13, 2011 at 17:21 UTC | |
by Eliya (Vicar) on Apr 13, 2011 at 17:30 UTC | |
by simonodell (Acolyte) on Apr 13, 2011 at 20:34 UTC | |
by FunkyMonk (Bishop) on Apr 13, 2011 at 20:46 UTC | |
|
Re: package compiling
by afoken (Chancellor) on Apr 14, 2011 at 09:59 UTC | |
by simonodell (Acolyte) on Apr 14, 2011 at 18:17 UTC | |
by afoken (Chancellor) on Apr 17, 2011 at 07:10 UTC | |
by Anonymous Monk on Apr 22, 2011 at 11:56 UTC | |
by afoken (Chancellor) on Apr 22, 2011 at 15:57 UTC |