perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Hedges <hed...@scriptdolphin.org>
Subject Re: a2c controller method names
Date Fri, 02 Jan 2009 17:23:29 GMT

> > On Thu, 1 Jan 2009, Mark Hedges wrote: Talking to myself
> > again. I think I can make it work either way.
> > Apache2::Controller won't use Apache2::Request as a
> > base, but it will still instantiate the Apache2::Request
> > object and put it in $self->{r}.  Then if you want to
> > use Apache2::Request as a base in your controller module
> > to access those methods via $self, you can.  Otherwise,
> > don't.
>
> For a compromise between them you could also do the 'fake
> delegate' where your AUTOLOAD subroutine checks if
> $self->{r}->can(($AUTOLOAD =~ /::(.+?)$/)[0]) returns a
> CODE ref and delegates the call to that routine.

I don't want to use AUTOLOAD.  It adds latency and it
confuses the hell out of me when the method namespace gets
complicated.  You're free to use AUTOLOAD in controller
packages though.

> I think you're right, its better to be explicit about
> choosing the request object when you want to do a request
> object method.  That works find unless you're replicating
> some sort of interface where the methods you need directly
> callable are in two diff subclasses and inheritance
> doesn't do what you want and explicit delegation (wrapper
> methods) is too much of a PITA.

Yeah, this is why I usually spell things out instead of
using SUPER::.  In this case I've discovered it is in fact
important to get the inheritance order right.  As long as
Apache2::Request is the last base it comes out okay, new()
then creates the A2C handler object instead of trying to
make an Apache2::Request object.

> I would make myself a little method
>
> sub r { shift->{'r'} };
>
> just so I could write
>
> $self->r->...
>
> instead of having to do the hash dereference.  Of course,
> you can program that sort of thing in AUTOLOAD too.  ;)

You could do that in some app co-base that you write to
extend your controllers with convenience methods, if you
choose not to use Apache2::Request as a base to suck its
methods into $self.  But if you don't choose to do that,
dereferencing $self->{r} is faster than calling a method
that then does the same thing, so I probably won't provide
the convenience method.

Mark

Mime
View raw message