The docs discuss the idea of having a “base” module (say, MyBase.pm) that inherits from C::A and that your cgi app inherits from that. MyBase.pm takes care of common setup e.g. the query, state, config, db and could therefore be used by many/all of your cgi apps. But only cgi specific setup. My experience is that you are tempted to get too clever and add too much and you will regret it.
Your cgi app then only has to worry about run modes. The run modes take any input from the query, session or config and calls the application proper. The app returns a data structure and the run mode saves any session data and drops the appropriate param into an HTML::Template. The application api accepts input, returns output and is blissfully unaware of who or what has called it. The run mode is short and simple, it has no clue as to what the application does.
MyBase.pm is easy to test (and the simpler it is the better), once it is working you can forget about it. A dummy app can test the run modes - checking that the correct input is supplied and can handle results correctly (this where you can tweak your html).
The big gain in my opinion is that a non cgi instance script can now test your application while you develop it without having to worry about anything cgi related (httpd, query, state, html etc.). Nail down the api, once that is hammered out you'll know what run modes you need and what they need to do. If the api includes methods like $app->is_success, $app->session_data, $app->HT_tmpl, $app->HT_param etc. the run mode can easily handle any house keeping chores.
All the serious work, all the heavy lifting is done by the application which is, I believe, the best place to do it. I've found that this “separation of concerns”, where cgi is used purely as a front end to a separate, stand alone application can help enormously with speed of development and maintenance of my cgi apps.
Skinny run modes; not rocket science but can make a big difference.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Taking your application out of CGI::Application (skinny run modes)
by derby (Abbot) on May 04, 2009 at 11:55 UTC | |
|
Re: Taking your application out of CGI::Application (skinny run modes)
by merlyn (Sage) on May 04, 2009 at 16:23 UTC | |
by ysth (Canon) on May 05, 2009 at 09:16 UTC | |
by merlyn (Sage) on May 08, 2009 at 20:27 UTC |