NAME

CatalystX::Declare::Keyword::Role - Declare Catalyst Controller Roles

SYNOPSIS

use CatalystX::Declare;

controller_role MyApp::Web::ControllerRole::Foo {

    method provided_method { ... }

    action foo, under base, is final { ... }

    around bar_action (Object $ctx) { ... }
}

controller_role MyApp::Web::ControllerRole::WithParam (Str :$msg!) {

    final action message under base {
        $ctx->stash(message => $msg);
    }
}

DESCRIPTION

This handler provides the controller_role keyword. It is an extension of the MooseX::Declare::Syntax::Keyword::Role handler. Like with declared controllers, the method keyword and the modifiers are provided. For details on the syntax for action declarations have a look at CatalystX::Declare::Keyword::Action, which also documents the effects of method modifiers on actions.

Parameters

You can use a parameter signature containing named parameters for a role. To apply the controller role in the "SYNOPSIS", you'd use code like this:

controller MyApp::Web::Controller::Hello {
    with 'MyApp::Web::ControllerRole::WithParam' => { msg => 'Hello!' };

    action base under '/' as '';
}

You can currently only use the parameters in action declarations in the body, te name, the as path part and the under base action specification:

controller_role Foo (Str :$base, Str :$part) {

    action foo under $base as $part { ... }
}

You can specify the parameters either as plain scalar variables or as quoted strings. The latter is especially useful for more complex path parts:

action foo under $base as "$pathpart/fnord" { ... }

To use it in the action name is rather simple:

final action $foo { ... }

You might want to use the as $foo option to specify a path part instead, though. Use the dynamic action name possibility only if you are really concerned with the name of the generated method, not only the path the action is reachable under.

SUPERCLASSES

MooseX::Declare::Syntax::Keyword::Role

METHODS

add_namespace_customizations

Object->add_namespace_customizations (Object $ctx, Str $package)

This hook is called by MooseX::Declare and will set the package up as a role and apply MooseX::MethodAttributes.

default_inner

ArrayRef[Object] Object->default_inner ()

Same as "default_inner" in CatalystX::Declare::Keyword::Class.

SEE ALSO

CatalystX::Declare
"role" in MooseX::Declare
CatalystX::Declare::Keyword::Action
CatalystX::Declare::Keyword::Controller

AUTHOR

See "AUTHOR" in CatalystX::Declare for author information.

LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as perl itself.