up
Perl Lecture Notes - December 8 - last 1st trimester class
- Questions
- Housekeeping
- CGI Overview
- This is a simply a preview of where we'll start
next trimester.
- CGI stands for "Common Gateway Interface". In practice,
it means a "web application" - a program that runs on
the server to generate the web page.
- Example 1 : time.cgi (run it - source code) what time is it?
- What's going on:
- browser sends HTTPD to bob port 80, "GET time.cgi ..."
- apache deamon runs "./time.cgi", collects STDOUT
- apache returns that with headers : "HTTP/1.1 200 OK ..."
- The details include stuff like
- how to define apache's behavior - when it should do what
- how to pass in user input, typically from an HTML form
- how to return different kinds of stuff : text, html, images
- various techniques for cgi script itself (html within perl, perl within html, xml templates, ... )
- session management - tricks for remembering the visitor data
- various security issues
- ways of interacting with the filesystem and/or server-client database
- speed, number of connections, and scalability
- different web pages based on same content for browsers, PDA's, phones, ...
- getting inside the apache request cycle itself
- Here are a few more examples, to wet your appetite.
- Vanilla perl cgi scripts - perl program prints html
(Many times something like this is all you need.)
- On bob, all files ending in .cgi are
executed (as if from the command line), and
the output is the web page. Voila.
- apache configuration
- environment.cgi (run it - source code) displays %ENV hash -
raw inputs to the script
- form.html (run it - source html) demo of an HTML <FORM> block,
typical way to get user input
- slidingBlock.cgi (run it - souce code) a classic puzzle
- mod_perl
(For more speed or more in-depth control of request)
- On bob, all files ending with .cgimp are run
within mod_perl.
- apache configuration
- environment.cgimp (run it) symbolic link to same environment.cgi script
- slidingBlock2.cgimp (run it - source code) small changes for the mod_perl environment
- Another (big) example is the wiki, which
is one big .cgi or .cgimp perl script.
See the source at UseModWiki.pm.
- HTML::Mason - an html file with bits of perl within it
(When you're doing a whole web site.
Many, many similar tools : Embperl, TemplateToolkit, PHP, ColdFusion, ...)
- apache configuration
- mason handler
- The idea is that your
web pages are built from "components":
files whose html can be
embedded within each other and/or
treated like perl subroutines.
Arguments to the subroutines
are like name/value pairs passed in the URL.
Perl code is embedded with the HTML, either on
lines that start with % or within <%perl>
XML-ish tags.
I've set this up on bob as "file.mhtml" with a
built-in session management hash $session{key}.
Also, some file names are special: "autohandler"
is always called; "dhandler" is called if
a file isn't found.
Powerful systems, but each
takes time to learn...
- mason/sample.mhtml (run it - source code)
- mason/autohandler (source) - all files in this directory call this first
- mason/nofile.mhtml (see it - dhandler source
- mason/inner.mhtml?string=hello
(see it -
souce code)
call a mason component from its url
- (The online gradebook is an HTML::Mason application.)
- Readings (Entirely optional - we will be starting in
somewhere in here when the second trimester starts.)
- Assignment:
- Not this time. See you after the break...
Have you tried Acme::Bleach yet?