NAME
OpenInteract2::ActionResolver - Small classes and chain of responsibility to resolve URLs to action objects
SYNOPSIS
# Get all the available resolver objects my @resolvers = OpenInteract2::ActionResolver->get_all_resolvers(); # Send OI2::Request object from which we get the URL using the # default resolvers... my $action = OpenInteract2::ActionResolver->get_action( $request ); # ...or specify the URL and resolvers yourself my $action = OpenInteract2::ActionResolver->get_action( $request, $url, @resolvers );
DESCRIPTION
An action resolver takes a URL and tries to create an OpenInteract2::Action from it. If the resolver cannot do so it does nothing and the next one is called.
Resolvers are found at runtime as long as they're under the 'OpenInteract2::ActionResolver' namespace. You can also add them manually using normal Class::Factory directives:
OpenInteract2::ActionResolver->register_factory_class(
myresolver => 'MyApplication::Resolver::FooResolver' );
CLASS METHODS
get_all_resolvers()
Returns a list of resolver objects -- order is important!
get_action( $request, [ $url ], [ @resolvers ] )
Match up $url to the corresponding action. If not given we ask
$request for its url_relative() property, and if @resolvers
aren't given we use the result from our get_all_resolvers() class
method. Each of the OpenInteract2::ActionResolver objects in
@resolvers will get called and asked if it can resolve $url.
This will either return an OpenInteract2::Action object or throw an exception.
new( $type )
Creates a new resolver -- no parameters are passed in besides the
$type that each resolver uses to register itself.
OBJECT METHODS
get_order() - subclass may implement
Return a number between 1 and 10 indicating when the resolver should be run. If you do not implement this the default is '5', which will probably be fine for most implementations.
resolve( $request, $url ) - subclass must implement
Tries to find data in $url to create an action. The $url will
not contain any deployment context information. (Note that $url
may have come from $request or may have been specified by the
original caller, so don't go peeking around in $request for it
unless you know what you're doing.)
If that particular resolver does not know what to do with the URL it should return nothing to indicate that the next resolver down the line should get executed.
If you're thinking of implementing an this class to create a
side-effect (like looking for a 'my_language' request parameter and
using that for the language assigned), don't. There's a better
way. Just create an observer in the
OpenInteract2::Observer::Controller namespace and we'll pick it up
automatically from OpenInteract2::Setup::InitializeControllers. The
observation you're looking for is 'action assigned'.
So to do the above you'd create:
package OpenInteract2::Observer::Controller::Language;
use strict;
use OpenInteract2::Context qw( CTX );
sub update {
my ( $class, $controller, $observation, $action ) = @_;
return unless ( $observation eq 'action assigned' );
my $request = CTX->request;
my $lang = $request->param( 'my_language' );
if ( $lang ) {
$request->find_languages( $lang, $request->language );
}
}
SEE ALSO
COPYRIGHT
Copyright (c) 2005 Chris Winters. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHORS
Chris Winters <chris@cwinters.com>
Generated from the OpenInteract 1.99_06 source.
