Hi,
I have some modules that use the idiom
package Foo;
use Bar;
{
my $bar = Bar->new(args);
sub bar { return $bar }
}
which works fine until one tries to preload them in startup.pl.
I realized that, by preloading, I was innocently sharing the same DBI
object between Apache children (nothing strange happened during
testing, but I guess it was only a question of time & stress).
I also happen to have Foo subclasses that need the DBI connection to
produce otherwise shareable (read only) class data.
My question is about good programming practice in this case. I guess
I have three options:
(init once per MaxRequestsPerChild)
* initialize the class data externally, from within a method.
* do something like
{
my $bar;
sub bar {
$bar = BAR->new(args) unless $bar; # too ugly? performance loss small?
return $bar;
}
}
(init only once)
* initialize everything in the parent Apache, just make sure to create
new DBI connections in the children.
What do you think?
Thanks,
--
Adriano