logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Catalyst::Controller::ActionRole - (DEPRECATED) Apply roles to action instances

Attributes

_action_role_prefix
       This class attribute stores an array reference of role prefixes to search for role names in if they
       aren't prefixed with "+" or "~". It defaults to "[ 'Catalyst::ActionRole::' ]".  See "role prefix
       searching".

   _action_roles
       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.

Author

       Florian Ragwitz <rafl@debian.org>

Contributors

       •   Karen Etheridge <ether@cpan.org>

       •   Tomas Doran <bobtfish@bobtfish.net>

       •   Hans Dieter Pearcey <hdp@weftsoar.net>

       •   Alex J. G. BurzyXski <ajgb@ajgb.net>

       •   Jason Kohles <email@jasonkohles.com>

       •   William King <william.king@quentustech.com>

       •   NAKAGAWA Masaki <masaki.nakagawa@gmail.com>

       •   Joenio Costa <joenio@cpan.org>

       •   John Napiorkowski <jjnapiork@cpan.org>

perl v5.30.3                                       2020-09-27              Catalyst::Controller::ActionRole(3pm)

Deprecation Notice

       As of version 5.90013, Catalyst has merged this functionality into the core Catalyst::Controller.  You
       should no longer use it for new development and we recommend switching to the core controller as soon as
       practical.

Description

       This module allows one to apply Moose::Roles to the "Catalyst::Action"s for different controller methods.

       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 "::ActionRole::" is
       prepended. If it isn't prefixed with "+" or "~", the role name will be searched for in @INC according to
       the rules for role prefix searching.

       It's possible to apply roles to all actions of a controller without specifying the "Does" keyword in
       every action definition:

           package MyApp::Controller::Bar

           use Moose;
           use namespace::autoclean;

           BEGIN { extends 'Catalyst::Controller::ActionRole' }

           __PACKAGE__->config(
               action_roles => ['Foo', '~Bar'],
           );

           # Has Catalyst::ActionRole::Foo and MyApp::ActionRole::Bar applied.
           #
           # If MyApp::ActionRole::Foo exists and is loadable, it will take
           # precedence over Catalyst::ActionRole::Foo.
           #
           # If MyApp::ActionRole::Bar exists and is loadable, it will be loaded,
           # but even if it doesn't exist Catalyst::ActionRole::Bar will not be loaded.
           sub moo : Local { ... }

       Additionally, roles can be applied to selected actions without specifying "Does" using "action" in
       Catalyst::Controller and configured with "action_args" in Catalyst::Controller:

           package MyApp::Controller::Baz;

           use Moose;
           use namespace::autoclean;

           BEGIN { extends 'Catalyst::Controller::ActionRole' }

           __PACKAGE__->config(
               action_roles => [qw( Foo )],
               action       => {
                   some_action    => { Does => [qw( ~Bar )] },
                   another_action => { Does => [qw( +MyActionRole::Baz )] },
               },
               action_args  => {
                   another_action => { customarg => 'arg1' },
               }
           );

           # has Catalyst::ActionRole::Foo and MyApp::ActionRole::Bar applied
           sub some_action : Local { ... }

           # has Catalyst::ActionRole::Foo and MyActionRole::Baz applied
           # and associated action class would get additional arguments passed
           sub another_action : Local { ... }

Methods

gather_action_roles(\%action_args)
       Gathers the list of roles to apply to an action with the given %action_args.

Name

       Catalyst::Controller::ActionRole - (DEPRECATED) Apply roles to action instances

Role Prefix Searching

       Roles specified with no prefix are looked up under a set of role prefixes.  The first prefix is always
       "MyApp::ActionRole::" (with "MyApp" replaced as appropriate for your application); the following prefixes
       are taken from the "_action_role_prefix" attribute.

Synopsis

           package MyApp::Controller::Foo;

           use Moose;
           use namespace::autoclean;

           BEGIN { extends 'Catalyst::Controller::ActionRole' }

           sub bar : Local Does('Moo') { ... }

Version

       version 0.17

See Also