[cgiapp] Re: can AUTOLOAD sub be named AUTOLOAD?

Mark Stosberg mark at summersault.com
Thu Jun 12 10:10:55 EDT 2008


On Wed, 2008-04-16 at 10:38 -0600, Darin McBride wrote:
> On April 16, 2008 09:48:42 am Perrin Harkins wrote:
> > >  But if the AUTOLOAD problem is a bug that can be fixed
> > >  easily, then I'd rather do that than use this workaround.
> >
> > I have no idea if it's a bug or not, but a sub called AUTOLOAD has a
> > well-known meaning in Perl which you are not entirely following here,
> > and that seems very confusing to me.  It's kind of like wanting to
> > call your custom cleanup method DESTROY.
> 
> This looks like a minor bug to me - CA is reusing a well-known meme in a way 
> that doesn't quite work.  When I started using CA, the ability to just 
> specify runmodes and subs that were the same name didn't exist, so having 
> C<AUTOLOAD => \&catchall> was not any worse than also having to specify 
> C<myrunmode => \&myrunmode>.  Now, there is an indirect implicit suggestion 
> to use a sub called 'AUTOLOAD' to handle the 'AUTOLOAD' action, based on the 
> perldoc:
> 
>            Often, it makes good organizational sense to have your run modes
>            map to methods of the same name.  The array-ref interface provides
>            a shortcut to that behavior while reducing verbosity of your code.
> 
> My suggestion is that AUTOLOAD is not, and never has been, a runmode.  No one 
> should be able to load http://myapp.net/?rm=AUTOLOAD.  I've not tested to see 
> if that actually calls the AUTOLOAD runmode or not, but it shouldn't.  (I 
> suspect it does.)
> 
> Instead, if I want the fallback, I should not be setting a run_mode, I should 
> be setting a fallback:
> 
>             $self->fallback_mode('my_catchall_sub');
> 
> This is something that should be callable only in cases where the fallback is 
> required.
> 
> Something like this:

I don't plan to add this patch for the following reasons:

- As mentioned already, run_modes() is additive, you can use the
arrayref call for declaring most methods as a 1-to-1 mapping, and add *1
line of code* to declare the AUTOLOAD method if you need to. 

- error_mode() already works an awful lot like fallback_method().
Perhaps it could work for you? 

- Seeing that the current functionality of "AUTOLOAD" is "deprecated"
either means that we will continue to support two ways of doing the same
thing, which can make the documentation more verbose and confusing, or
we would drop support for the current functionality at some point, which
people have been using for several years, breaking backward
compatibility, but making the docs and code both simpler again. 

Overall, I don't find the change compelling enough to update the API.
But as usual, I will continue to listen the community conversation, and
am open to be swayed in my opinion if there is a strong feeling about
this from others.  

   Mark




More information about the cgiapp mailing list