[Catalyst] Chained actions with can't terminate with :PathPart('') ?

Trevor Leffler tleffler at uw.edu
Fri May 7 18:13:41 GMT 2010


Evan,

Here's an example of chaining that breaks out a lot of your path parts 
into discreet methods.  Watch the server debug output while hitting 
these in your browser to see how each piece is executed.

Notice how "middle man" methods use :CaptureArgs while endpoints use 
:Args.  Also, each piece of the chain uses :PathPart, rather than :Path, 
and it cannot be omitted.

Your application may not need or want all the controllers, methods, and 
endpoints I set up here, so play around with it.  Read also about how 
auto() and begin() might play a role in your controller hierarchy.

[root controller]
sub auth : Chained('/') : PathPart('auth') : CaptureArgs(0) { }

[company controller]
sub base : Chained('/auth') : PathPart('company') : CaptureArgs(0) { }
sub list : Chained('base') : PathPart('') : Args(0) { }
sub base_view : Chained('base') : PathPart('') : CaptureArgs(1) { }
sub view : Chained('base_view') : PathPart('') : Args(0) { }

[lot controller]
sub base : Chained('/company/base_view') : PathPart('lot') : 
CaptureArgs(0) { }
sub list : Chained('base') : PathPart('') : Args(0) { }
sub view : Chained('base') : PathPart('') : Args(1) { }

This setup generates these chained actions:
/auth/company
/auth/company/123
/auth/company/123/lot
/auth/company/123/lot/987

--Trevor

Evan Carroll wrote:
> I have two destinations in my Catalyst app
> 
> /auth/company/5/lot
> /auth/company/5/lot/5
> 
> This works and is often seen in Catalyst apps to achive this effect.
> sub lot :Chained('/auth/company') :CaptureArgs(1) {
> sub view_lot :Chained('/auth/company') :PathPart('') :Args(1) {
> 
> However, I would also expect the below to work; but, it seems it doesn't. I
> can only formulate the effect I want the above way. This is
> unfortunate because if all chained descendants of `lot` utilize a
> check provided here in the chain, then shouldn't `view_lot` also get
> to utilize that code? It would certainly be nice to eliminate
> redundant code here.
> sub lot :Chained('/auth/company') :CaptureArgs(1) {
> sub view_lot :Chained('/auth/company/lot') :PathPart('') :Args(0) {
> 
> I think it is also confusing to those that first encounter it.
> 
> I always know that I could just call it /view, and be done with it, but still.
> /auth/company/5/lot/5/view rather than, /auth/company/5/lot/5
> 
> But, I just wanted to know what others thought of this.
> 



More information about the Catalyst mailing list