perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Ihnen <>
Subject Re: a2c controller method names
Date Fri, 02 Jan 2009 16:47:42 GMT
Mark Hedges wrote:
> On Thu, 1 Jan 2009, Mark Hedges wrote:
>> Regarding your comment about inheritance vs. references -
>> something I hadn't thought much about.  A) I need to prefix
>> all my internal method names with 'a2c_' to stay out of
>> the controller namespace.  B) You can't have any controller
>> subroutines with the same names as anything in the
>> Apache2::Request* family, which (slightly) limits your
>> choice of allowable URL's.  But I think it's worth it so
>> that '$self' is the Apache object.  What do people think?
> 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.

The downside is that you're overlapping namespaces, as you mentioned 
before, which has its own complications.

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.

I would make myself a little method

sub r { shift->{'r'} };

just so I could write


instead of having to do the hash dereference.  Of course, you can 
program that sort of thing in AUTOLOAD too.  ;)


View raw message