Skip to content

ajgb/catalyst-controller-actionrole

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Catalyst-TraitFor-Controller-ActionRole

INSTALLATION

To install this module, run the following commands:

	perl Build.PL
	./Build
	./Build test
	./Build install

SYNOPSIS
        package MyApp::Controller::Foo;

        BEGIN { extends 'Catalyst::Controller'; }

        with qw/Catalyst::TraitFor::Controller::ActionRole/;

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

DESCRIPTION
    This module allows to apply 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;

        BEGIN { extends 'Catalyst::Controller'; }

        with 'Catalyst::TraitFor::Controller::ActionRole' => {
            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
        sub moo : Local { ... }

    Additionally roles could 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;

        BEGIN { extends 'Catalyst::Controller'; }

        with 'Catalyst::TraitFor::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 { ... }

    Please note that above example shows "action_roles" specified with
    "__PACKAGE__->config()".

PARAMETERS
    This module can be configured with following parameters.

  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 an
    "action_roles" argument as the role parameter or via
    "__PACKAGE__->config()". The same expansions as for "Does" will be
    performed.

    Please note that roles specified with action_roles are not applied to
    methods with names starting with underscore.

ATTRIBUTES
  _action_role_prefix
    Returns the value of "action_role_prefix" role parameter.

  _action_roles
    Returns the value of "action_roles" role parameter.

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" parameter.

AUTHORS
        Alex J. G. Burzyński <[email protected]>
        Florian Ragwitz <[email protected]>
        Hans Dieter Pearcey <[email protected]>

BUGS
    Please report any bugs or feature requests to
    "bug-catalyst-traitfor-controller-actionrole at rt.cpan.org", or through
    the web interface at
    <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-TraitFor-Contro
    ller-ActionRole>. I will be notified, and then you'll automatically be
    notified of progress on your bug as I make changes.

ACKNOWLEDGEMENTS
    This module wouldn't exists without initial
    Catalyst::Controller::ActionRole upon which it is heavily based.

LICENSE AND COPYRIGHT
    Copyright 2010 Alex J. G. Burzyński.

    This program is free software; you can redistribute it and/or modify it
    under the terms of either: the GNU General Public License as published
    by the Free Software Foundation; or the Artistic License.

    See http://dev.perl.org/licenses/ for more information.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Perl 100.0%