Apache :: ASP
Web applications with Apache + mod_perl
  INTRO
  INSTALL
  CONFIG
  SYNTAX
  EVENTS
  OBJECTS
  SSI
  SESSIONS
  XML/XSLT
% CGI
  PERLSCRIPT
  FAQ
  TUNING
  CREDITS
  SUPPORT
  SITES USING
  RESOURCES
  TODO
  CHANGES
  LICENSE

  EXAMPLES

Powered by Apache::ASP
Powered by ModPerl and Apache
Powered by Perl
Links Checked by NodeWorks
CGI

CGI has been the standard way of deploying web applications long before
ASP came along.  CGI.pm is a very useful module that aids developers in
the building of these applications, and Apache::ASP has been made to
be compatible with function calls in CGI.pm.  Please see cgi.htm in the
./site/eg directory for a sample ASP script written almost entirely in CGI.
As of version 0.09, use of CGI.pm for both input and output is seamless when working under Apache::ASP. Thus if you would like to port existing cgi scripts over to Apache::ASP, all you need to do is wrap <% %> around the script to get going. This functionality has been implemented so that developers may have the best of both worlds when building their web applications.
Following are some special notes with respect to compatibility with CGI. Use of CGI.pm in any of these ways was made possible through a great amount of work, and is not guaranteed to be portable with other perl ASP implementations, as other ASP implementations will likely be more limited.

Query Object Initialization print()ing CGI
CGI headers File Upload

Query Object Initialization

You may create a CGI.pm $query object like so:
	use CGI;
	my $query = new CGI;
As of Apache::ASP version 0.09, form input may be read in by CGI.pm upon initialization. Before, Apache::ASP would consume the form input when reading into $Request->Form(), but now form input is cached, and may be used by CGI.pm input routines.

CGI headers

Not only can you use the CGI.pm $query->header() method
to put out headers, but with the CgiHeaders config option
set to true, you can also print "Header: value\n", and add
similar lines to the top of your script, like:
 Some-Header: Value
 Some-Other: OtherValue

 <html><body> Script body starts here.
Once there are no longer any cgi style headers, or the there is a newline, the body of the script begins. So if you just had an asp script like:
    print join(":", %{$Request->QueryString});
You would likely end up with no output, as that line is interpreted as a header because of the semicolon. When doing basic debugging, as long as you start the page with <html> you will avoid this problem.

print()ing CGI

CGI is notorious for its print() statements, and the functions in CGI.pm
usually return strings to print().  You can do this under Apache::ASP,
since print just aliases to $Response->Write().  Note that $| has no
affect.
	print $query->header();
	print $query->start_form(); 

File Upload

CGI.pm is used for implementing reading the input from file upload.  You
may create the file upload form however you wish, and then the
data may be recovered from the file upload by using $Request->Form().
Data from a file upload gets written to a file handle, that may in
turn be read from.  The original file name that was uploaded is the
name of the file handle.
	my $filehandle = $Request->Form('file_upload_field_name');
	print $filehandle; # will get you the file name
	my $data;
	while(read($filehandle, $data, 1024)) {
		# data from the uploaded file read into $data
	};
Please see the docs on CGI.pm (try perldoc CGI) for more information on this topic, and ./site/eg/file_upload.asp for an example of its use.
There is a $Request->FileUpload() API extension that you can use to get more data about a file upload, so that the following properties are available for querying:
  my $file_upload = $Request->{FileUpload}{upload_field};
  $file_upload->{BrowserFile}
  $file_upload->{FileHandle}
  $file_upload->{ContentType}

  # only if FileUploadTemp is set
  $file_upload->{TempFile}

  # whatever mime headers are sent with the file upload
  # just "keys %$file_upload" to find out
  $file_upload->{?Mime-Header?}
Please see the $Request section in OBJECTS for more information.
 
Copyright © 1998-2001, Joshua Chamas, Chamas Enterprises Inc.