[Catalyst] ActionClass vs. Moose Role?

Tomas Doran bobtfish at bobtfish.net
Sun Aug 30 17:16:34 GMT 2009


On 28 Aug 2009, at 19:05, Bill Moseley wrote:
> Well, if you were going to write something like RenderView now would  
> you still write it as an ActionClass?

Yes, as Render view isn't something I would ever want two of them on  
the same action.

As a counter example, Catalyst::ActionRole::ACL is _much better_ as an  
action role, as then it plays nicely with Catalyst::Action::REST  
(which should itself be an actionrole!) and other things..

> The purpose is to have a standard end() that I use in multiple  
> applications -- similar to RenderView as I mentioned.

Yeah, in your case, I would probably just go with a controller role  
which wraps the end method, as this is conceptually simpler than an  
actionclass, but either is a perfectly appropriate decision.

> Anyway, using "before 'end'" is probably the way to go in the role  
> instead of "sub end".

Yes, that's significantly better, due to the fact that methods from  
roles will be silently ignored if the local class has a method of that  
name.

What I'd be doing is something like this:

package MyApp::Role::Foo;
use Moose::Role -traits => 'MethodAttributes';

sub end : Action {}

before 'end' => sub { # Your code here };

package MyApp::Controller::Foo;
use Moose;
BEGIN { extends 'Catalyst::Controller' }
with 'MyApp::Role::Foo';

# Works like this, OR you can say:
# sub end : Action {
#     # Your code here, will get wrapped with your modifier.
# }

> BTW -- will the helpers for catalyst.pl start generating Moose-ified  
> context and controller classes at some point soon?

Yes, this is in the pipeline right now - but nobody has wanted to  
tackle it till the GSOC -Devel refactoring is complete. This is  
hopefully going to be brushed up and merged fairly soon now. :)

Cheers
t0m




More information about the Catalyst mailing list