Catalyst-Manual
view release on metacpan or search on metacpan
lib/Catalyst/Manual/Cookbook.pod view on Meta::CPAN
$c->stash->{volume} = $volume;
}
sub track : Chained('volume') PathPart('track') CaptureArgs(1) {
my ($self, $c, $track_no) = @_;
$c->stash->{track} = $self->stash->{cd}->find_track_by_vol_and_track_no(
$c->stash->{volume}, $track_no
);
}
Note that adding other actions (i.e. chain endpoints) which operate on a track
is simply a matter of adding a new sub to CD::Controller - no code is duplicated,
even though there are two different methods of looking up a track.
This technique can be expanded as needed to fulfil your requirements - for example,
if you inherit the first action of a chain from a base class, then mixing in a
different base class can be used to duplicate an entire URL hierarchy at a different
point within your application.
=head2 Component-based Subrequests
lib/Catalyst/Manual/ExtendingCatalyst.pod view on Meta::CPAN
my ($self, $c, $id) = @_;
my $model = $c->model( $self->{model_name} );
$c->stash(row => $model->find($id));
}
1;
This example implements two simple actions. The C<list> action chains
to a (currently non-existent) C<base> action and puts a result-set
into the stash taking a configured C<model_name> as well as a search
condition and attributes. This action is a
L<chained|Catalyst::DispatchType::Chained> endpoint. The other action,
called C< load > is a chain midpoint that takes one argument. It takes
the value as an ID and loads the row from the configured model. Please
not that the above code is simplified for clarity. It misses error
handling, input validation, and probably other things.
The class above is not very useful on its own, but we can combine it
with some custom actions by sub-classing it:
package MyApp::Controller::Foo;
use Moose;
( run in 0.486 second using v1.01-cache-2.11-cpan-27979f6cc8f )