Apache-ASP
view release on metacpan or search on metacpan
site/cgi.html view on Meta::CPAN
to date has only been done with mod_cgi scripts under Apache on a
Unix platform, and it is unlikely to work under other web servers
or Win32 operating systems without further development.
<font face="courier new" size=3><pre>
</pre></font>To run the ./site/eg scripts as CGI scripts, you copy the
./site directory to some location accessible by your web
server, in this example its /usr/local/apache/htdocs/aspcgi,
then in your httpd.conf activate Apache::ASP cgi
scripts like so:
<font face="courier new" size=3><pre>
Alias /aspcgi/ /usr/local/apache/htdocs/aspcgi/
<Directory /usr/local/apache/htdocs/aspcgi/eg/ >
AddType application/x-httpd-cgi .htm
AddType application/x-httpd-cgi .html
AddType application/x-httpd-cgi .asp
AddType application/x-httpd-cgi .xml
AddType application/x-httpd-cgi .ssi
AllowOverride None
Options +ExecCGI +Indexes
</Directory>
</pre></font>Then install the asp-perl script from the distribution
into /usr/bin, or some other directory. This is
so the CGI execution line at the top of those scripts
will invoke the asp-perl wrapper like so:
<font face="courier new" size=3><pre>
#!/usr/bin/perl /usr/bin/asp-perl
</pre></font>The asp-perl script is a cgi wrapper that sets up the
Apache::ASP environment in lieu of the normal mod_perl
handler request. Because there is no Apache->dir_config()
data available under mod_cgi, the asp-perl script will load
a asp.conf file that may define a hash %Config of
data for populating the dir_config() data. An example
of a complex asp.conf file is at <a href=eg/asp.conf>./site/eg/asp.conf</a>
<font face="courier new" size=3><pre>
</pre></font>So, a trivial asp.conf file might look like:
<font face="courier new" size=3><pre>
# asp.conf
%Config = (
'Global' => '.',
'StateDir' => '/tmp/aspstate',
'NoState' => 0,
'Debug' => 3,
);
</pre></font>The default for NoState is 1 in CGI mode, so one must
set NoState to 0 for objects like $Session & $Application
to be defined.</font>
<p>
<a name=CGI.pm></a>
<font face=verdana><font class=title size=+0 color=#555555><b>CGI.pm</b></font>
<font face="courier new" size=3><pre>
</pre></font>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 <a href=cgi.html><font size=-1 face=verdana><b>CGI</b></font></a>.
<font face="courier new" size=3><pre>
</pre></font>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.
<font face="courier new" size=3><pre>
</pre></font>For more information about CGI.pm, please see the web site
<font face="courier new" size=3><pre>
<a href=http://search.cpan.org/dist/CGI/>http://search.cpan.org/dist/CGI/</a>
</pre></font>
<p>
<a name=Query%20Object4fef5875></a>
<font face=verdana><font class=title size=+0 color=#555555><b>Query Object Initialization</b></font>
<font face="courier new" size=3><pre>
</pre></font>You may create a <a href=http://stein.cshl.org/WWW/software/CGI/cgi_docs.html><font size=-1 face=verdana><b>CGI.pm</b></font></a> $query object like so:
<font face="courier new" size=3><pre>
use CGI;
my $query = new CGI;
</pre></font>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.</font>
<p>
<a name=CGI%20headers></a>
<font face=verdana><font class=title size=+0 color=#555555><b>CGI headers</b></font>
<font face="courier new" size=3><pre>
</pre></font>Not only can you use the <a href=http://stein.cshl.org/WWW/software/CGI/cgi_docs.html><font size=-1 face=verdana><b>CGI.pm</b></font></a> $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:
<font face="courier new" size=3><pre>
Some-Header: Value
Some-Other: OtherValue
<html><body> Script body starts here.
</pre></font>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:
<font face="courier new" size=3><pre>
print join(":", %{$Request->QueryString});
</pre></font>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.</font>
<p>
<a name=print%28%29ing%20C99232b52></a>
<font face=verdana><font class=title size=+0 color=#555555><b>print()ing CGI</b></font>
<font face="courier new" size=3><pre>
</pre></font>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.
<font face="courier new" size=3><pre>
print $query->header();
print $query->start_form();
</pre></font>
<p>
<a name=File%20Upload></a>
<font face=verdana><font class=title size=+0 color=#555555><b>File Upload</b></font>
( run in 0.702 second using v1.01-cache-2.11-cpan-39bf76dae61 )