Listing 4: wrapper.pl, a simple program that expects to receive the
name of a Perl/HTML template in the query string. Any Perl in that
template is evaluated, turning the file into an HTML document that is
returned to the user's browser.

#!/usr/bin/perl -w

use strict vars;
use diagnostics;
use CGI;     # see http://www.perl.com/CPAN
use Mysql;
use Text::Template;

# Create an instance of CGI
my $query = new CGI;

# Send an appropriate HTTP header
print $query->header("text/html");

# Get the filename from the query string
my $filename = $query->param("keywords");

# Log an error if the file doesn't exist
&log_and_die("Could not find the file \"$filename\"!") 
 unless (-s $filename);

# Create an instance of Text::Template
my $template = new Text::Template("type" => "FILE",
				 "source" => $filename);

# Evaluate the Perl inside the template, and send the results
# to the user's browser
$VARS::query = $query;
print $template->fill_in('package' => VARS);
exit;

sub log_and_die
 {
  my $message = shift;
  
  print $query->start_html(-title => "Error!");
  print $message;
  print $query->end_html;
  
  die $message;
}


