[Catalyst] Questions about chained actions, endpoints, etc.
Danny Warren
danny at io.com
Wed Mar 21 22:13:17 GMT 2007
A couple of clarifications:
1) I typo'd 'sub sub' below in the 'add' action, whoops!
2) In my example, I should have used 'detail' as the action instead of
'view', to match your layout ('view' is what I use).
3) I think the general confusion on all of this, and I didn't wrap my
head around this when I read the Chained perldoc at first either (even
though reading it again, it makes sense) is how the 'Chained' attribute
behaves. A general rule of thumb I keep in my head is (and this doesn't
apply in all situations and special cases, but stays true for most
normal chain layouts I have used)...
When dealing with 'CaptureArgs' type methods, the 'Chained' attribute
refers to parts of the URI path.
When dealing with 'Args' type endpoint actions, the 'Chained' attribute
refers to the 'CaptureArgs' method we want to chain off of, and has
nothing to do with the URI path.
Danny Warren
Danny Warren wrote:
> 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/[email protected]/
>> Dev site: http://dev.catalyst.perl.org/
>
> _______________________________________________
> List: Catalyst at lists.rawmode.org
> Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/[email protected]/
> Dev site: http://dev.catalyst.perl.org/
>
>
More information about the Catalyst
mailing list