[cgiapp] New Plugin: RunmodeDeclare

Rhesa Rozendaal perl at rhesa.com
Tue Oct 21 08:25:06 EDT 2008


Richard Jones wrote:
> Rhesa Rozendaal wrote:
> 
>> Version 0.03 is on CPAN now, and adds this feature:
>>
>>   use CGI::Application::Plugin::RunmodeDeclare invocant => '$c';
>>
>>   runmode foo { $c->bar }
>>
>> It also incorporates the suggestion by Mark and Michael to first default 
>> to $app->param, then to $query->param.
> 
> So, having had chance to have a play with it, I've run into a couple of 
> problems. First, all subclasses need to 'use 
> CGI::Application::Plugin::RunmodeDeclare' - it is not inherited from the 
> superclass as are all other CAP's. Attempts to run against a subclass 
> without the 'use CAP::RunmodeDeclare' causes a syntax error. Not a 
> problem as such, but seems odd.

It's not object oriented, so there's nothing to inherit. It's no different 
from "use strict" in that sense.

As far as I know, there aren't any hooks in Perl's OO system I could use to 
make this work as a real plugin. For instance, "use base 'Foo';" doesn't call 
Foo's import().

> Second, the superclass startmode seems to override the subclass 
> startmode. With a setup where My::WebApp::Foo subclass inherits from 
> My::WebApp superclass, a request to /myapp.cgi that maps to 
> My::WebApp::Foo should display the subclass startmode template, but it 
> doesn't - it loads the template defined in the superclass startmode 
> instead. Specifying the rm eg /myapp.cgi?rm=rm1 does work as expected 
> though - loads My::WebApp::Foo::rm1 template.
> 
> I know I could specify the required rm in all requests 
> (myapp.cgi?rm=start), but I'm using Dispatch where :app and :app/:rm are 
> used in the dispatch table, and this works as documented with 
> CAP::AutoRunmode - ie the subclass StartRunmode 'wins'.

Yeah, a runmode named "start" is treated differently by cgiapp, and I've 
already filed a bug report for it: http://rt.cpan.org/Ticket/Display.html?id=39631
Right now, every other name than "start" as startmode will work just fine.

rhesa.


More information about the cgiapp mailing list