[Catalyst] Chained action confusion...

Jason Kohles email at jasonkohles.com
Sat Feb 10 13:38:57 GMT 2007


I've been converting a big chunk of my next Catalyst application to  
Reaction, and have run into an issue with :Chained that seems strange  
to me, after working with it for a while I've managed to turn it into  
a tiny little example, hopefully small enough that someone can spot  
what I'm doing wrong...


I've got a basic catalyst application right from the helper  
(catalyst.pl Test), and the only thing I modified is the root  
controller:

package Test::Controller::Root;

use strict;
use warnings;
use base 'Catalyst::Controller';

__PACKAGE__->config->{namespace} = '';

sub base : Chained('/') PathPart('') CaptureArgs(0) {
     my ( $self, $c ) = @_;

     push( @{ $c->stash->{ 'path' } }, 'base' );
}

sub index : Chained('base') PathPart('') Args(0) {
     my ( $self, $c ) = @_;

     push( @{ $c->stash->{ 'path' } }, 'index' );
}

sub foo : Chained('base') PathPart('foo') Args(0) {
     my ( $self, $c ) = @_;

     push( @{ $c->stash->{ 'path' } }, 'foo' );
}

sub end : ActionClass('RenderView') {
     my ( $self, $c ) = @_;

     $c->response->body( join( ' / ', @{ $c->stash->{ 'path' } } ) );
}

1;

When Catalyst starts up, it shows me these chained actions:

[debug] Loaded Chained actions:
.------------------------------------- 
+--------------------------------------.
| Path Spec                           |  
Private                              |
+------------------------------------- 
+--------------------------------------+
| /foo                                | /base  
(0)                            |
|                                     | => / 
foo                              |
|                                     | /base  
(0)                            |
|                                     | => / 
index                            |
'------------------------------------- 
+--------------------------------------'

Which is as it should be, calls to http://myapp/ should go through "/ 
base(0) => /index" and calls to http://myapp/foo should go through "/ 
base(0) => /foo".

When I load up /foo in a browser, I get the expected response:

[info] *** Request 2 (0.333/s) [17853] [Sat Feb 10 08:23:51 2007] ***
[debug] "GET" request for "foo" from "127.0.0.1"
[debug] Path is "/foo"
[info] Request took 0.007484s (133.618/s)
.---------------------------------------------------------------- 
+-----------.
| Action                                                         |  
Time      |
+---------------------------------------------------------------- 
+-----------+
| /base                                                          |  
0.000052s |
| /foo                                                           |  
0.000031s |
| /end                                                           |  
0.000173s |
'---------------------------------------------------------------- 
+-----------'

And the output in the browser is "base / foo", just like I wanted.

However, when I hit the index, it skips right over the base action:

[info] *** Request 3 (0.375/s) [17853] [Sat Feb 10 08:23:53 2007] ***
[debug] "GET" request for "/" from "127.0.0.1"
[info] Request took 0.005970s (167.504/s)
.---------------------------------------------------------------- 
+-----------.
| Action                                                         |  
Time      |
+---------------------------------------------------------------- 
+-----------+
| /index                                                         |  
0.000033s |
| /end                                                           |  
0.000152s |
'---------------------------------------------------------------- 
+-----------'

And the output to the browser is just "index".

-- 
Jason Kohles
email at jasonkohles.com
http://www.jasonkohles.com/
"A witty saying proves nothing."  -- Voltaire


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070210/b6b95862/attachment.htm


More information about the Catalyst mailing list