FAQ
I have a number of chained actions that use an end() method that generates a
json response in a view.

Another developer added an action to support a POST, and at the end of the
action they call $c->visit on a few actions to build up a response -- I
assume to avoid making a few extra ajax requests. $c->visit does a full
dispatch so auto and end methods are called for each visit, plus for the
original action. But, because of the chained actions, $c->visit makes
running the requests very simple.

Yes, normally the POST would be followed by a redirect, but this POST is a
file upload in an iframe an a json response is desired. But, doing this
partial re-dispatch has also come with GET requests.


Any tricks to do a $c->visit type of call but w/o doing a full dispatch,
that is, without calling the auto and end actions?

I suppose I could do something like this, but it's not very pretty.

for my $action_name ( @action_names_to_run ) {
local $c->req->{method} = 'GET';
local $c->request->{arguments} = [];
local $c->request->{captures} = [ $item_id ];

my $action = $c->controller->action_for( $action_name );
$action = $c->dispatcher->expand_action($action);
local $c->{action} = $action;

$action->dispatch( $c );
}


--
Bill Moseley
moseley@hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20101112/68288df2/attachment.htm

Search Discussions

  • Bill Crawford at Nov 15, 2010 at 1:11 pm

    On 13 November 2010 02:54, Bill Moseley wrote:

    Any tricks to do a $c->visit type of call but w/o doing a full dispatch,
    that is, without calling the auto and end actions?
    Doesn't $c->forward(...) do exactly that? Or have I completely
    misunderstood the docs?

    $c->visit( $action [, \@captures, \@arguments ] )
    $c->visit( $class, $method, [, \@captures, \@arguments ] )
    Almost the same as forward, but does a full dispatch, instead of just
    calling the new $action / $class->$method. This means that begin, auto
    and the method you go to are called, just like a new request.
  • Aristotle Pagaltzis at Nov 15, 2010 at 4:56 pm

    * Bill Crawford [2010-11-15 14:20]:
    On 13 November 2010 02:54, Bill Moseley wrote:
    Any tricks to do a $c->visit type of call but w/o doing
    a full dispatch, that is, without calling the auto and end
    actions?
    Doesn't $c->forward(...) do exactly that? Or have I completely
    misunderstood the docs?
    No, `forward` does not do a full redispatch. Most importantly,
    if you?re using chains in your app, then `visit` will walk the
    entire chain to the action you passed and call those actions
    (as well as all the `begin` and `auto` actions along the way),
    while `forward` will only call the action itself.

    Regards,
    --
    Aristotle Pagaltzis // <http://plasmasturm.org/>
  • Bill Crawford at Nov 15, 2010 at 5:26 pm

    On 15 November 2010 16:56, Aristotle Pagaltzis wrote:
    * Bill Crawford [2010-11-15 14:20]:
    On 13 November 2010 02:54, Bill Moseley wrote:
    Any tricks to do a $c->visit type of call but w/o doing
    a full dispatch, that is, without calling the auto and end
    actions?
    Doesn't $c->forward(...) do exactly that? Or have I completely
    misunderstood the docs?
    No, `forward` does not do a full redispatch. Most importantly,
    if you?re using chains in your app, then `visit` will walk the
    entire chain to the action you passed and call those actions
    (as well as all the `begin` and `auto` actions along the way),
    while `forward` will only call the action itself.
    Erm, he was asking for something that doesn't "do a full dispatch" ?
  • Bill Moseley at Nov 15, 2010 at 6:46 pm

    On Mon, Nov 15, 2010 at 9:26 AM, Bill Crawford wrote:
    No, `forward` does not do a full redispatch. Most importantly,
    if you�re using chains in your app, then `visit` will walk the
    entire chain to the action you passed and call those actions
    (as well as all the `begin` and `auto` actions along the way),
    while `forward` will only call the action itself.
    Erm, he was asking for something that doesn't "do a full dispatch" ?
    There's two difference with calling forward. $c->forward does not use
    passed-in captures, and it doesn't run:

    $action = $c->dispatcher->expand_action($action);


    which, IIRC, turns an action into a chain of actions. I haven't looked at
    in in quite some time so probably worth looking at the source.

    So, $c->visit will run through the chain but also runs auto and end.
    $c->forward just executes the action w/o auto and end, but if the action is
    part of a chain and expand_action has not been run then it won't run the
    chain. Seem right?


    What's the reason that forward doesn't expand the chain and set the
    captures?


    --
    Bill Moseley
    moseley@hank.org
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20101115/41d7c786/attachment.htm

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedNov 13, '10 at 2:54a
activeNov 15, '10 at 6:46p
posts5
users3
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2022 Grokbase