Apache-ASP

 view release on metacpan or  search on metacpan

site/events.html  view on Meta::CPAN

	<p>
	<a name=Application_61345d1d></a>
	<font face=verdana><font class=title size=+0 color=#555555><b>Application_OnStart</b></font>
<font face="courier new" size=3><pre>
</pre></font>This event marks the beginning of an ASP application, and 
is run just before the Session_OnStart of the first Session
of an application.  This event is useful to load up
$Application with data that will be used in all user sessions.</font>
	
	<p>
	<a name=Application_4bca009c></a>
	<font face=verdana><font class=title size=+0 color=#555555><b>Application_OnEnd</b></font>
<font face="courier new" size=3><pre>
</pre></font>The end of the application is marked by this event, which
is run after the last user session has timed out for a 
given ASP application.</font>
	
	<p>
	<a name=Server_OnSta0d174f59></a>
	<font face=verdana><font class=title size=+0 color=#555555><b>Server_OnStart ( pseudo-event )</b></font>
<font face="courier new" size=3><pre>
</pre></font>Some might want something like a Server_OnStart event, where
some code gets runs when the web server starts.  In <a href=http://perl.apache.org><font size=-1 face=verdana><b>mod_perl</b></font></a>,
this is easy to achieve outside of the scope of an ASP
application, by putting some initialization code into
a &lt;Perl&gt; section in the httpd.conf file.  Initializations
that you would like to be shared with the child httpds are
particularly useful, one such being the Apache::ASP-&gt;Loader() 
routine which you can read more about in the <a href=tuning.html><font size=-1 face=verdana><b>TUNING</b></font></a> section -
Precompile Scripts subsection. It is could be called like:
<font face="courier new" size=3><pre>
  # httpd.conf
  &lt;Perl&gt;
     Apache::ASP-&gt;Loader($path, $pattern, %config)
  &lt;/Perl&gt;
</pre></font>So a &lt;Perl&gt; section is your Server_OnStart routine!</font>
	
	<p>
	<a name=mod_perl%20han02da5c9c></a>
	<font face=verdana><font class=title size=+0 color=#555555><b>mod_perl handlers</b></font>
<font face="courier new" size=3><pre>
</pre></font>If one wants to extend one&#39;s environment with <a href=http://perl.apache.org><font size=-1 face=verdana><b>mod_perl</b></font></a>
handlers, Apache::ASP does not stop this.  Basic
use of Apache::ASP in fact only involves the content
handler phase of mod_perl&#39;s PerlHandler, like
<font face="courier new" size=3><pre>
  SetHandler perl-script
  PerlModule Apache::ASP
  PerlHandler Apache::ASP 
</pre></font>But mod_perl allows for direct access to many more
Apache event stages, for full list try &quot;perldoc mod_perl&quot;
or buy the mod_perl Eagle book.  Some commonly used ones are:
<font face="courier new" size=3><pre>
  PerlInitHandler
  PerlTransHandler
  PerlFixupHandler
  PerlHandler
  PerlLogHandler
  PerlCleanupHandler
</pre></font>For straight Apache::ASP programming, there are some 
equivalents, say Script_OnStart event instead of Init/Fixup
stages, or $Server-&gt;RegisterCleanup() for Log/Cleanup stages,
but you can do things in the mod_perl handlers that you 
cannot do in Apache::ASP, especially if you want to handle
all files globally, and not just ASP scripts.
<font face="courier new" size=3><pre>
</pre></font>For many Apache::* modules for use with mod_perl, of which
Apache::ASP is just one, check out
<a href=http://perl.apache.org/src/apache-modlist.html>http://perl.apache.org/src/apache-modlist.html</a>
<font face="courier new" size=3><pre>
</pre></font>To gain access to the ASP objects like $Session outside
in a non-PerlHandler mod_perl handler, you may use this API:
<font face="courier new" size=3><pre>  
  my $ASP = Apache::ASP-&gt;new($r); # $r is Apache-&gt;request object
</pre></font>as in this possible Authen handler:
<font face="courier new" size=3><pre>
  &lt;Perl&gt;
    use Apache::ASP;
    sub My::Auth::handler {
      my $r = shift;
      my $ASP = Apache::ASP-&gt;new($r) 
      my $Session = $ASP-&gt;Session;
    }
  &lt;/Perl&gt;
</pre></font>Here are some examples of do-it-yourself mod_perl
handler programming...
<font face="courier new" size=3><pre>
 === Forbid Bad HSlide User Agent ===

 # httpd.conf
 PerlAccessHandler My::Access
 &lt;Perl&gt;
   sub My::Access::handler {
     my $r = shift;
     if($r-&gt;headers_in-&gt;{&#39;USER_AGENT&#39;} =~ /HSlide/) {
	 403;
     } else {
	 200;
     }
   }
 &lt;/Perl&gt;

 === Runtime Path Parsing ===
</pre></font>This example shows how one might take an arbitrary
URL path /$path/$file.asp, and turn that into a runtime 
config for your site, so your scripts get executed
always in your sites DocumentRoot.
<font face="courier new" size=3><pre>
 INPUT URL /SomeCategory/
 OUTPUT
  Script: index.asp
  $Server-&gt;Config(&#39;PATH&#39;) eq &#39;/SomeCategory&#39;

 INPUT URL /SomeCategory/index.asp
 OUTPUT
  Script: index.asp
  $Server-&gt;Config(&#39;PATH&#39;) eq &#39;/SomeCategory&#39;

 INPUT URI /index.asp
 OUTPUT
  Script: index.asp



( run in 0.426 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )