[Catalyst] forwarding to chained actions

Bernhard Graf catalyst2 at augensalat.de
Tue Apr 24 09:41:28 GMT 2007


Is there a way to forward to (the end point of) a chained action and run 
the whole action chain again?

Simplified example:

sub instance : PathPart('') Chained('/') CaptureArgs(1) {
  my ($self, $c, $data_id) = @_;
  # fetch data for $data_id and put on stash
  $c->stash(data => $self->fetch_data_for_id($data_id));
}

# view data
# /data/<DATA_ID>
sub view : PathPart('') Chained('instance') Args(0) {
  my ($self, $c) = @_;
  $c->stash(template => 'view.tt');
}

# update data from form
# /data/<DATA_ID>/update
sub update : PathPart Chained('instance') Args(0) {
  my ($self, $c) = @_;
  my $data = $c->stash->{data};
  $self->update_from_form($data);
  $c->forward('view'); # view data
}

update() updates the data in the database but $c->stash->{data} is not 
changed. Then forward('view') calls view(), but this view's the 
unchanged (outdated) data from the stash.

Of course I could do a $c->stash(data => $data) before 
$c->forward('view'), but as stated this is only a simple example.
In many cases it would be convenient to have something like
$c->forward_chain('view') to execute all methods of the chain.

Does such a thing exist in Catalyst?
-- 
Bernhard Graf



More information about the Catalyst mailing list