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

Trevor Leffler tleffler at uw.edu
Tue Feb 10 03:51:31 GMT 2015


On 2/9/2015 1:59 AM, Dmitry L. wrote:
> I'd rather split one application into several (admin app, survey app,
> etc) and "join" its via middleware.
>
> But you can try this:
>
> In MyApp::Admin:
> sub default : Path('admin') {
> # or
> # sub default : Chained(base) PathPart('') Path {
>      my ( $self, $c ) = @_;
>      $c->response->body( 'Page not found in /admin/...' );
>      $c->response->status(404);
> }

Neither of these work, as in both cases default() wins over index() 
except when index is defined as 'sub index : Path', which isn't a good 
option for me.

And... I'd imagine that having both default and index defined with " : 
Chained('base') PathPart('') Args(0)" would lead to a collision and/or 
non-deterministic behavior...?

--Trevor

>
> In MyApp::Survey;
> sub default : Path('survey') {
> # or
> # sub default : Chained(base) PathPart('') Path {
>      my ( $self, $c ) = @_;
>      $c->response->body( 'Page not found in /survey/...' );
>      $c->response->status(404);
> }
>
> On 7 February 2015 at 01:51, Trevor Leffler <tleffler at uw.edu> wrote:
>> Some of my top-level controllers represent different, er... "major pieces"
>> of my application.  They have, among other things, different default views,
>> which are mainly just for configuring different page wrappers.  These
>> controllers have this action pattern:
>>
>> package MyApp::Admin;
>> sub base : Chained('/') : PathPart('admin') : CaptureArgs(0) { ... }
>> sub index : Chained('base') : PathPart('') : Args(0) { ... }
>>
>> package MyApp::Survey;
>> sub base : Chained('/') : PathPart('survey') : CaptureArgs(0) { ... }
>> ...etc...
>>
>> 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'.  Otherwise, I get the
>> appropriate view with 'Page Not Found' content for bad urls, e.g.
>> /admin/blargh or /survey/123/nurgle
>>
>> I am looking for suggestions/solutions to get the desired behavior.
>>
>> Changing index() to 'index : Path' is not a viable option.
>>
>>
>> Thanks,
>> --Trevor
>>
>> [1] http://www.gossamer-threads.com/lists/catalyst/users/24883
>>
>> _______________________________________________
>> List: Catalyst at 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/
>
>
>

-- 
Trevor Leffler, Sr. Software Engineer
Office of Educational Assessment
University of Washington
4311 11th Ave NE, Seattle, WA 98195
tel 206.616.1479 | fax 206.543.3961
http://www.washington.edu/oea



More information about the Catalyst mailing list