The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Apache2::ASP::Manual::Handlers - Documentation about writing Handlers

SYNOPSIS

Here is a basic handler:

  package MyHandler;
  
  use strict;
  use warnings 'all';
  use base 'Apache2::ASP::FormHandler';
  
  use vars qw(
    $Request $Response
    $Session $Server
    $Application $Form
    $Config
  );
  
  sub run
  {
    # Perform some work, then:
    $Response->Redirect("/another-page.asp");
  }# end run()
  
  1;# return true:

INTRODUCTION

What are Handlers?

Handlers are a kind of middle-ground for ASP programmers. There are no <% %> tags and no HTML parsing, but you still have the ASP objects ($Request, $Response, $Session, etc).

What makes them special?

Handlers are an object-oriented approach to form processing in a web application.

This means that Handlers that derive from one root Handler class will have different properties than Handlers that derive from another root Handler class.

What are Handlers for?

Handlers are intended for processing forms or responding to AJAX Web2.0 applications where you don't need to worry about large chunks of HTML embedded in your code.

What kinds of Handlers are there?

Handlers can subclass the following root classes:

Apache2::ASP::FormHandler

Subclasses of Apache2::ASP::FormHandler are used for processing form input. Typically a FormHandler will redirect the user to another page after the request has been processed.

Apache2::ASP::UploadHandler

Subclasses of Apache2::ASP::UploadHandler are used for processing file uploads. Unless you need to start completely from scratch, you're probably better off subclassing Apache2::ASP::MediaManager.

Apache2::ASP::MediaManager

Subclasses of Apache2::ASP::MediaManager get instant file-upload manager functionality just by showing up. Override a method or two and you've got basic file management that should work fine for most small websites. Override a couple more methods and you can have enterprise-class file management.

Apache2::ASP::PageHandler

All ASP scripts are compiled into a Perl module that subclasses Apache2::ASP::PageHandler.

Learn more about ASP compilation at Apache2::ASP::Manual::ASP_Compilation.

SUBCLASSING OTHER HANDLERS

All Handlers are subclasses of Apache2::ASP::Handler. Apache2::ASP::MediaManager is a subclass of Apache2::ASP::UploadHandler.

You could make your own "private" Handler classes (not installed under /handlers on your site) that your "public" Handlers (available under /handlers on your site) derive from.

For example, one could write an abstract "shopping cart" Handler that others are derived from, only adding or replacing functionality specific to their needs.

So Generic::Handler::Newsletter::Signup might contain all the logic necessary to add someone to a mailing list (in general). Newsletter::Signup could subclass Generic::Handler::Newsletter::Signup and handle the redirect part.

Example

  package Newsletter::Signup;
  
  use strict;
  use warnings 'all';
  use base 'Generic::Handler::Newsletter::Signup';
  use vars qw(
    $Request $Response
    $Session $Server
    $Application $Form
    $Config
  );
  
  sub run
  {
    my $s = shift;
    
    # Have Generic::Handler::Newsletter::Signup do the heavy lifting:
    $s->SUPER::run( @_ );
    
    # Now just redirect the user:
    $Response->Redirect("/thank-you.asp");
  }# end run()
  
  1;# return true:

READ THIS

Please note - your Handlers are not automatically reloaded if you make changes to them.

You will have to restart Apache to make sure that your changes take effect.

On a strictly development webserver you could use Apache::Reload to help this, but even then you may get some strange behavior.

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 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.