Apache::Request::Dispatcher

Apache::Request::Dispatcher Perl module dispatches requests to a sub-class of Apache::Request::Controller.
Download

Apache::Request::Dispatcher Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Bradley Kite
  • Publisher web site:
  • http://search.cpan.org/~kite/gestalt-0.2.1/Dispatcher/Dispatcher.pm

Apache::Request::Dispatcher Tags


Apache::Request::Dispatcher Description

Apache::Request::Dispatcher Perl module dispatches requests to a sub-class of Apache::Request::Controller. Apache::Request::Dispatcher Perl module dispatches requests to a sub-class of Apache::Request::Controller.SYNOPSIS < Location /myApplication > SetHandler perl-script Perlhander Apache::Request::Dispatcher SetEnv DispatcherConf /path/to/file.cfg setEnv APP_NAME myApplication < /Location >Apache::Request::Dispatcher is a mod_perl handler which handles Apache HTTP requests under mod_perl, and dispatches them to a sub-class of Apache::Request::Controller (after some initial request setup has been performed).If required, it will establish a connection to a database using the DBI, retrieve (or create) session data for this request (using Apache::Session), initialise a template processor (using the Template-Toolkit).The Dispatcher parses the URI of the request to determine which subclass of Apache::Request::Controller to then pass control to.Parsing of the URI occurs as follows:APP_NAME (environment set in Apache Config) is removed from the begining of the URI, so that: '/myApplication/SubClass/action'becomes: 'SubClass/action'or '/myApplication/Sub/Class/action'becomes: 'Sub/Class/action'This is then converted to a module name, and a method name, such as: Apache::Request::Controller::SubClass or Apache::Request::Controller::Sub::Classwith action() being the method name.It should be noted that if the SubClass or Action name contain any thing other than then the request is declined.The dispatcher then dynamically inherits from the module name, and then calls $self->action().The action() method of the controller is then called in an object-oriented fashion, with a dispatcher object passed in as its first parameter.This object contains the following hash elements: request => $r, # The Apache Request Object dbh => $dbh, # The Database Connection Object cfg => $cfg, # The AppConfig object template => $template, # The Template Processor apr => $q, # The CGI/libapreq object session => %session # Any session data for this userDepending on the configuration file, 'dbh' or 'session' may be undefined if they've been turned off.an example controller method might be written as follows: package Apache::Request::Controller::SubClass; our @ISA = qw(Apache::Request::Controller); use strict; use Apache::Const qw(:common :methods :http); sub action { my $self = shift; my $thing = getThingByID($self->{'dbh'}, $self->{'apr'}->param('thingId')); $self->{'request'}->status(HTTP_OK); $self->{'request'}->content_type('text/html'); $self->{'template'}->process('myTemplate', {thing => $thing}); return OK; } 1; Requirements: · Perl


Apache::Request::Dispatcher Related Software