Apache-ASP

 view release on metacpan or  search on metacpan

site/articles/perlmonth2_build.html  view on Meta::CPAN


<html>
<head><title>Apache::ASP Site Building</title></head>
<bgcolor=white>
<h2>Apache::ASP Site Building</h2>
<h3>By: Joshua Chamas</h3>
<i>published originally in PerlMonth.com in 1999</i>
<p>

Last month,
I gave a rough introduction of <a href=http://www.apache-asp.org/>Apache::ASP</a>, 
and why you might want to use it to build your web site.  
Now I get to show you Apache::ASP in action.

<h3>Requirements</h3>
First, we must decide what our site will do, or 
state its requirements.  As a trivial site,
we are going do build something my.*.com style, which 
holds a user's favorite links, a MyBookmarks site
if you will.  
<p>
This site will require a user to login
with a chosen user name for security, 
and view, add, and delete their internet bookmarks.  
The deletion will leave the deleted bookmark data in the form to allow
easy modification and recreation of that bookmark.
<p>
The user will also be able to logout, and the system
will auto-logout their account automatically after 
15 minutes, so that if it is a public terminal, another user using the 
same browser later will not be able modify the 
first user's bookmarks. 
<p>

<h3>Specification</h3>
Often times, there is a specification round that we
must do to pick our web application environment and 
hardware, as well as supported client software, but this is a no 
brainer here.  We are choosing Apache::ASP because of its built 
in <tt>$Session</tt> which make user logins easy, and its built 
in event <tt>Session_OnEnd</tt> which will automatically destroy 
the contents of <tt>$Session</tt> every <tt>SessionTimeout</tt>, which 
defaults to 20 minutes.
<p>
Also, because our web application has more than one page, we 
will make use of the same headers and footers for each
page, using the includes <tt>&lt;!--#include file=src.inc--&gt;</tt>
functionality to modularize the html.

<h3>Design</h3>
Before we start coding, let's take a minute to diagram
what pages and actions our MyBookmarks web application 
needs to have.  We have 2 pages, the intro, and the 
actual bookmarks page, where we get to view, add, and 
delete the bookmark entries.  We have the user login to 
the bookmarks, and logout, securing access for the user's 
eyes only.
<p>
<center><img src=flow.gif border=0></center>
<p>
You might also design the objects, methods, and functions
that will be used for the site, but this site is so 
simple, that we are going to jump into implementation.

<h3>Implementation</h3>
We start by configuring <tt>.htaccess</tt> file 
of a directory in apache to allow Apache::ASP
to run <tt>.asp</tt> files, and testing the configuration
with a <tt>dummy.asp</tt> file.


	<p>
	<center>
	<table border=0 cellspacing=0 width=90% >
	<tr bgcolor=gray><td><font color=white><b># .htaccess</b></td></tr>
	<tr bgcolor=#c0c0c0><td><pre>
<tt>DirectoryIndex index.asp
&lt;Files ~ \.asp$&gt;
	SetHandler perl-script
	PerlHandler Apache::ASP
	PerlSetVar Global .
	PerlSetVar GlobalPackage My::Bookmarks
	PerlSetVar StateDir /tmp/asp_apps_bookmarks
	PerlSetVar Debug 2
	PerlSetVar SessionTimeout 15
	PerlSetVar StatScripts 1
	PerlSetVar AllowApplicationState 1
	PerlSetVar AllowSessionState 1
&lt;/Files&gt;</tt></pre></td></tr>
	</table>
	</center>
	<p>
	

	<p>
	<center>
	<table border=0 cellspacing=0 width=90% >
	<tr bgcolor=gray><td><font color=white><b># dummy.asp</b></td></tr>
	<tr bgcolor=#c0c0c0><td><pre>
<tt>INTRO &lt;%=$Session%&gt;</tt></pre></td></tr>
	</table>
	</center>
	<p>
	

If the index.asp works on your server, and just prints
<tt>INTRO Apache::ASP::Session=HASH(0x??????)</tt>, 
then we know Apache::ASP is working and $Sessions are 
enabled.

<hr size=1>

Next, we set up the <tt>global.asa</tt> with globals and 
libraries that need to be initialized for the web 
application, and define the relevant event handlers.  
We also set up per request globals, like the document's 
title, which is something that we can do in 
<tt>Script_OnStart</tt>.  Finally, we use
the <tt>Script_OnStart</tt> and <tt>Script_OnEnd</tt>
events to automatically include the header and footer
for each script in our web application, and initialize
relevant globals used by the scripts.
<p>
Notice that each script can process its own <tt>Logout</tt>
request, which was a decision made after the design
because it seemed good to make the first script, <tt>index.asp</tt>,
<tt>$Session</tt> aware.

	<p>
	<center>
	<table border=0 cellspacing=0 width=90% >
	<tr bgcolor=gray><td><font color=white><b># global.asa</b></td></tr>
	<tr bgcolor=#c0c0c0><td><pre>
<tt>use File::Basename;
use DBI;
use DBD::CSV;

use vars qw( $DarkColor $Name %Titles $FontBase $Db $Title $Basename $Form $Query );

$DarkColor = &#39;#0000aa&#39;;
$Name = &quot;MyBookmarks&quot;;
%Titles = (
	   &#39;index.asp&#39; =&gt; &#39;Introduction&#39;,
	   &#39;bookmarks.asp&#39; =&gt; &#39;Viewer&#39;
	  );

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.698 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )