passing an object to a handler

2002-10-02 Thread william ross

hello,

I've been off-list for a while, so please forgive (and direct) me if 
this is a tired subject.

In short, i'd like to pass through another object on method invocation, 
in addition to the apache request. Ideally the (method)handler would 
look something like:

sub handler ($$$) {
my ($class, $r, $factory) = _;
...
}

where $factory is an object I made earlier, and is shared among all the 
requests. I'd like to avoid class data because the handler will almost 
always be subclassed, and anyway it makes me nervous. And for the same 
reason I don't want to make the factory a singleton: each single, 
hard-working object of the factory class will have a different 
configuration.

but I can't find anything to tell me how to do it. I feel sure I'm 
missing something really obvious here?

thanks

will




Re: passing an object to a handler

2002-10-02 Thread Per Einar Ellefsen

At 20:47 02.10.2002, william ross wrote:
hello,

I've been off-list for a while, so please forgive (and direct) me if this 
is a tired subject.

In short, i'd like to pass through another object on method invocation, in 
addition to the apache request. Ideally the (method)handler would look 
something like:

sub handler ($$$) {
 my ($class, $r, $factory) = @_;
 ...
}

where $factory is an object I made earlier, and is shared among all the 
requests. I'd like to avoid class data because the handler will almost 
always be subclassed, and anyway it makes me nervous. And for the same 
reason I don't want to make the factory a singleton: each single, 
hard-working object of the factory class will have a different configuration.

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:

http://perl.apache.org/docs/1.0/guide/method_handlers.html


-- 
Per Einar Ellefsen
[EMAIL PROTECTED]





Re: passing an object to a handler

2002-10-02 Thread william ross


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:

 http://perl.apache.org/docs/1.0/guide/method_handlers.html

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.

thanks

will




Re: passing an object to a handler

2002-10-02 Thread Per Einar Ellefsen

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:

http://perl.apache.org/docs/1.0/guide/method_handlers.html

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?


-- 
Per Einar Ellefsen
[EMAIL PROTECTED]





Re: passing an object to a handler

2002-10-02 Thread william ross


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:

 http://perl.apache.org/docs/1.0/guide/method_handlers.html

 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

will




Re: passing an object to a handler

2002-10-02 Thread william ross


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




Re: passing an object to a handler

2002-10-02 Thread Dave Rolsky

On Wed, 2 Oct 2002, william ross wrote:

 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.

I'm not quite following you.  Overheated?

 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.

Check out Class::Singleton.


-dave

/*==
www.urth.org
we await the New Sun
==*/




Re: passing an object to a handler

2002-10-02 Thread william ross


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

 On Wed, 2 Oct 2002, william ross wrote:

 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.

 I'm not quite following you.  Overheated?

sorry. i just meant that it seemed like a lot of engineering - much of 
which was a little beyond me, though I've caught up a bit since - for 
what seemed like such a simple requirement.
but i've just been doing as you suggested, and it does work rather 
nicely. thanks.

 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.

(dimwit: both calls should be to instance(). oops)

 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.

 Check out Class::Singleton.

er, that's what I said. guess it must be ok :)

will