[Catalyst-dev] Issue with calling methods on the Action object

John Napiorkowski jjn1056 at yahoo.com
Thu Feb 8 21:36:26 GMT 2007


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.

For example, say I have an action class like:

package TestApp::Action::Test;

use strict;
use warnings;

use base qw/Catalyst::Action/;

__PACKAGE__->mk_accessors(qw/test/);

sub trivial
{
  my ( $self, @args ) = (shift, @_);
  return 1;
}

1;

And this Action Class is used inside a Controller
like:

[setup the controller]

sub act1 :Local ActionClass('+TestApp::Action::Test')
{
  my ($self, $c) = @_;

  my $ret1 = $c->action->trivial(); #Is 1

  $c->action->test('some value')
  my $ret2 = $c->action->test();  #Is 'some value'
}

Okay, this is fine, but if these are chained actions
it fails, because the ActionChain object can't pass
along the method calls to the corresponding Action. 
It just dies.

Attached is a patch against SVN with tests that shows
this issue.

I'm not sure how hard this would be to fix; do you
think having AUTOLOAD in ActionChain dispatch to the
Action if the Action has the asked for methods would
do it?  I can work on this if we can figure out the
best solution.

Thanks!

--John


 
____________________________________________________________________________________
8:00? 8:25? 8:40? Find a flick in no time 
with the Yahoo! Search movie showtime shortcut.
http://tools.search.yahoo.com/shortcuts/#news
-------------- next part --------------
A non-text attachment was scrubbed...
Name: action_issues.patch
Type: application/octet-stream
Size: 4169 bytes
Desc: 3439785680-action_issues.patch
Url : http://lists.scsys.co.uk/pipermail/catalyst-dev/attachments/20070208/3edb0a1b/action_issues.obj


More information about the Catalyst-dev mailing list