NAME

Apache2::ASP::Base - Base class for ASP engines

SYNOPSIS

package MyASP;

use strict;
use base 'Apache2::ASP::Base';

# Use whatever Apache2::* and APR::* modules are necessary:

sub handler : method
{
  my ($class, $r) = @_;
  
  # We function best as an object:
  my $s = $class->SUPER::new( $ENV{APACHE2_ASP_CONFIG} );
  
  # What Apache2::ASP::Handler is going to handle this request?
  my $handler_class = $s->resolve_request_handler( $r->uri );
  if( $handler_class->isa('Apache2::ASP::UploadHandler') )
  {
    # We use the upload_hook functionality from Apache::Request
    # to process uploads:
    my $upload_hook = sub {
      my ($upload, $data) = @_;
      # Handle upload hook here...
    };
    $s->{q} = Apache2::ASP::CGI->new( $r, $upload_hook );
  }
  else
  {
    # Not an upload - normal CGI functionality will work fine:
    $s->{q} = Apache2::ASP::CGI->new( $r );
  }# end if()
  
  # Get our subref and execute it:
  my $handler = $s->setup_request( $r, $s->{q} );
  my $status = eval { $handler->( ) };
  if( $@ )
  {
    warn "ERROR AFTER CALLING \$handler->( ): $@";
    return $s->_handle_error( $@ );
  }# end if()
  
  # 0 = OK, everything else means errors of some kind:
  return $status;
}# end handler()

sub _handle_error
{
  my ($s, $err) = @_;
  
  my $stack = Devel::StackTrace->new;
  warn $stack->as_string;
  $s->response->Clear();
  $s->global_asa->can('Script_OnError')->( $stack );
  
  return 500;
}# end _handle_error()

DESCRIPTION

METHODS

new( $config )

Returns a new Apache2::ASP::Base object using the Apache2::ASP::Config object passed in as $config.

setup_request( $r )

Creates a new request instance, based on the information about the request gleaned from $r - an Apache2::RequestRec object (or something that behaves like one anyway).

Returns a subroutine reference.

Execute like:

my $ref = $asp->setup_request( $r );

# A normal request:
$ref->( 0 );
# or
$ref->( );

# A subrequest (i.e. as in the case of an include):
$ref->( 1 );

config( )

Returns the current Apache2::ASP::Config object.

r( )

Returns the Apache2::RequestRec object.

q( )

Returns the Apache2::ASP::CGI object.

session( )

Returns the current Apache2::ASP::SessionStateManager object.

request( )

Returns the current Apache2::ASP::Request object.

response( )

Returns the current Apache2::ASP::Response object.

server( )

Returns the current Apache2::ASP::Server object.

application( )

Returns the current Apache2::ASP::Application object.

global_asa( )

Returns the Apache2::ASP::GlobalASA object.

resolve_request_handler( $uri )

Returns the classname of the Apache2::ASP::Handler subclass that will process the current HTTP request.

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://apache2-asp.no-ip.org/ to see examples of Apache2::ASP in action.

AUTHOR

John Drago mailto: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.