Many handlers in the same module
Many handlers in the same module
am 19.03.2008 19:22:20 von Colin Wetherbee
Greetings.
In order to have many handlers in a file, I've put the following lines
and other, similar lines in my virtual host configuration:
PerlAccessHandler JetSet::Handler->AccessHandler
PerlResponseHandler JetSet::Handler->ResponseHandler
Then, my handlers look like this:
sub ResponseHandler
{
my (undef, $r) = @_;
# ...
}
This seems to work well enough, but just today, I thought there might be
some reason to not do this. I searched through the documentation and
couldn't find anything, but it's still nagging me.
Is there anything inherently Bad about doing this?
I think the undef $self is bugging me the most, but I don't know why
this would cause any problems.
Thanks.
Colin
Re: Many handlers in the same module
am 19.03.2008 19:31:07 von aw
In a similat setup, I successfuly use
my ($self, $r) = @_;
so, if the undef bothers you ..
;-)
Colin Wetherbee wrote:
> Greetings.
>
> In order to have many handlers in a file, I've put the following lines
> and other, similar lines in my virtual host configuration:
>
> PerlAccessHandler JetSet::Handler->AccessHandler
> PerlResponseHandler JetSet::Handler->ResponseHandler
>
> Then, my handlers look like this:
>
> sub ResponseHandler
> {
> my (undef, $r) = @_;
> # ...
> }
>
> This seems to work well enough, but just today, I thought there might be
> some reason to not do this. I searched through the documentation and
> couldn't find anything, but it's still nagging me.
>
> Is there anything inherently Bad about doing this?
>
> I think the undef $self is bugging me the most, but I don't know why
> this would cause any problems.
>
> Thanks.
>
> Colin
>
Re: Many handlers in the same module
am 19.03.2008 19:37:03 von Colin Wetherbee
André Warnier wrote:
> In a similat setup, I successfuly use
> my ($self, $r) = @_;
> so, if the undef bothers you ..
:)
Do you actually use $self for anything?
Colin
Re: Many handlers in the same module
am 19.03.2008 19:41:46 von John ORourke
André Warnier wrote:
> In a similat setup, I successfuly use
> my ($self, $r) =3D @_;
Colin Wetherbee wrote:
>> PerlAccessHandler JetSet::Handler->AccessHandler
>> PerlResponseHandler JetSet::Handler->ResponseHandler
The only down-side is that (AFAICR) it is creating a new object for each =
request - my handler is quite expensive to set up, so I have a=20
persistent object and use method handlers like this:
package My::Handlers;
$My::Handlers::Persistent=3DMy::Handlers->new();
sub response_handler { my ($self,$r)=3D@_; .... }
sub fixup_handler { my ($self,$r) =3D @_; .... }
and apache config:
PerlResponseHandler $My::Handlers::Persistent->response_handler
PerlFixupHandler $My::Handlers::Persistent->fixup_handler
cheers
John
Re: Many handlers in the same module
am 19.03.2008 19:46:49 von Colin Wetherbee
John ORourke wrote:
> The only down-side is that (AFAICR) it is creating a new object for each
> request - my handler is quite expensive to set up, so I have a
> persistent object and use method handlers like this:
Ah, that's quite neat. I might give that a shot.
Thanks for the suggestion.
Colin
Re: Many handlers in the same module
am 19.03.2008 21:10:14 von aw
John,
It does not look as if what you write below is true though.
I just tested with
PerlResponseHandler AM::TestStuff->handler
and
sub handler {
my ($self,$r) = @_;
$r->print('$self is a [' . ref($self) . '] and contains [' . $self .
"]\n");
[...]
and the result is
$self is a [] and contains [AM::TestStuff]
doesn't seem to be an object.
I think it is only the module's name you get in there.
So maybe you can save yourself some cpu cycles in future
(a pity though, it was elegant stuff).
I'll stick to my (unused) $self, though maybe I'll rename it to
$classname, now that I know.
It was worth finding out for sure though.
André
John ORourke wrote:
> André Warnier wrote:
>> In a similat setup, I successfuly use
>> my ($self, $r) = @_;
> Colin Wetherbee wrote:
>>> PerlAccessHandler JetSet::Handler->AccessHandler
>>> PerlResponseHandler JetSet::Handler->ResponseHandler
>
> The only down-side is that (AFAICR) it is creating a new object for each
> request - my handler is quite expensive to set up, so I have a
> persistent object and use method handlers like this:
>
> package My::Handlers;
> $My::Handlers::Persistent=My::Handlers->new();
>
> sub response_handler { my ($self,$r)=@_; .... }
> sub fixup_handler { my ($self,$r) = @_; .... }
>
> and apache config:
>
> PerlResponseHandler $My::Handlers::Persistent->response_handler
> PerlFixupHandler $My::Handlers::Persistent->fixup_handler
>
> cheers
> John
>
>
>
Re: Many handlers in the same module
am 19.03.2008 23:41:22 von Colin Wetherbee
André Warnier wrote:
> PerlResponseHandler AM::TestStuff->handler
>
> and
>
> sub handler {
> my ($self,$r) = @_;
> $r->print('$self is a [' . ref($self) . '] and contains [' . $self .
> "]\n");
>
> [...]
>
> and the result is
> $self is a [] and contains [AM::TestStuff]
>
> doesn't seem to be an object.
I get the same thing.
> I think it is only the module's name you get in there.
> So maybe you can save yourself some cpu cycles in future
> (a pity though, it was elegant stuff).
>
> I'll stick to my (unused) $self, though maybe I'll rename it to
> $classname, now that I know.
>
> It was worth finding out for sure though.
+1
Colin
Re: Many handlers in the same module
am 26.03.2008 04:36:33 von jonathan vanasco
On Mar 19, 2008, at 2:22 PM, Colin Wetherbee wrote:
> PerlAccessHandler JetSet::Handler->AccessHandler
> PerlResponseHandler JetSet::Handler->ResponseHandler
>
> sub ResponseHandler
> {
> my (undef, $r) = @_;
> # ...
> }
what about...
PerlAccessHandler JetSet::Handler::AccessHandler
sub AccessHandler {
my ($r) = @_;
}
Re: Many handlers in the same module
am 26.03.2008 14:47:03 von Colin Wetherbee
Jonathan Vanasco wrote:
> On Mar 19, 2008, at 2:22 PM, Colin Wetherbee wrote:
>> PerlAccessHandler JetSet::Handler->AccessHandler
>> PerlResponseHandler JetSet::Handler->ResponseHandler
>>
>> sub ResponseHandler
>> {
>> my (undef, $r) = @_;
>> # ...
>> }
>
> what about...
>
> PerlAccessHandler JetSet::Handler::AccessHandler
>
> sub AccessHandler {
> my ($r) = @_;
> }
We seem to have solved the problem, but for the sake of conversation...
When I've tried that in the past, mod_perl would always look for
handler() within JetSet::Handler::AccessHandler.pm.
Colin
Re: Many handlers in the same module
am 28.03.2008 01:27:25 von jonathan vanasco
On Mar 26, 2008, at 9:47 AM, Colin Wetherbee wrote:
> We seem to have solved the problem, but for the sake of
> conversation...
>
> When I've tried that in the past, mod_perl would always look for
> handler() within JetSet::Handler::AccessHandler.pm.
Wow.
I've got 5 sites in production right now... and dating back to
03/04.... with multiple specified handlers like that
I've never had that issue come up, nor have i planned for it. I
could see that happening though....
Wow... again... I never thought of that.
Re: Many handlers in the same module
am 28.03.2008 01:43:38 von Colin Wetherbee
Jonathan Vanasco wrote:
> On Mar 26, 2008, at 9:47 AM, Colin Wetherbee wrote:
>> We seem to have solved the problem, but for the sake of conversation...
>>
>> When I've tried that in the past, mod_perl would always look for
>> handler() within JetSet::Handler::AccessHandler.pm.
>
> Wow.
>
> I've got 5 sites in production right now... and dating back to 03/04....
> with multiple specified handlers like that
>
> I've never had that issue come up, nor have i planned for it. I could
> see that happening though....
>
> Wow... again... I never thought of that.
Yep... here it is:
[Fri Mar 28 00:37:00 2008] [error] [client 192.168.171.80] failed to
resolve handler `JetSet::Handler::InitHandler': Can't locate
JetSet/Handler/InitHandler.pm in @INC (@INC contains:
/home/cww/sites/js.iron.denterprises.org/htdocs/jet-set /etc/perl
/usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5
/usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8
/usr/local/lib/site_perl . /etc/apache2) at (eval 7) line 3.\n, referer:
http://js/jet-set/login
From this bit of the virtual host:
PerlSetVar ReloadDirectories
"/home/cww/sites/js.iron.denterprises.org/htdoc
SetHandler perl-script
PerlInitHandler Apache2::Reload
#PerlInitHandler JetSet::Handler->InitHandler
PerlInitHandler JetSet::Handler::InitHandler
#PerlResponseHandler JetSet::Handler->ResponseHandler
PerlResponseHandler JetSet::Handler::ResponseHandler
(Note the PerlSetVar line was truncated by my non-use of line-wrap in vim.)
Actually, though, I think I remember ResponseHandler working OK... so,
I'm going to put InitHandler back to the way it was (with ->) and try again.
Hm. Yep. ResponseHandler can interpret the ::ResponseHandler part as
being a function within Handler.pm, but that does *not* work for
InitHandler.
Interesting.
For completeness, the above does not work, but the following does.
PerlSetVar ReloadDirectories
"/home/cww/sites/js.iron.denterprises.org/htdoc
SetHandler perl-script
PerlInitHandler Apache2::Reload
PerlInitHandler JetSet::Handler->InitHandler
#PerlResponseHandler JetSet::Handler->ResponseHandler
PerlResponseHandler JetSet::Handler::ResponseHandler
Where InitHandler() and ResponseHandler() are subs declared within
Handler.pm.
Colin
Re: Many handlers in the same module
am 28.03.2008 19:50:32 von jonathan vanasco
On Mar 27, 2008, at 8:43 PM, Colin Wetherbee wrote:
> Hm. Yep. ResponseHandler can interpret the ::ResponseHandler part
> as being a function within Handler.pm, but that does *not* work for
> InitHandler.
i have it set up using
PerlFixupHandler
PerlResponseHandler
PerlCleanupHandler
PerlPostReadRequestHandler
I haven't tried init handler
do you have , perhaps, a conflict in packages and subs?
ie:
JetSet/Handler.pm
JetSet/Handler/ResponseHandler.pm
or something like that, where we need a difference between :: and -> ?
Re: Many handlers in the same module
am 28.03.2008 20:11:11 von Colin Wetherbee
Jonathan Vanasco wrote:
> On Mar 27, 2008, at 8:43 PM, Colin Wetherbee wrote:
>> Hm. Yep. ResponseHandler can interpret the ::ResponseHandler part as
>> being a function within Handler.pm, but that does *not* work for
>> InitHandler.
>
> i have it set up using
>
> PerlFixupHandler
> PerlResponseHandler
> PerlCleanupHandler
> PerlPostReadRequestHandler
>
> I haven't tried init handler
Care to add one, just to see what happens? :)
> do you have , perhaps, a conflict in packages and subs?
>
> ie:
>
> JetSet/Handler.pm
> JetSet/Handler/ResponseHandler.pm
>
> or something like that, where we need a difference between :: and -> ?
I don't have anything like that. The only subdirectory under JetSet
is called 'static', which just contains a couple .html files.
Colin
Re: Many handlers in the same module
am 29.03.2008 00:02:15 von jonathan vanasco
On Mar 28, 2008, at 3:11 PM, Colin Wetherbee wrote:
> Care to add one, just to see what happens? :)
You know you've been working too much on the Business Side when you
stop testing stuff like that automatically. sigh...
ok...
it works if i have
package MyApp;
sub handler {}
sub handler_init {}
sub handler_etc {}
if there is a package
MyApp::hander_init.pm
and a function
MyApp->handler_init
mp will call
MyApp->handler_init
the only way i could get get
MyApp::hander_init->handler
to call was to delete MyApp->handler_init
here's a snipped from my startup.pl
foreach my $dir ( @dirs ) {
$Location{"/$dir"} = {
SetHandler=>
'modperl' ,
#PerlInitHandler=>
'Apache2::Reload',
PerlInitHandler=>
'FindMeOn::handler_test',
PerlFixupHandler=>
'FindMeOn::relaunch_check',
PerlResponseHandler=> 'FindMeOn',
PerlCleanupHandler=>
'FindMeOn::cleanup',
}
}
Re: Many handlers in the same module
am 29.03.2008 11:41:33 von aw
Hi.
Just for the rest of us : does anyone care to summarise what works and
works not (inasfar as not necessarily documented and/or intuitive) ?
And maybe what the original point of this interesting thread was ?
Thanks
André
Jonathan Vanasco wrote:
>
> On Mar 28, 2008, at 3:11 PM, Colin Wetherbee wrote:
>> Care to add one, just to see what happens? :)
>
> You know you've been working too much on the Business Side when you stop
> testing stuff like that automatically. sigh...
>
> ok...
>
> it works if i have
>
>
> package MyApp;
>
> sub handler {}
> sub handler_init {}
> sub handler_etc {}
>
> if there is a package
> MyApp::hander_init.pm
>
> and a function
> MyApp->handler_init
>
> mp will call
> MyApp->handler_init
>
> the only way i could get get
> MyApp::hander_init->handler
>
> to call was to delete MyApp->handler_init
>
> here's a snipped from my startup.pl
>
> foreach my $dir ( @dirs ) {
> $Location{"/$dir"} = {
> SetHandler=> 'modperl' ,
> #PerlInitHandler=>
> 'Apache2::Reload',
> PerlInitHandler=>
> 'FindMeOn::handler_test',
> PerlFixupHandler=>
> 'FindMeOn::relaunch_check',
> PerlResponseHandler=>
> 'FindMeOn',
> PerlCleanupHandler=>
> 'FindMeOn::cleanup',
> }
> }
>
>
Re: Many handlers in the same module
am 31.03.2008 19:36:17 von Colin Wetherbee
Jonathan Vanasco wrote:
> On Mar 28, 2008, at 3:11 PM, Colin Wetherbee wrote:
>> Care to add one, just to see what happens? :)
>
> You know you've been working too much on the Business Side when you stop
> testing stuff like that automatically. sigh...
Indeed. :)
> ok...
>
> it works if i have
[snip]
I think your testing concludes that our InitHandler definitions are
interpreted differently by mod_perl.
i.e., Mine only works if -> is used, but yours works for both -> and ::,
where -> takes precedence over ::. I believe your tested behavior would
be the expected behavior.
Is that correct? :P
Also, I wonder if the difference is caused by the different ways we're
adding handlers? I specify mine in the virtual host configuration, and
it looks like you specify yours in startup.pl.
Colin
Re: Many handlers in the same module
am 31.03.2008 19:37:52 von Colin Wetherbee
� wrote:
> Just for the rest of us : does anyone care to summarise what works
> and works not (inasfar as not necessarily documented and/or
> intuitive) ? And maybe what the original point of this interesting
> thread was ?
Sure, but I don't think we're finished quite yet. ;)
Colin
Re: Many handlers in the same module
am 31.03.2008 20:55:35 von Ryan Gies
I imagine you're already aware of this, but just in case...
"PerlInitHandler
When configured inside any container directive, except ,
this handler is an alias for PerlHeaderParserHandler described earlier.
Otherwise it acts as an alias for PerlPostReadRequestHandler described
earlier."
(http://perl.apache.org/docs/2.0/user/handlers/http.html#Per lInitHandler)
Colin Wetherbee wrote:
> � wrote:
>> Just for the rest of us : does anyone care to summarise what works
>> and works not (inasfar as not necessarily documented and/or
>> intuitive) ? And maybe what the original point of this interesting
>> thread was ?
>
> Sure, but I don't think we're finished quite yet. ;)
>
> Colin
--
Livesite Networks, LLC
Ryan Gies (ryan@livesite.net)
(208) 265-4229, or (800) 230-4113; Fax (302) 261-0543
Re: Many handlers in the same module
am 31.03.2008 21:42:59 von Perrin Harkins
On Wed, Mar 19, 2008 at 2:22 PM, Colin Wetherbee wrote:
> In order to have many handlers in a file, I've put the following lines
> and other, similar lines in my virtual host configuration:
>
> PerlAccessHandler JetSet::Handler->AccessHandler
> PerlResponseHandler JetSet::Handler->ResponseHandler
>
> Then, my handlers look like this:
>
> sub ResponseHandler
> {
> my (undef, $r) = @_;
> # ...
> }
>
> This seems to work well enough, but just today, I thought there might be
> some reason to not do this.
There's no reason not to do that. It's merely a question of how you
like to organize your code.
> I think the undef $self is bugging me the most, but I don't know why
> this would cause any problems.
The first argument to class method calls in perl (which is what this
is) is the name of the class. It doesn't hurt anything to throw it
away if you won't use it though.
- Perrin
Re: Many handlers in the same module
am 31.03.2008 21:46:45 von Perrin Harkins
On Wed, Mar 19, 2008 at 2:41 PM, John ORourke wrote:
> The only down-side is that (AFAICR) it is creating a new object for each
> request
No, it's a class method. No object is created.
> PerlResponseHandler $My::Handlers::Persistent->response_handler
> PerlFixupHandler $My::Handlers::Persistent->fixup_handler
That should work, but is not an issue unless you need your handler to
be called as an object method instead of a class method.
- Perrin
Re: Many handlers in the same module
am 31.03.2008 21:49:36 von Perrin Harkins
On Wed, Mar 26, 2008 at 9:47 AM, Colin Wetherbee wrote:
> > what about...
> >
> > PerlAccessHandler JetSet::Handler::AccessHandler
> >
> > sub AccessHandler {
> > my ($r) = @_;
> > }
>
> We seem to have solved the problem, but for the sake of conversation...
>
> When I've tried that in the past, mod_perl would always look for
> handler() within JetSet::Handler::AccessHandler.pm.
Right. That is completely different configuration from
JetSet::Handler->AccessHandler. Without the method call indicator,
you're just telling mod_perl which package to look for the handler()
sub in, and telling it to call handler() as a sub rather than a class
method.
- Perrin
Re: Many handlers in the same module
am 31.03.2008 21:54:55 von Perrin Harkins
On Sat, Mar 29, 2008 at 6:41 AM, Andr=E9 Warnier wrote:
> Just for the rest of us : does anyone care to summarise what works and
> works not (inasfar as not necessarily documented and/or intuitive) ?
I think it's pretty well-documented:
http://perl.apache.org/docs/2.0/user/porting/porting.html#Me thod_Handlers
http://perl.apache.org/docs/2.0/user/coding/coding.html#Meth od_Handlers
http://perl.apache.org/docs/2.0/user/porting/compat.html#Met hod_Handlers
There's more in the 1.0 docs and in all of the mod_perl books.
- Perrin