Apache-ASP

 view release on metacpan or  search on metacpan

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

across every script:

<pre>
[header.inc]
&lt;html&gt;
&lt;head&gt;&lt;title&gt;Company Name&gt;&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;

[footer.inc]
Copyright / Disclaimer
&lt;/body&gt;&lt;/html&gt;

[sample.asp]
&lt;!--#include file=header.inc--&gt;
&lt;!-- main body of page here --&gt;
&lt;!--#include file=footer.inc--&gt;

</pre>
<h3>Powerful</h3>

When developing a web site under ASP, one has access to a complete 
set of objects and events, my favorite being $Session, which was one of ASP's
key selling points for me.  $Session is ASP's answer to the problem of HTTP being a 
stateless protocol.  By using temporary session cookies, each web user 
has a unique $Session in which you may store data, and that follows them from
script to script. Because the data storage
for $Session is handled on the server, you do not have to worry about
size limits of cookies as an alternate mechanism of storing user session data.
<p>
There are some very useful events as well.  Let's say that you are
using <tt>$Session->{login}</tt> to control a user account login and logout.  Because
$Session automatically times out every SessionTimeout, if a user
walks away from her/his computer for SessionTimeout minutes, the
<tt>$Session->{login}</tt> is destroyed along with the rest of the data stored in 
$Session, and the next person that uses the computer will find themselves
automatically logged out from the account.  This is a huge security win if 
you maintain a set of accounts at your web site that hold sensitive information like
credit card numbers.
<p>
Here is a basic listing of the built-in <a href=http://www.apache-asp.org/objects.html>objects</a> 
available to the developer within every <a href=http://www.apache-asp.org>Apache::ASP</a>
script:
<pre>
	Object		-	Function
	------			--------
	$Session	-	session state
	$Response	-	output
	$Request	-	input
	$Application	-	application state
	$Server		-	OLE support + misc.
</pre>

You might be looking at the $Application object as saying "huh, what's that?".
Simply, $Application allows you to share data between various ASP scripts
and users.  Metaphorically it represents your web site as an application,
and $Application is initialized when the first user $Session is created,
and destroyed when the last user $Session is destroyed.
<p>
Events are triggered when these objects are created and destroyed.
In addition to data initialization and destruction, these events allow
the developer to define, in the global.asa, subroutines to be executed 
at these event times, providing hooks enabling the web site
to function easily as a dynamic software application.  The 
<a href=http://www.apache-asp.org/events.html>events</a>
are as follows:
<pre>
	Action			Event
	------			------
        Script_OnStart *	Beginning of Script execution
        Script_OnEnd *		End of Script execution
	Application_OnStart	Beginning of Application
	Application_OnEnd	End of Application
	Session_OnStart		Beginning of user Session.
	Session_OnEnd		End of user Session.

  * These are API extensions that are not portable, but were
    added because they are incredibly useful
</pre>
<p>
<h3>Fast</h3>
Execution speed is always important when picking your web application
environment ... shoot for the stars and design with the fastest
from the beginning, saving yourself a massive redesign later when 
your site becomes a success.  One of the motivations for not using PerlScript 
under IIS, a couple years ago, was that it was painfully slow, but has since been 
much improved.  

The <a href=http://perl.apache.org>mod_perl</a> project boasts a 20 times
speedup in CGIs handled by Apache::Registry, and it 
handles perl ASP scripts just as well under Apache::ASP, with
some performance lost because of all the objects initialization and 
events execution that ASP handles.  
<p>
The startup overhead on simple scripts is significantly more
when moving from CGI to ASP under mod_perl for Apache, at least 20%,  
as shown in my previous 
<a href=http://chamas.com/bench/>Hello 
World - Web Application Benchmarks</a> article, but this startup overhead
will become relatively less important as your scripts get longer, and 
a base rate of 75 Apache::ASP requests per second on a PII 300 Solaris 
x86 is nothing to scoff at!
<p>
In order to justify using ASP over CGI despite the performance hit, 
just remember how much more <b>maintainable</b> and <b>powerful</b> ASP is.  The general
consensus is that developer time is much more valuable than 
computer time so save the former where possible!

<h3>Next Month</h3>
In this article I tried to convey a sense of how and why you might
use <a href=http://www.apache-asp.org/>Apache::ASP</a> to build
your web site.  Next month we will build a simple web site using
some of the powerful and modular features ASP has to offer.
</body>
</html>



( run in 0.459 second using v1.01-cache-2.11-cpan-39bf76dae61 )