EvdB has asked for the wisdom of the Perl Monks concerning the following question:
Say I want to create a package with this framework:
package my_test_package; # Create a package global. my $ME = undef; # Return the required reference. sub new { # If $ME has been set do not bother doing all the init again. return $ME if defined $ME; my $class = shift; my $self = {}; # A lot of long-winded initialization. bless $self, $class; $ME = $self; return $self; } 1;
The basic idea is to avoid running through all the longwinded setting up several times. This is intended to be run under something such as mod_perl where the object might actually hang around for weeks, leading to performance gains.
My question is 'Is this a good idea?' I can think of the following pros and cons:
I suppose I really want your opinions on wether the risks involved outweigh the benefits. Are there any safeguards that could be put in place to keep the code safer? Any thoughts would be much appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Never letting package objects to go out of scope
by jdporter (Paladin) on Feb 10, 2003 at 14:53 UTC | |
|
Re: Never letting package objects to go out of scope
by mowgli (Friar) on Feb 10, 2003 at 14:41 UTC | |
|
Re: Never letting package objects to go out of scope
by perrin (Chancellor) on Feb 10, 2003 at 15:31 UTC | |
|
Re: Never letting package objects to go out of scope
by LanceDeeply (Chaplain) on Feb 11, 2003 at 03:08 UTC | |
|
Re: Never letting package objects to go out of scope
by Anonymous Monk on Feb 10, 2003 at 15:01 UTC |