[Catalyst] Catalyst Actions precedence
Kieren Diment
diment at gmail.com
Wed Feb 27 21:50:21 GMT 2013
On 28/02/2013, at 8:20 AM, Nick Anderson <nick at webcraftcs.com> wrote:
> Hi,
>
> please could someone explain how Catalyst determines the precedence of actions, specifically in relation to the following simple chained example. It doesn't behave in the way I would expect for requests numbered 4 and 6:
>
> 1. http://127.0.0.1:3001/action0 => Matched action 0
> 2. http://127.0.0.1:3001/action0/abc => Matched XPages / pages
> 3. http://127.0.0.1:3001/action1 => Matched XPages / pages
> 4. http://127.0.0.1:3001/action1/abc => Matched XPages / pages
> 5. http://127.0.0.1:3001/actionx => Matched action x
> 6. http://127.0.0.1:3001/actionx/abc => Matched XPages / pages
>
> The controllers are detailed below:
>
> package TestApp::Controller::Root;
> use Moose;
> use namespace::autoclean;
>
> BEGIN { extends 'Catalyst::Controller' }
>
> __PACKAGE__->config(namespace => '');
>
> sub site_base :Chained :PathPart('') :CaptureArgs(0) {
> my ($self,$c ) = @_;
> }
>
You seem to have missed :Chained('site_base') from all the sub attributes below.
Check the DwarfChains app in the catalyst book code (chapter 7 available from - http://www.apress.com/downloadable/download/sample/sample_id/205/ ) for an example along the same lines of yours that works.
> sub action0 :Path('action0') :Args(0) {
> my ($self,$c ) = @_;
> $c->response->body( "Matched action 0" );
> }
>
> sub action1 :Path('action1') :Args(1) {
> my ($self,$c ) = @_;
> $c->response->body( "Matched action 1" );
> }
>
> sub actionx :Path('actionx') :Args() {
> my ($self,$c ) = @_;
> $c->response->body( "Matched action x" );
> }
>
> sub end : ActionClass('RenderView') {}
>
> __PACKAGE__->meta->make_immutable;
>
> 1;
>
> package TestApp::Controller::XPages;
> use Moose;
> use namespace::autoclean;
>
> BEGIN {extends 'Catalyst::Controller'; }
>
> sub base : Chained( '/site_base' ) : PathPart('') : CaptureArgs( 1 ) {
> my ( $self, $c ) = @_;
> }
>
> sub pages : Chained( 'base' ) : PathPart('') : Args() {
> my ( $self, $c ) = @_;
> $c->response->body('Matched XPages / pages');
> }
>
> __PACKAGE__->meta->make_immutable;
>
> 1;
>
>
> Thanks for any help you can give
>
> Nick Anderson
>
> _______________________________________________
> 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/
More information about the Catalyst
mailing list