[Catalyst] How to get default()-like behavior outside of the Root controller

Aristotle Pagaltzis pagaltzis at gmx.de
Tue Feb 10 10:39:57 GMT 2015

Hi Trevor,

* Trevor Leffler <tleffler at uw.edu> [2015-02-07 00:00]:
> Requests for non-extant paths fall through to Root->default(), which
> gives the (undesired) default root view. I tried giving my top-level
> controllers their own default() methods, but as others have found [1],
> 'default() : Path' has precedence over 'index : Chained'.

    package MyApp::Admin;
    sub default : Chained('base') PathPart('') { ... }
    package MyApp::Survey;
    sub default : Chained('base') PathPart('') { ... }

Note how you don’t specify any particular number of arguments. So it
will match any number of trailing URL segments.

I *think* this will work. I haven’t tried it.

However, contrary to what you claimed, splitting the app into multiple
Cat apps joined together at the PSGI level *will* also work just fine.
That will lead to requests for /admin/* always being dispatched to
MyApp::Admin – which gets to have its own MyApp::Admin::Controller::Root
with a `default` action that applies only to it. Likewise requests for
/survey/* will always be dispatched to MyApp::Survey which equally has
its own root controller with a `default` action that applies only to it.
If the parts of your app are not closely related, this will be a more
natural structure.

Aristotle Pagaltzis // <http://plasmasturm.org/>

More information about the Catalyst mailing list