I just happened to find the answer here: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/msg07604.html
t0m++ for (1..10) On Mon, 2010-02-15 at 21:38 +0100, Kiffin Gish wrote: > In my application, users are allowed to edit only their own settings > like this: > > /account/id/client/settings/edit > > | /role/*/settings/edit | /auth (0) | > | | -> /role/base (1) | > | | -> /role/settings/crud/base (0) | > | | => /role/settings/crud/edit | > > # Controller::Role > sub base : Chained('/auth') PathPart('role') CaptureArgs(1) { > my ( $self, $c, $id ) = @_; > > # Get the user if possible. > my $user = $c->model('DB::User')->find($id); > > # Make sure that the user is indeed this user. > $c->detach('/error_403') unless $c->user->id == $id; > > # Save the user in the stash. > $c->stash( user => $user ); > } > > # Controller::Role::Settings::CRUD > sub base : Chained('/role/base') PathPart('settings') CaptureArgs(0) > {...} > > sub edit : Chained('base') PathPart('edit') Args(0) { > my ( $self, $c ) = @_; > my $user = $c->stash->{user}; > .... > } > > Now the hard part. > > I also want to allow the admin to be able to edit all user settings in > exactly the same way, like this: > > /account/id/admin/user/id/settings/edit > > # Controller::Role::Admin::User > sub base : Chained('/role/admin/base') PathPart('user') CaptureArgs(0) > {...} > > sub id : Chained('base') PathPart('') CaptureArgs(1) { > my ( $self, $c, $id ) = @_; > > # Get the user if possible. > my $user = $c->model('DB::User')->find($id); > > # Does this user exist? > $c->detach('/error_404') unless ($user); > > # Save the user in the stash. > $c->stash( user => $user ); > } > > sub edit : Chained('base') PathPart('settings') Args(0) {...} > > As you can see there's alot of repetition going on and there must be a > more elegant way to handle this. > > How does one go about chaining the same action from multiple points. > Does this make sense and if so is it possible? > > Thanks alot in advance, > Kiffin > > -- Kiffin Gish <kiffin.g...@planet.nl> Gouda, The Netherlands _______________________________________________ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/