[Catalyst] Very basic chained question

will trillich will.trillich at serensoft.com
Wed Jan 18 05:20:31 GMT 2012


Don't forget -- A method (sub) with :CaptureArgs() is a link in the chain,
and one with :Args() is the end of a chain. So,

sub base :PathPart('/member/profile') CaptureArgs(0) { ... }
sub edit :PathPart('edit') Chained('base') Args(0) { ... } # Args(), not
CaptureArgs()
sub image :PathPart('image') Chained('edit') Args(0) { ... } # Args(), not
CaptureArgs()

And within your methods you can
$c->forward('/member/profile/edit',[$additional,$args]) as needed.

Often we have a paradigm like so:

# method /auth would handle user authentication in the Root controller,
then...

sub base : Chained('/auth') PathPart('/path') *CaptureArgs*(0) {} # prepare
for /path items

sub list : Chained('base') PathPart('') *Args*(0) {} # do a listing, like
index.html
sub new : Chained('base') PathPart('new') *Args*(0) {} # handle /path/new
to create a new item

sub item : Chained('base') PathPart('') *CaptureArgs*(1) {} # prepare for
item 'xyz' as in /path/xyz

sub show : Chained('item') PathPart('') *Args*(0) {} # handle /path/xyz,
display the item
sub edit : Chained('item') PathPart('edit') *Args*(0) {} # handle
/path/xyz/edit
sub delete : Chained('item') PathPart('delete') *Args*(0) {} # handle
/path/xyz/delete

CaptureArgs() indicates a method that does some preparation (usually in
$c->stash) for other intermediate and final methods to utilize, and Args()
is the final method in the chain that does the true 'handling' of the
request. (Also read up on 'begin' and 'end' and 'auto' methods at
http://search.cpan.org/~hkclark/Catalyst-Manual-5.9002/lib/Catalyst/Manual/=
Intro.pod#Built-in_special_actions
.)



On Tue, Jan 17, 2012 at 10:10 PM, Santiago Zarate <santiago at zarate.net.ve>w=
rote:

> Hello, if i'm not mistaken, you could just do:
>
> sub base :PathPart('/member/profile') CaptureArgs(0) { ... }
>
> sub edit :PathPart('edit') Chained('base') CaptureArgs(0) { ... }
>
> sub image :PathPart('image') Chained('edit') CaptureArgs(0) { ... }
>
> That should do it, there's a very easy to understand doc at the
> catalyst's wiki [1]
>
> [1]
> http://wiki.catalystframework.org/wiki/gettingstarted/howtos/chainedexamp=
les
>
> On Tue, Jan 17, 2012 at 10:56 PM, Fagyal Csongor
> <concept at conceptonline.hu> wrote:
> > Hi,
> >
> > Sorry about this basic question, but I am kind of lost when it comes to
> > chained dispatching.
> >
> > I have a controller "Members::Profile" with methods "edit" and "images".
> >
> > I would like "edit" called with the URL "/members/profile/edit", and
> > "images" and *after that* "edit" called with
> "/members/profile/edit/images".
> >
> > I thought this should look something like as:
> > sub edit: Local Args(0) { ... }
> > sub images: PathPart('images') Chained('edit') { ... }
> >
> > But obviously I misunderstand something.
> >
> > I have also tried:
> > sub edit :PathPart('edit') Chained('') CaptureArgs(0) { ... }
> > sub images :PathPart('images') Chained('edit') Args(0) { ... }
> >
> > I guess this clearly shows I just have no idea how this is supposed to
> work
> > :)
> >
> > It actually works if I add another method like this:
> > sub edit :PathPart('members/profile/edit') Chained('/') CaptureArgs(0) {
> ...
> > }
> > sub images :PathPart('images') Chained('edit') Args(0) { ... }
> > sub root : PathPart('') Chained('edit') Args(0) { ... }
> >
> > This kind of looks logical, but it don't think this is what I should do:
> I
> > don't like the PathPart for edit, and the extra method either.
> >
> >
> > So how do I do this properly?
> >
> > Thanks,
> > - Fagzal
> >
> >
> >
> > _______________________________________________
> > 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/
>
>
>
> --
> Santiago Zarate
> Consultoria de Software || Software Consulting
>   +(507) 64271684
>   Skype: santiago-ve
>   BB PIN: 23929BFE
>   santiago at zarate.net.ve
>
> "La mejor forma de hacer que un adolecente lea un libro es vetandolo.
> Cuando alguien que ostenta una figura de autoridad dice, 'Danos tu
> libro', creo que esos estudiantes piensan 'Debe haber algo poderoso en
> esas palabras'." - Erin Gruwell
>
> "The best way to get a teenager to read a book is to ban it. When
> someone who is a daunting authority figure says, 'Give us your book',
> I think these students [thought], 'There must be something powerful in
> these words'. " - Erin Gruwell
>
> _______________________________________________
> 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/
>



-- =

"We act as though comfort and luxury were the chief requirements of life,
when all that we need to make us happy is something to be enthusiastic
about." -- Albert Einstein
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20120117/19452=
bc9/attachment.htm


More information about the Catalyst mailing list