The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Apache2::ASP::GlobalASA - Base class for your GlobalASA

SYNOPSIS

  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:

DESCRIPTION

The Apache2::ASP::GlobalASA class is mostly analogous to the Global.asa or Global.asx of Microsoft ASP and ASP.Net web applications.

Simply by overriding a few methods you can completely change the behavior of your web application.

OVERRIDABLE METHODS

new( $asp )

Returns a new GlobalASA object.

Server_OnStart( )

Executes once per Apache child, before servicing the first request that Apache child processes.

Script_OnParse( $source_ref )

Called after a script's contents have been read from disk, but before it has been parsed by Apache2::ASP::Parser.

If the script is encrypted or requires a source filter, this is the time to do that kind of pre-processing.

Script_OnFlush( $buffer_ref )

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.

Session_OnStart( )

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_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()

Script_OnEnd( )

Called right after processing for the script has finished, but not if an error occurred during the script's execution.

Script_OnError( $error )

Called right after processing for the script has finished, only if an error occurred.

The $error passed in is the current value of $@.

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.

BUGS

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.

HOMEPAGE

Please visit the Apache2::ASP homepage at http://www.devstack.com/ to see examples of Apache2::ASP in action.

AUTHOR

John Drago jdrago_999@yahoo.com

COPYRIGHT AND LICENSE

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.