|
From: Chris W. <ch...@cw...> - 2001-12-12 21:57:05
|
* Victor Piterbarg (ope...@ha...) [011212 15:35]:
> I wrote this handler that manages the purchasing process. It
> basically checks that all the needed objects exist -- like user
> profile, a credit card, etc., -- and calls appropriate action. For
> example, if there is no user profile it calls up the handler for
> user profiles with the 'create' task. Here's the gist of how I do
> it:
> ...
> sub buy_stuff
> {
> if(!$profile)
> {
> return OpenInteract::Handler::RegNasa->handler({task => 'create'});
> }
> }
>
> This seems to work fine actually. I just was wondering if there
> perhaps was an interface to just run one of the actions I have
> defined in actions.perl from within a handler -- without having to
> explicitly refer to the handler I want to run. Seems it would be
> neater that way. Thanks.
Yes -- you can do:
my ( $class, $method ) = $R->lookup_action( 'action_name' );
$class->handler({ task => 'create' });
or if you'd prefer calling it directly:
$class->$method();
You can see an example of this in OpenInteract::Handler::Logout in the
'base' package where we do:
my ( $action_class, $action_method ) = $R->lookup_action( 'redirect' );
return $action_class->$action_method({ url => $return });
This will be replaced in the relatively near future by an actual
action dispatcher, where you'd simply do something like:
$R->dispatch( 'action_name', \%params );
And have security get checked properly, parameters from the action be
passed into the action, etc.
Chris
--
Chris Winters (ch...@cw...)
Building enterprise-capable snack solutions since 1988.
|