[Catalyst] A point of confusion/frustration on chained actions

Ash Berlin ash_cpan at firemirror.com
Wed May 19 22:38:44 GMT 2010


On 19 May 2010, at 23:16, Stephen Howard wrote:
> I am trying to sort out some interdependent chains and I'm having trouble figuring out why the urls I'm trying to build aren't working out.
> 
> I have a site where the primary objects of interest are flash-based tutorials.  Each tutorial can have comments, and each comment can have replies.  I'm using jQuery to manipulate comments in a REST fashion, and I'm aiming for a url map like this:
> 
> /tutorials                         # GET a list of tutorials, or POST a new tutorial
> /tutorials/*                       # GET/POST/DELETE a specific tutorial
> /tutorials/*/comments              # GET the comments for a tutorial, or POST a new comment
> /tutorials/*/comments/*            # GET/POST/DELETE a specific comment
> /tutorials/*/comments/*/replies    # GET the replies for a comment, or POST a new reply
> /tutorials/*/comments/*/replies/*  # GET/POST/DELETE a specific reply
> 
> But the best I've been able to come up with is this:
> 
>  /tutorials
> ^tutorials/(\d+)$
> /tutorial/*/comments
> /tutorial/*/comment/*/replies
> /tutorial/*/comment/*/reply/*
> 
> missing: /tutorial/*/comment (what would I call it? /tutorial/*/cmt ?)
> 
> Essentially I'm hitting an issue with is due to the (seeming?) impossibility of matching a chained set of actions at multiple url depths. Is it possible to build the url structure I'm looking for above using chained actions?
> 
> thanks,
> Stephen

You can get it exactly as you want:

(manually re-ordered the below to match your desired list)
[debug] Loaded Chained actions:
.-------------------------------------+--------------------------------------.
| Path Spec                           | Private                              |
+-------------------------------------+--------------------------------------+
| /tutorials                          | /tutorials (0)                       |
|                                     | => /all_tutorials                    |
| /tutorials/*                        | /tutorials (0)                       |
|                                     | -> /a_tutorial (1)                   |
|                                     | => /show_tutorial                    |
| /tutorials/*/comments               | /tutorials (0)                       |
|                                     | -> /a_tutorial (1)                   |
|                                     | -> /comments (0)                     |
|                                     | => /show_tutorial_comments           |
| /tutorials/*/comments/*             | /tutorials (0)                       |
|                                     | -> /a_tutorial (1)                   |
|                                     | -> /comments (0)                     |
|                                     | -> /a_comment (1)                    |
|                                     | => /show_comment                     |
| /tutorials/*/comments/*/replies     | /tutorials (0)                       |
|                                     | -> /a_tutorial (1)                   |
|                                     | -> /comments (0)                     |
|                                     | -> /a_comment (1)                    |
|                                     | -> /replies (0)                      |
|                                     | => /show_replies                     |
| /tutorials/*/comments/*/replies/*   | /tutorials (0)                       |
|                                     | -> /a_tutorial (1)                   |
|                                     | -> /comments (0)                     |
|                                     | -> /a_comment (1)                    |
|                                     | -> /replies (0)                      |
|                                     | -> /a_reply (1)                      |
|                                     | => /show_reply                       |
'-------------------------------------+--------------------------------------'



sub tutorials : Chained('/') PathPart CaptureArgs(0) {
  # stash tutorials rs
}
sub all_tutorials : Chained('tutorials') PathPart('') Args(0) {
  # empty, or set stash for view
}

sub a_tutorial : Chained('tutorials') PathPart('') CaptureArgs(1) {
  # stash tutorial
}
sub show_tutorial : Chained('a_tutorial') Args(0) PathPart('') {
 # setup view
}

sub comments : Chained('a_tutorial') CaptureArgs(0) PathPart {
  # stash comments rs from stash->{tutorial}
}

# You get the idea hopefully....
sub show_tutorial_comments : Chained('comments') Args(0) PathPart('') {}
sub a_comment : Chained('comments') CaptureArgs(1) PathPart('') {}

sub show_comment : Chained('a_comment') Args(0) PathPart('') { }

sub replies : Chained('a_comment') PathPart CaptureArgs(0) {}
sub show_replies : Chained('replies') Args(0) PathPart('') {}
sub a_reply : Chained('replies') CaptureArgs(1) PathPart('') {}
sub show_reply : Chained('a_reply') Args(0) PathPart('') {}


-ash


More information about the Catalyst mailing list