[cgiapp] CGI::Application status update from the maintainer
Ron Savage
ron at savage.net.au
Thu Sep 6 19:52:46 EDT 2012
Hi Brett
On 07/09/12 00:48, B. Estrade wrote:
> What I mean is that there are 2 methods that basically do the same
> thing. If you have MyApp (ISA CGI::Application), you would initialize
> runmodes and whatnot via cgiapp_init. Say you subclass MyApp to get
> MyApp::Foo, but want to keep what is going on in MyApp::cgiapp_init;
> but you have your own specific MyApp::Foo runmodes. You'd most cleanly
> do this by defining MyApp::Foo::setup. Now, what if you want to
> subclass MyApp::Foo into MyApp::Foo::Derp, but you have some Derp
> specific runmodes. You end up having to redefine cgiapp_init or
> setup; in either case, you're going to have to make an explicit call
> to SUPER::cgiapp_init or SUPER::setup.
>
> You're limited to 2 generations below CAP if you want to subclass
> without explicitly calling on SUPER because you have 2 explicit
> methods -cgiapp_init and setup. I am suggesting a way to provide any
> number of generations without having to call on SUPER.
Rhesa has replied with one (slightly more complex) way of doing things.
Here is another:
package WebCommon;
use base 'CGI::Application';
sub cgi_init # or setup
{
$self -> web_common_init;
}
package WebAPI;
use base 'WebCommon';
sub cgi_init # or setup
{
$self -> web_api_init;
}
package WebAPI::Stuff;
use base 'WebAPI';
sub cgi_init # or setup
{
$self -> web_api_stuff_init;
}
The 3 new subs can be stand-alone or call each other or call common
code. They can do whatever you think best.
The point is that the sub-class cgi_inits are overridden by the /normal/
operation of CAP, and hence are called at the appropriate time
/automatically/.
Obviously you can call SUPER::cgi_init or SUPER::anything if you wish.
(Sometimes of course calling a super class's method is mandatory. For
instance, with CGI::Snapp, a sub-class must call SUPER::_init($arg), as
in the demo. But that's to initialize object-level variables, having
nothing to do with what we're talking about.)
The problem is that SUPER::* is a way of sharing /all/ the code in the
super class's cgi_init.
If you don't wish to do that, then do as I've indicated above, and just
share none or some of the code via web_common_init etc. You really do
have a variety of ways to work.
Lastly, there is no limit on the depth of nesting possible.
--
Ron Savage
http://savage.net.au/
Ph: 0421 920 622
More information about the cgiapp
mailing list