Best Perl Method for CGI Programming

pudge on 2000-04-20T14:44:17

Maclir writes: There seem to a a number of ways of building CGI programs with perl; CGI.pm , the other CGI:: modules, HTML::Embperl, HTML::Mason. I have played around with CGI.pm and embedded parl (HTML::Embperl), and there are good and bad points with both.

What is the collected experiences and recommendations of the "use Perl;" community? (I can do without the "Python rulez" or "PHP is much better" comments - that is why I asked here and not on ./ :-) )

ADVA-thanks-NCE


use CGI;

chip on 2000-04-20T15:14:42

Lincoln is a Very Smart Guy, and CGI.pm is, IMO, required usage for any non-trivial CGI program.

My only beef with CGI.pm is that it mixes two technically distinct feature sets into one module: The HTTP/CGI protocol complex (parameters in, URL handling, content out) and HTML (fonts, tables, etc.).

But that said, even if you only need the parameter parsing, it's madness to try to roll your own code instead of using CGI.pm. There are just too many weird rules and exceptions in the CGI and HTTP specs. And that's kind of what code reuse is supposed to help us with, right?!

TMTOWTDI

jjohn on 2000-04-21T10:30:42


You may want to pick this quarter's Perl Journal
for an article I wrote on HMTL::Mason. Mason
is a *great* tool for separating form and
functionality from CGI (ala ASP, ColdFusion, JSP, et al).
You'll need mod_perl and a bit of
Apache configuration to get this running.

That said, mod_perl and the CGI module alone are,
in my Mass-Hole venaculuar, wicked powerful.
In many ways, they are all you really need.
Check out the CPAN nearest you for the Apache*
modules, like Apache::Session.

For just blunt tools, I used plain old CGI.pm for
my http://aliensaliensaliens.com site. I created
a web front end with web admin tools for a mysql
database.

You may want to look at http://www.webtechniques.com
for more general overview of web technologies.
As great as Perl is, there are other web tools
that bear investigation.

Which CGI/HTML system?

gnat on 2000-04-21T15:57:34

CGI.pm is a good general purpose workhorse. Some people like the CGI::Lite types of modules where the functionality is limited to simply decoding the form parameters, leaving aside the HTML generation shortcuts.

It all comes down to "how do you want to mix your code and your HTML?" CGI.pm has shortcuts to generate HTML, but this means that you must change your program to change the HTML it produces. Most folks don't want to give their idiot cow orkers the ability to edit their code, nor do we trust idiot cow orkers to able to write Perl to make HTML when they have enough problems "programming HTML" as it is.

HTML::EmbPerl is a reversal: instead of putting HTML into your programs, you put Perl into your HTML. The files are processed by the web server and their output is sent back to the browser.

Mason and the Template toolkit are the next level up from EmbPerl. While HTML::EmbPerl generates one page, it doesn't have very good facilities for combining pages. Mason and Template.pm are excellent for building component-based websites. These are website where you have pages with common elements: nav bar, ad line, search box, personalised links, etc. Each of these things becomes a component and you can easily build pages made from these components.

When I write a single CGI program, I use CGI.pm. I either use CGI.pm's HTML shortcuts or I use a simple template system like Text::Template or my own s///. When I have to build an integrated system of web pages, then I use Template or Mason.

Nat

CGI.pm

gbarr on 2000-04-24T21:36:52

While there are many people who would swear by this module, I do feel that sometimes it is used just because it is well known. This maybe because it was the first, or maybe because it is so complete. But I must say that I have rarely been satisfied with any results I have had from it.

I would agree that if you want to parse parameters then rolling your own is madness and reusing something that is already there is the best solution. But the many uses I have seen of CGI.pm are for generating HTML, which is where the module is at it's weakest if what you are trying to generate is slightly complex.

IMO, for this a template module is far easier to use and maintain. Personally I have used the Template-Toolkit and Text::Template modules, but I have also looked at HTML::Mason although I have not used it yet.