From: Chris W. <la...@us...> - 2005-02-25 05:37:05
|
Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23995 Modified Files: ActionResolver.pm Log Message: doc updates -- discard the stuff about side-effects and show how to actually do it Index: ActionResolver.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/ActionResolver.pm,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ActionResolver.pm 13 Feb 2005 20:37:35 -0000 1.1 --- ActionResolver.pm 25 Feb 2005 05:36:38 -0000 1.2 *************** *** 122,126 **** aren't given we use the result from our C<get_all_resolvers()> class method. Each of the L<OpenInteract2::ActionResolver> objects in ! C<@resolvers> will get called and asked if it can resolve C<$url> This will either return an L<OpenInteract2::Action> object or throw an --- 122,126 ---- aren't given we use the result from our C<get_all_resolvers()> class method. Each of the L<OpenInteract2::ActionResolver> objects in ! C<@resolvers> will get called and asked if it can resolve C<$url>. This will either return an L<OpenInteract2::Action> object or throw an *************** *** 152,161 **** should get executed. ! The object may also create side-effects along the way. For instance, ! one of the built-in resolvers finds a parameter 'oi_language' from ! C<$request> and if it exists assigns that language for the ! request. (Yes, this technically isn't resolving an action, but there's ! no real use to create B<another> set of classes that perform such a ! similar action.) =head1 SEE ALSO --- 152,179 ---- 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 ! C<OpenInteract2::Observer::Controller> namespace and we'll pick it up ! automatically from L<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 ); ! } ! } =head1 SEE ALSO |