[Catalyst] Question about Chained Controller

Eden Cardim edencardim at gmail.com
Mon Nov 15 16:53:29 GMT 2010

>>>>> "Charlie" == Charlie Garrison <garrison at zeta.org.au> writes:

    Charlie> I've never bothered to find out why, but I've run into
    Charlie> situations where $c->user_exists returns true and $c->user
    Charlie> returns false. I just check for defined($c->user) instead
    Charlie> and that solved it for me.

Probably a mangled session?

    Charlie> I also agree with other users that auto is a better place
    Charlie> to do that check.

Chaining is a lot more powerful because it allows you to distribute
responsibilities hierarchically throughout several actions:

package MyApp::Controller::Root;

sub foo :Chained('/') CaptureArgs(0) {
  my ($self, $c) = @_;
  $c->detach unless $c->user_exists;

sub do_something :Chained('foo') Args(0) {}

sub bar :Chained('foo') PathPart('') CaptureArgs(0) {
  my($self, $c) = @_;
  $c->detach unless $c->assert_user_roles('bar_level_users');

sub do_something_else :Chained('bar') Args(0) {}

It also gives you a lot more flexbility, given you can change the
chaining via config:

            Chained foo

The above configuration will eliminate the check for the
'bar_level_users' role before running do_something_else.

     Eden Cardim            Need help with your perl Catalyst or DBIx::Class project?
   Software Engineer                   http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.        Want a managed development or deployment platform?
http://blog.edencardim.com             http://www.shadowcat.co.uk/servers/

More information about the Catalyst mailing list