CGI Programming with Perl
From Dev411: The Code Wiki
Perl remains popular with CGI programming however there are now better and higher performance methods to develop web applications with Perl. One of the most popular alternatives to CGI is mod_perl, a persistent Perl interpreter that can be incorporated into the Apache web server. If you are programming CGI with Perl today, ideally your scripts would be compatible with both CGI and mod_perl's ModPerl::Registry module (or Apache::Registry with mod_perl < 1.99). This would allow your scripts to run unchanged under CGI or mod_perl's higher performance configuration.
Best Practices
Here are some best practices guidelines:
- Always design your Perl CGI scripts to run under both CGI and mod_perl using ModPerl::Registry for small applications. This can be accomplished following just a few guidelines.
- Use a Perl web application framework for medium to large applications. A framework will typically ensure your application runs under both mod_cgi and mod_perl; as long as your application works with the framework, it will work with mod_perl. There are a variety of frameworks with different features. Some do more and restrict your freedom while others do less and give you more flexibility. Some example Perl web application frameworks are CGI::Application, HTML::Mason, Catalyst, and OpenInteract.
- Use a templating system to generate your HTML in order to separate your display code from your application code. This is especially useful if you have dynamically generated HTML pages share a lot of similar HTML. It is also useful if your HTML design staff is separate from your Perl coding staff.
- Leverage CPAN to get modules for other useful areas such as session management, database abstraction, HTML forms abstraction, input filtering, CGI parameter parsing, and caching. Some of the Perl web application frameworks have plugin wrappers to easily incorporate popular support modules.
See Also
Writing Scripts for mod_perl Registry
Further Reading / External Links
Where and how to start learning Perl (PerlMonks.com) (http://www.perlmonks.org/index.pl?node_id=284175)
