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

Jeff Albert jralbert at uvic.ca
Wed May 19 23:24:05 GMT 2010


As an unabashed Catalyst n00b, I spent a couple of hours earlier this week bashing through this same design conundrum on my own application, and although I did ultimately come up with the solution that Ash describes under my own steam, the Catalyst::DispatchType::Chained documentation didn't do much to help me with the process at all - nor did the Catalyst tutorial.

I've never contributed, so I don't know the process, but it would be nice to see this information in the documentation. If somebody who knows what's necessary mails me off-list with the information on how to get started, I would be willing hack up Ash's reply into a fairly minimal doc patch in whichever location is appropriate.

Cheers,
Jeff

-----Original Message-----
From: Ash Berlin [mailto:ash_cpan at firemirror.com] 
Sent: Wednesday, May 19, 2010 3:39 PM
To: The elegant MVC web framework
Subject: Re: [Catalyst] A point of confusion/frustration on chained actions

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
_______________________________________________
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