You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Jordan McLain <jo...@gmail.com> on 2006/10/27 05:16:40 UTC
method handlers
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
Re: Re: method handlers
Posted by Jordan McLain <jo...@gmail.com>.
Ahh, I see. Great tip. Thanks alot.
Jordan
On 10/27/06, John ORourke <jo...@o-rourke.org> 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)=@_; etc etc }
> -----------------------------------------------
> in httpd.conf:
>
> PerlResponseHandler $My::HandlerModule::Persistent->handler_method
> -----------------------------------------------
>
> hope this helps,
> John
>
>
Re: method handlers
Posted by John ORourke <jo...@o-rourke.org>.
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)=@_; etc etc }
-----------------------------------------------
in httpd.conf:
PerlResponseHandler $My::HandlerModule::Persistent->handler_method
-----------------------------------------------
hope this helps,
John
Re: method handlers
Posted by Jordan McLain <jo...@gmail.com>.
just noticed... in the actual code 'handler' is prototyped with ($$)
On 10/26/06, Jordan McLain <jo...@gmail.com> 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
>