On Jul 3, 2007, at 5:51 PM, Perrin Harkins wrote:
I don't really understand this description. If you're trying to code
a singleton pattern, use global variables to hold the object. That
makes it clearer what your intent is.
Scoping works the same as usual under mod_perl. If you need access to
object instances, you can use a singleton pattern, storing the objects
in global variables, or you can pass the instances to the sub that
needs to use them.
i prefer storing them as class variables and using a public method to
provide access
ie:
package myfactory;
my $object= object->new();
sub get_object { return $object ;}
my %objects= (
'a'=> object->new(),
)
sub get_object_hash { my ( $class, $flavor )= @_; return $objects
{$flavor} ;}
package myapp;
my $object= myfactory->get_object();
my $object_a= myfactory->get_object('a');
i can't remember if the $class is necessary or not. i'm responding
via my mobile :)