[Catalyst] Chained('.') counter-intuitive?
John Napiorkowski
jjn1056 at yahoo.com
Fri Nov 10 15:59:21 GMT 2006
--- Pedro Melo <melo at simplicidade.org> wrote:
> Hi,
>
> I've been learning to use chained actions in the
> past few hours, and
> I must say I admire the though that went into them
> and the default
> values for each attribute, they are extremely
> elegant.
>
> The only issue I have is with Chained('.').
>
> I prefer to keep the actions related to the same
> concept in the same
> controller. For example, if I have a Film
> controller, I expect to
> find there the view and delete actions, for example.
>
> With chained actions, I also expect to see this type
> of urls:
>
> /films/1/view
> /films/2/delete
>
> Right now I have to write this:
>
> package cad::Controller::Films;
>
> use strict;
> use warnings;
> use base 'Catalyst::Controller';
>
> sub films : Chained CaptureArgs(1) {}
> sub view : Chained('films') Args(0) {}
> sub delete : Chained('films') Args(0) {}
>
> I was expecting to write Chained('.') in sub view
> and sub delete, but
> to do that I would have to move them to a different
> controller,
> cad::Controller::Films::View and C::Films::Delete.
>
> My reasoning is that '.' is the current controller,
> not the parent
> controller. I would use '..' for that one...
>
> Any thoughs?
I've also wished I could do this. I often do
something like:
package myapp::Controller::members
sub members :Chained('/') CaptureArgs(0) {}
sub member :Chained('members') CaptureArgs(1) {}
package myapp::Controller::members::member
sub friends :Chained('.') CaptureArgs(0) {}
Now I can use the Chained('.') in the second package
and it will map '.' to '/members/member' based on the
package name, which is a private name to the action in
the 'parent' controller, right? This is great and
makes it easy with my data model to find exactly what
I need.
Based on this you'd think you could change:
sub member :Chained('members') CaptureArgs(1) {}
to:
sub member :Chained('.') CaptureArgs(1) {}
But I can never get this to work. I would assume that
'.' would map to '/members', based on the controller
action namespace, but it doesn't seem to do that.
I would this it would work, based on the following
from Chained.pm:
if (defined($parent) && length($parent)) {
if ($parent eq '.') {
$parent = '/'.$action->namespace;
} .....
Anyone out there know if this is supposed to work?
It would be great if I could figure this out, it would
reduce some of the boilerplate code in my controllers.
Actually the controllers are starting to look pretty
bare for me, since I've refactored a lot of the
activity into action classes.
--john
>
> best regards,
> --
> Pedro Melo
> JID: xmpp:melo at simplicidade.org
>
>
>
> _______________________________________________
> 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/
>
____________________________________________________________________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com
More information about the Catalyst
mailing list