perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From william ross <w...@spanner.org>
Subject Re: passing an object to a handler
Date Wed, 02 Oct 2002 20:34:35 GMT

On Wednesday, October 2, 2002, at 09:11 PM, Dave Rolsky wrote:

> On Wed, 2 Oct 2002, william ross wrote:
>
>> sorry: i wasn't very clear, was I? I am using a method handler, but I
>> want to pass an object of another class to it each time it is called.
>> The object needs to be created outside of an individual request, and
>> therefore presumably in a startup file, and then either passed to the
>> handler along with each request, or somehow made available to all the
>> requests, but preferably without setting a class variable, which is
>> what I do at the moment but dislike.
>
> You could make the other object a singleton, so you could just do:
>
>   my $factory = My::Factory->instance

I did have it set up that way at one point. it worked quite nicely as 
long as I made the singleton in a subclass of the main Factory (which 
might be shared by several applications with different configurations). 
i gave up on it in the end because it seemed a bit overheated, but if 
you approve, i shall reconsider.

so, rehearsing: all it should take is a Factory::Subclass->new(config 
blah) in the startup script and a Factory::Subclass->instance() in the 
handler? it does sound good if you put it like that.

incidentally I made the singleton like this (yes, more poop):

use base qw (Class::DBI::Factory Class::Singleton);
...
sub _new_instance { shift->new(@_) }

but it felt rather naughty to subclass the private _new_instance. if 
anyone knows a better way, I'd be very glad to hear it.

(but this is galloping quickly away from the topic, and I'm sure I can 
work it out in the end :)

thank you.


will


Mime
View raw message