[Catalyst-dev] Issue with calling methods on the Action object
John Napiorkowski
jjn1056 at yahoo.com
Mon Feb 12 15:05:07 GMT 2007
--- Matt S Trout <dbix-class at trout.me.uk> wrote:
>
> On 8 Feb 2007, at 21:36, John Napiorkowski wrote:
>
> > Hi,
> >
> > I noticed there is a difference in the behavior
> when
> > accessing methods on an action depending on if
> that
> > action is part of a chain or not. This is because
> if
> > an action is part of a chain the $c->action
> returns an
> > ActionChain object of the Chain that Action is
> part
> > of.
> >
> > For the most part the ActionChain object trys hard
> to
> > look like the Action object for the current
> action.
> > It uses Overload to help with this. So you can do
> > stuff like $c->action->attributes and so forth.
> It
> > generally will DWIM. However if the Action has a
> > custom ActionClass with it's own methods or
> accessors,
> > then trying to use those methods will return an
> error.
>
> You should really be calling $c->action->chain[-1]
> for this.
>
> The ActionChain only looks like the base Action to
> handle things that
> rely on $c->action looking like that; if you
> actually know it's a
> chain you shouldn't try and use the compat stuff.
My reasoning behind this is that if I'm writing a
generic ActionClass I won't always know if it's going
to be used for a chain or not and the way things work
right now I'd need instructions to handle either case.
Because now you need something like:
my $action = $c->action->can('chain') ?
$c->action->chain[-1] : $c->action;
I can see that in a lot of ways this is good. I do
agree that something that's different should act
different, just right now we have it acting mostly the
same. Because ActionChain will mimic acting like
->action[-1] for a lot of stuff. At least it's same
enough to be confusing to someone that doesn't
understand that $c->action is not an action object
when you are in a chain. I know I wasted hours trying
to figure out what was wrong with my code, so at least
we need to patch the documentation to let people know
this. I think I've seen a few questions about this on
the general list, so I'm pretty sure I'm not the only
one that had this trouble. I've offered a
documentation patch for comments.
If I'm the only one that has a problem with this
behavior then I can just write a plugin to smooth it
over for my custom action classes and that can be the
end of it.
Thanks,
John
>
> --
> Matt S Trout, Technical Director, Shadowcat Systems
> Ltd.
> Offering custom development, consultancy and support
> contracts for
> Catalyst,
> DBIx::Class and BAST. Contact mst (at)
> shadowcatsystems.co.uk for
> details.
> + Help us build a better perl ORM: http://dbix-
> class.shadowcatsystems.co.uk/ +
>
>
>
> _______________________________________________
> Catalyst-dev mailing list
> Catalyst-dev at lists.rawmode.org
>
http://lists.rawmode.org/mailman/listinfo/catalyst-dev
>
____________________________________________________________________________________
We won't tell. Get more on shows you hate to love
(and love to hate): Yahoo! TV's Guilty Pleasures list.
http://tv.yahoo.com/collections/265
-------------- next part --------------
A non-text attachment was scrubbed...
Name: catalyst.diff
Type: application/octet-stream
Size: 820 bytes
Desc: 941238900-catalyst.diff
Url : http://lists.scsys.co.uk/pipermail/catalyst-dev/attachments/20070212/08494592/catalyst.obj
More information about the Catalyst-dev
mailing list