[Catalyst] $c->visit without calling end()

Bill Moseley moseley at hank.org
Sat Nov 13 02:54:36 GMT 2010

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} =3D 'GET';
        local $c->request->{arguments} =3D [];
        local $c->request->{captures}  =3D [ $item_id ];

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

        $action->dispatch( $c );

-- =

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

More information about the Catalyst mailing list