NAME
Apache2::Controller::Dispatch::Simple - simple dispatch mechanism for A2C
SYNOPSIS
<Location /subdir>
SetHandler modperl
PerlOptions +SetupEnv
PerlInitHandler MyApp::Dispatch
</Location>
# lib/MyApp::Dispatch:
package MyApp::Dispatch;
use base qw(
Apache2::Controller::Dispatch
Apache2::Controller::Dispatch::Simple
);
our %dispatch_map = (
foo => 'MyApp::C::Foo',
'foo/bar' => 'MyApp::C::Foo::Bar',
);
sub handler { Apache2::Controller::Dispatch::handler(shift, __PACKAGE__) }
DESCRIPTION
Implements find_controller() for Apache2::Controller::Dispatch with a simple URI-to-controller module mapping. Your URI's are the keys of the %dispatch_map hash in your base package, and the values are the Apache2::Controller modules to which those URI's should be dispatched.
This dispatches URI's in a case-insensitive fashion. It searches from longest known path to shortest. For a site with many controllers and paths, a trie could possibly be more efficient. Consider that implementation for another Dispatch plugin module.
Any implementation of find_controller() should throw an Apache2::Controller::X with http => Apache2::Const::NOT_FOUND in the event that the detected method selected does not appear in the list of @ALLOWED_METHODS
in the controller module. See "check_allowed_method( )" in Apache2::Controller::Funk
Successful run of find_controller() should result in four items of data being set in request->notes and request->pnotes:
- notes->{relative_uri} = matching part of uri relative to location
-
This is the uri relative to the location. For example, if the dispatch module is the init handler in a
<Location /subdir>
config block, then for /subdir/foo/bar/biz/zip in this example code, relative_uri should be 'foo/bar' because this is the key of %dispatch_map that was matched. /subdir/foo/bar is the 'virtual directory.'If there is no relative uri, for example if the uri requested was /subdir and this is the same as the location, then
notes-
{relative_uri}> would be set to the empty string. - notes->{controller} = selected package name
-
This should be the name of an Apache2::Controller subclass selected for dispatch.
- notes->{method} = method name in controller to process the uri
-
This is the name of the method of the controller to use for this request.
- pnotes->{path_args} = [ remaining path_info ]
-
The remaining 'virtual directory' arguments of the uri. In the example above for notes->{relative_uri}, this is [ 'biz', 'zip' ].
@path_args is the array of remaining elements. For example if your dispatch map contains the URI 'foo', and the incoming URI was '/foo/bar/baz', then $r->pnotes->{path_args} should be ['bar', 'baz'] before returning.
SEE ALSO
Apache2::Controller::Dispatch