perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From william ross <>
Subject Re: passing an object to a handler
Date Wed, 02 Oct 2002 20:21:37 GMT

On Wednesday, October 2, 2002, at 08:37 PM, Per Einar Ellefsen wrote:

> At 21:30 02.10.2002, william ross wrote:
>> On Wednesday, October 2, 2002, at 08:18 PM, Per Einar Ellefsen wrote:
>>> At 20:47 02.10.2002, william ross wrote:
>>>> but I can't find anything to tell me how to do it. I feel sure I'm 
>>>> missing something really obvious here?
>>> You can configure objects instead of using static class names. See 
>>> the doc:
>> 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.
> Yes, and that it exactly what the doc I referred to shows you:
> You instantiate an object in your startup file; then you configure 
> mod_perl to call your handler with this object as the class, like:
> PerlHandler $My::obj->handler
> $My::Obj must then be an instance of the handler class, but can 
> contain any other information too.
> Now, in your handler, you get:
> sub handler ($$) {
> my ($obj, $r) = @_;
> and you have your $obj, which you can use freely. ($obj isn't a class 
> name, it is an ... object!)
> Wasn't that what you wanted?

no, not quite, though i begin to suspect that i wanted the wrong thing, 
and what you suggest - which I had read several times but apparently 
not taken in - is what I should be looking for.

the trouble is that I want to have many handler objects - they hold 
session information, among other reasons - but I want each one to use 
the same factory object. I don't want to instantiate a single handler, 
as i think your snippet would. so i thought i'd make a new one each 
time and pass the factory to each one.

but it looks - from what you say - like I've just got it back to front: 
at the moment Class::DBI::Handler expects to be given a 
Class::DBI::Factory object, but what I should do is put the handler($$) 
method in the factory itself, and construct a new 
Class::DBI::Factory::Handler object each time it's called, to hold 
whatever per-request information is required.

excuse me thinking out loud: maybe you could warn me if it sounds like 
i've found another wrong tree. meanwhile, I'll go try it.

thanks for your help


View raw message