On Dec 15, 10:06*am, Justin C <justin.1...@purestblue.com> wrote:
> Has CGI.pm come to the end of it's usefulness?
I've used CGI.pm since around 1999 to build many web sites. In the
past several years, I've used it extensively at work to build
graphical interfaces to databases. FWIW, here's my opinion.
I have never, repeat never, used CGI to construct outgoing HTML. I
write the HTML by hand, typically putting it into a module in the
application directory named HTML.pm, and write the HTML fragments
using qq(), here docs, or similar, sometimes just using print(). I
started doing this in the beginning because I was frustrated
integrating CSS and JavaScript with CGI, and it was just easier for me
to do it this way.
For my database connections, I typically write a module called SQL.pm,
and call that as well. For the programmatic aspects, I write a module
named after the application, and call that as well.
I have never used anything other than CGI to handle HTTP requests in
my scripts, and I've never had a complaint.
My web apps wind up looking a lot like this:
use strict;
use warnings;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use HTML;
use SQL;
use APP; #this is my program code
use DBI: #if needed
use Mail::Sendmail #if needed
use MIME::Lite #if needed
use PDF::API2 #if needed
....
my $what = param('what');
....
elsif($what eq 'Request Employee Data')
{
my $queryresults = SQL::employee_select($what); #returns hash ref
my $returnvalues = APP::employee_select($queryresults); #builds data
my $formattedoutput = HTML::employee_select($returnvalues); #returns
HTML as a string
}
....
else { $formattedoutput = HTML::default_page(); } #user didn't make
any request
#main logic
HTML:

rint_header(...);
HTML:

rint_body($formattedoutput);
HTML:

rint_footer(...);
exit(0);
Obviously, there are better ways to do this, using dispatch tables is
one that I am presently experimenting with, but this has worked well
for me in that it's conceptually simple, easy to write, easy to
maintain, modular, and reliable.
Monday of this week, I bashed out a web app in about eight hours
(using SQLite) mostly without having to refer to any documentation,
using exactly this kind of structure. If you do it a lot, as I have,
you can do it with your eyes closed. I'm sure that a seasoned .NET
programmer using Visual Studio could probably do it in half the time,
but the typical PHP or ColdFusion guy would take twice as long, and
IMO Perl/CGI beats them all for cost, reliability, and simplicity.
CC