Overview
The workshop will cover
using the CGI.pm module to generate HTML,
handle HTML form input,
and simulate http state management with cookies.
Intended Audience
Anyone interested in simplifying web development tasks. Attendees will be
assumed to have a basic knowledge of Perl, http, and HTML forms.
Outline
- CGI.pm context and CGI overview.
The Common Gateway Interface allows a web server to speak with another process to extend the server's functionality.
Most CGI programs, which enable us to easily develop interactive, dynamic web sites, are written in Perl. We'll discuss why.
Although you can handle CGI interactions by hand,
Lincoln Stein's CGI.pm module makes it easy to handle HTML form input, generate output, and simulate state.
- Using CGI.pm to generate _valid_ html.
As web pages become increasingly complex and dynamically driven from data sources,
the need to have properly formatted HTML is more important than ever.
Oh the horror! of poorly nested tags.
We'll explore CGI.pm's HTML-generating shortcuts-- they'll save you typing and debugging your HTML with a validator.
- Generating forms to collect user input.
We'll explore using CGI.pm's shortcuts,
which are more logical to use than <tag>s,
to generate our forms.
- Handling user input.
As anyone who's ever hand-parsed input
or had to deal with a form element that could contain multiple values (like <select multiple>) knows,
handling input can be tedious.
CGI.pm's param() method and its built in support for storing input as arrays when necessary make handling your form input easy!
- Developing multipart/pass-through forms.
One of the drawbacks of the Web is its lack of state:
web browsers and servers too easily forget about the discussion they had 3 pages back.
CGI.pm lets us have an easier time developing forms that "remember" data.
- Using cookies to simulate state maintenance.
Cookies, small pieces of text data stored on the client machine,
allows us to simulate state even after a user leaves our site and shuts down her browser.
CGI.pm has built-in support for cookies, and we'll explore how to use it.
- Misc topics: file uploads, generating http headers,
integration with mod_perl, PerlEx,
migrating from cgi-lib.pl or hand-parsing.
We'll examine how to handle uploaded files with CGI.pm,
generate http headers,
improve performance of vanilla CGI
with mod_perl for Apache and PerlEx for Win32 servers,
transition from older scripts,
integration with DBI.pm, LWP, and other modules,
and a variety of other tricks.
- object- v. function- syntax.
CGI.pm lets you import methods into your namespace,
saving explicitly instantiating and specifying your object with every method call.
Workshop Materials
Materials for the workshop,
including speaker's notes and demonstration files,
are available at
http://www.westlake.com/yapc/cgi_talk/.