Re: method handlers
Jordan McLain wrote: just noticed... in the actual code 'handler' is prototyped with ($$) sub handler { my ($class, $r) = @_; my $self = ... # something hashref-ish I will end up writing another new() for use when not called directly from apache. Is this bad style, since the method does not return the blessed ref to something, but instead calls methods directly with the blessed ref? Personally I get Apache to call new() for me, so other code can use the class in the same way apache does: --- in httpd.conf: PerlModule My::HandlerModule PerlResponseHandler My::HandlerModule-handler_method # apache calls your new() method automatically I think PerlFixupHandler My::HandlerModule-fixup_handler_method --- Or even better, when I want a single instance of my handler module per apache process: --- package My::HandlerModule; $My::HandlerModule::Persistent=My::HandlerModule-new(); sub new { etc etc } sub handler_method { my ($self,$r)[EMAIL PROTECTED]; etc etc } --- in httpd.conf: PerlResponseHandler $My::HandlerModule::Persistent-handler_method --- hope this helps, John
Re: Re: method handlers
Ahh, I see. Great tip. Thanks alot. Jordan On 10/27/06, John ORourke [EMAIL PROTECTED] wrote: Jordan McLain wrote: just noticed... in the actual code 'handler' is prototyped with ($$) sub handler { my ($class, $r) = @_; my $self = ... # something hashref-ish I will end up writing another new() for use when not called directly from apache. Is this bad style, since the method does not return the blessed ref to something, but instead calls methods directly with the blessed ref? Personally I get Apache to call new() for me, so other code can use the class in the same way apache does: --- in httpd.conf: PerlModule My::HandlerModule PerlResponseHandler My::HandlerModule-handler_method # apache calls your new() method automatically I think PerlFixupHandler My::HandlerModule-fixup_handler_method --- Or even better, when I want a single instance of my handler module per apache process: --- package My::HandlerModule; $My::HandlerModule::Persistent=My::HandlerModule-new(); sub new { etc etc } sub handler_method { my ($self,$r)[EMAIL PROTECTED]; etc etc } --- in httpd.conf: PerlResponseHandler $My::HandlerModule::Persistent-handler_method --- hope this helps, John
Re: method handlers
just noticed... in the actual code 'handler' is prototyped with ($$) On 10/26/06, Jordan McLain [EMAIL PROTECTED] wrote: Hello, This is more of a style and usage question. Sorry for the stupid question. I am rewriting one of my apps to be more OO so that I can abstract its' functionality out to another handler potentially. I end up doing something like this... sub handler { my ($class, $r) = @_; my $self = ... # something hashref-ish bless $self, $class; ... my $method = $modes{$mode}; # hash lookup of available modes $self-$method; return OK; } I will end up writing another new() for use when not called directly from apache. Is this bad style, since the method does not return the blessed ref to something, but instead calls methods directly with the blessed ref? thanks, Jordan Mclain eCarList.com