[Catalyst] Questions about chained actions, endpoints, etc.

Danny Warren danny at io.com
Wed Mar 21 21:53:09 GMT 2007


This is the same layout I have for my chained actions, and I went 
through the same "huh?" phase as well.

You seem to be on the right track so far.  Here is a quick copy / paste 
/ hack job of my layout adapted to your examples.  Won't go in to too 
much detail since I am busy at work, so let me know if this needs 
clarified further.

In Foo::Controller::Admin (left off "Form" attrib in examples, just 
showing the chain layout)...


# Not chained, responds to /admin
sub index : Private { ... }

# Not chained, responds to /admin/add
sub sub add : Local { ... }

# Captures a book id in the chain for use by further chained actions
# You would validate the id, grab it from the model, and put it in
# the stash here
sub get_book : PathPart('admin') Chained CaptureArgs(1)
{
   my ( $self, $c, $id) = @_;
   ...
}

# Chain endpoint for viewing book, responds to /admin/99
sub view : PathPart('') Chained('get_book') Args(0) { ... }

# Chain endpoint for editing book, responds to /admin/99/edit
sub edit : Chained('get_book') Args(0) { ... }

# Chain endpoint for deleting book, responds to /admin/99/delete
sub delete : Chained('get_book') Args(0) { ... }


Hope that helps!

Danny Warren

Doran L. Barton wrote:
> Hey guys, this very well may be due purely to my lack of experience in this
> matter, but I'm having trouble getting chained actions working the way I
> WANT them to work and I'm suspicious the way I want them to work is not the
> way they're intended to work.
> 
> Here's the situation: I want the application to have public paths like
> these:
> 
>     /admin              List of all existing "books" you can look at
>     /admin/add          Form (FormBuilder) for adding a new book
>     /admin/99           Detailed output of data on book 99
>     /admin/99/edit      Form (FormBuilder) for editing book 99 data
>     /admin/99/delete    Form for confirming deletion of book 99
> 
> Looking at the Catalyst::DispatchType::Chained documentation, it's not
> obvious (to me, anyway) how I should go about this.
> 
> The way I see it, /admin should be handled by a:
>     
>     package Foo::Controller::Admin;
>     sub index : private {...}
> 
> and /admin/add should be handled by a:
> 
>     sub add : Local Form {...}
> 
> So, how exactly would someone suggest I set up the chained handlers for the
> other paths? I had something like this:
> 
>     sub detail :PathPart('admin') Chained('/') Args(1) {...}
>         
> And that worked for the /admin/99 path, but nothing I can muster up seems
> to match the /admin/99/{edit,delete} paths. 
> 
> Any thoughts from those more experienced than me?
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> List: Catalyst at lists.rawmode.org
> Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
> Dev site: http://dev.catalyst.perl.org/



More information about the Catalyst mailing list