Apache2::ASP::GlobalASA - Base class for your GlobalASA
package DefaultApp::GlobalASA; use base 'Apache2::ASP::GlobalASA'; use vars qw($Request $Response $Session $Application $Server $Form); # Override any methods here: # Executed at the beginning of *every* ASP script: sub Script_OnStart { warn "Starting up script!"; }# end Script_OnStart() # # Special error-handling method: sub Script_OnError { my $err; # Log the error: warn "[" . localtime() . "] An error has occurred: " . $err; # Print something friendly: $Response->Write("Sorry for the inconvenience. Please try again later."); # Email the webmaster: $Server->Mail( To => 'me@mydomain.com', Subject => '500 Server error', Message => "Please look at the following error:\n\n" . $err ); # Done! $Response->End; }# end Script_OnError() 1;# return true:
The Apache2::ASP::GlobalASA class is mostly analogous to the Global.asa or Global.asx of Microsoft ASP and ASP.Net web applications.
Apache2::ASP::GlobalASA
Global.asa
Global.asx
Simply by overriding a few methods you can completely change the behavior of your web application.
Returns a new GlobalASA object.
Executes once per Apache child, before servicing the first request that Apache child processes.
Called after a script's contents have been read from disk, but before it has been parsed by Apache2::ASP::Parser.
Apache2::ASP::Parser
If the script is encrypted or requires a source filter, this is the time to do that kind of pre-processing.
Called *just* before $Response->Flush is called. Passed a reference to the output buffer, here one can perform any final adjustments to the resulting HTML code.
For example, fill in HTML form fields or remove excess whitespace.
Called after Script_OnParse() but before Script_OnStart(), this is a good place to set any Session variables that must be present at all times.
Script_OnParse()
Script_OnStart()
Called after the script has been parsed, but before it is executed, Script_OnStart() is a good place to check the logged-in status of a user.
For example:
sub Script_OnStart { my $script = $Request->ServerVariables("SCRIPT_FILENAME"); if( $script =~ m/^\/members\-only\/.*/ ) { # User tried to access the /members-only area if( ! $Session->{logged_in} ) { # Not logged in! $Session->{error} = "Please log in to access the members-only section."; $Response->Redirect("/login.asp"); }# end if() }# end if() }# end Script_OnStart()
Called right after processing for the script has finished, but not if an error occurred during the script's execution.
Called right after processing for the script has finished, only if an error occurred.
The $error passed in is the current value of $@.
$error
$@
This is a good place to insert code to email you about the error that occurred, or print out a friendly error message to the client.
It's possible that some bugs have found their way into this release.
Use RT http://rt.cpan.org/NoAuth/Bugs.html?Dist=Apache2-ASP to submit bug reports.
Please visit the Apache2::ASP homepage at http://www.devstack.com/ to see examples of Apache2::ASP in action.
John Drago jdrago_999@yahoo.com
Copyright 2007 John Drago, All rights reserved.
This software is free software. It may be used and distributed under the same terms as Perl itself.
To install Apache2::ASP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Apache2::ASP
CPAN shell
perl -MCPAN -e shell install Apache2::ASP
For more information on module installation, please visit the detailed CPAN module installation guide.