Catalyst::Controller::ActionRole - Apply roles to action instances
version 0.05
package MyApp::Controller::Foo; use parent qw/Catalyst::Controller::ActionRole/; sub bar : Local Does('Moo') { ... }
This module allows to apply roles to the Catalyst::Actions for different controller methods.
Catalyst::Action
For that a Does attribute is provided. That attribute takes an argument, that determines the role, which is going to be applied. If that argument is prefixed with +, it is assumed to be the full name of the role. If it's prefixed with ~, the name of your application followed by ::Action::Role:: is prepended. If it isn't prefixed with + or ~, the value of the _action_role_prefix attribute will be prepended.
Does
+
~
::Action::Role::
_action_role_prefix
Additionally it's possible to to apply roles to all actions of a controller without specifying the Does keyword in every action definition:
package MyApp::Controller::Bar use parent qw/Catalyst::Controller::ActionRole/; __PACKAGE__->config( action_roles => ['Foo', '~Bar'], ); sub moo : Local { ... } # has Catalyst::Action::Role::Foo and MyApp::Action::Role::Bar applied
This class attribute stores a string that is going to be prepended to all role names if they aren't prefixed with + or ~. It defaults to Catalyst::Action::Role::.
Catalyst::Action::Role::
This attribute stores an array reference of role names that will be applied to every action of this controller. It can be set by passing a action_roles argument to the constructor. The same expansions as for Does will be performed.
action_roles
Florian Ragwitz <rafl@debian.org> Hans Dieter Pearcey <hdp@weftsoar.net>
This software is copyright (c) 2009 by Florian Ragwitz.
This is free software; you can redistribute it and/or modify it under the same terms as perl itself.
To install Catalyst::Controller::ActionRole, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::Controller::ActionRole
CPAN shell
perl -MCPAN -e shell install Catalyst::Controller::ActionRole
For more information on module installation, please visit the detailed CPAN module installation guide.