Rapid Website Development with CGI::Application
by Mark Stosberg
|
Pages: 1, 2, 3, 4
Easy Form Handling
A lot of tedium can be involved in processing web forms. The first plugin, ValidateRM, helped with that.
my $results = $self->check_rm('display_form', '_form_profile' )
|| return $self->dfv_error_page;
This simple syntax calls a Data::FormValidator profile into action. If validation fails, the page with the original form is redisplayed with the previous values intact, and error messages appear next to each field that is missing or invalid.
Fans of Data::FormValidator will appreciate an upcoming related module from the CGI::Application community: JavaScript::DataFormValidator.
This module makes it easy to use the same Perl data structure to add an additional level of validation in JavaScript. I expect Catalyst and CGI::App users alike will be putting this to use.
Finally, there's a new plugin to simplify filling in a web form from a database record. This is the FillInForm plugin. The syntax is simple:
# fill in the HTML form from the query object
$self->fill_form($html);
In part, this plugin solves bug #13913 in HTML::FillInForm, which means the interface detects what kind of input you are giving it, rather than requiring you to explicitly declare that you have hashref or scalarref and so forth. As you can see from the example, if you are using the query object as input, you don't need to pass it in at all.
DevPopUp: A Unique Developer Tool
CGI::Application offers a unique developer tool in the form of the DevPopUp plugin. You can see DevPopUp in action on Rhesa's demo site. (Make sure your pop-up blocker doesn't trap it!).
The tool creates a persistent pop-up window that gives you feedback about each run mode as soon as it completes. "What were the HTTP Headers? How long did it take? Was the resulting HTML valid?"
The real kicker is that DevPopUp is itself pluggable, allowing other developers to add their own reports. I look forward to Sam Tregar releasing his graphical DBI profiling tool, which would make a nice addition here.
Easier Error Messages with DebugScreen
CGI::Application users in Japan recently brought us the DebugScreen plugin. This is a welcome change from referencing the web server log to find the most recent line that needs debugging.
Hello, Web 2.0: AJAX Integration
In another story of cross-pollination with Catalyst, CGI::Application integrates easily with the JavaScript Prototype library. Prototype provides easy access to plenty of interesting AJAX effects, such as auto-completing based on a lookup to the server. This uses a thin plugin-wrapping HTML::Prototype, which was written with Catalyst in mind.
CGI::Application and Catalyst
The appearance of Catalyst has been a great benefit to the CGI::Application community. Both projects support the use and development of focused, reusable components. When a new patch arrives for a module both projects use, both projects benefit. As the maintainer of Data::FormValidator, I'm well aware that the two camps are collaborating through this project.
Catalyst releases its code under a license that allows CGI::Application to reuse and integrate their work (and vice-versa). Often a plugin written for Catalyst takes only a little effort to port to work with CGI::Application. For example, Catalyst recently added PAR support, which allows the distribution and execution of a complex web application as a single binary. This helps a Perl project with complex module dependencies compete with the installation ease of typical PHP software.
This will be a great reference as CGI::Application users evaluate options for easier web application deployment.
Finally, Catalyst demonstrates an alternate approach as a web framework. This helps the CGI::Application community better evaluate their own options.
Conclusion
CGI::Application has always been about providing a clean structure for web applications. With the advent of myriad plugins, it is also about simplifying access to the many great tools that Perl offers web developers through the CPAN. With more plugins being developed on a regular basis, the life of the web developer is getting easier by the day.
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 1 of 1.
- I <3 CGI::Application
2006-10-23 13:40:24 mjg [Reply]
I've been using CGI::Application with DBIx::Class and Template Toolkit to create MVC-style apps, but I appreciate that it doesn't impose that architecture if I don't need it. Thanks to everyone involved for developing this framework while still retaining that focus.



