3 class CatalystX::Declare::Keyword::Role
4 extends MooseX::Declare::Syntax::Keyword::Role {
7 use aliased 'MooseX::MethodAttributes::Role::Meta::Role';
8 use aliased 'MooseX::Role::Parameterized::Meta::Role::Parameterizable';
9 use aliased 'CatalystX::Declare::Keyword::Action', 'ActionKeyword';
12 around import_symbols_from (Object $ctx) {
14 $ctx->has_parameter_signature
16 : sprintf('Moose::Role -traits => q(MethodAttributes),')
19 before add_namespace_customizations (Object $ctx, Str $package) {
21 my $source = $self->import_symbols_from($ctx);
22 my @symbols = $self->imported_moose_symbols;
24 $ctx->add_preamble_code_parts(
29 after add_namespace_customizations (Object $ctx, Str $package) {
31 $ctx->add_preamble_code_parts(
33 'use %s -traits => q(%s), qw( has )',
34 'MooseX::Role::Parameterized',
35 'MooseX::MethodAttributes::Role::Meta::Role',
37 ) if $ctx->has_parameter_signature;
40 around default_inner (@args) {
43 @{ $self->$orig(@args) },
44 ActionKeyword->new(identifier => 'action'),
45 ActionKeyword->new(identifier => 'under'),
46 ActionKeyword->new(identifier => 'final'),
55 CatalystX::Declare::Keyword::Role - Declare Catalyst Controller Roles
59 use CatalystX::Declare;
61 controller_role MyApp::Web::ControllerRole::Foo {
63 method provided_method { ... }
65 action foo, under base, is final { ... }
67 around bar_action (Object $ctx) { ... }
70 controller_role MyApp::Web::ControllerRole::WithParam (Str :$msg!) {
72 final action message under base {
73 $ctx->stash(message => $msg);
79 This handler provides the C<controller_role> keyword. It is an extension of the
80 L<MooseX::Declare::Syntax::Keyword::Role> handler. Like with declared
81 controllers, the C<method> keyword and the modifiers are provided. For details
82 on the syntax for action declarations have a look at
83 L<CatalystX::Declare::Keyword::Action>, which also documents the effects of
84 method modifiers on actions.
88 You can use a parameter signature containing named parameters for a role. To
89 apply the controller role in the L</SYNOPSIS>, you'd use code like this:
91 controller MyApp::Web::Controller::Hello {
92 with 'MyApp::Web::ControllerRole::WithParam' => { msg => 'Hello!' };
94 action base under '/' as '';
97 You can currently only use the parameters in action declarations in the body,
98 te name, the C<as> path part and the C<under> base action specification:
100 controller_role Foo (Str :$base, Str :$part) {
102 action foo under $base as $part { ... }
105 You can specify the parameters either as plain scalar variables or as quoted
106 strings. The latter is especially useful for more complex path parts:
108 action foo under $base as "$pathpart/fnord" { ... }
110 To use it in the action name is rather simple:
112 final action $foo { ... }
114 You might want to use the C<as $foo> option to specify a path part instead,
115 though. Use the dynamic action name possibility only if you are really
116 concerned with the name of the generated method, not only the path the
117 action is reachable under.
123 =item L<MooseX::Declare::Syntax::Keyword::Role>
129 =head2 add_namespace_customizations
131 Object->add_namespace_customizations (Object $ctx, Str $package)
133 This hook is called by L<MooseX::Declare> and will set the package up as a role
134 and apply L<MooseX::MethodAttributes>.
138 ArrayRef[Object] Object->default_inner ()
140 Same as L<CatalystX::Declare::Keyword::Class/default_inner>.
146 =item L<CatalystX::Declare>
148 =item L<MooseX::Declare/role>
150 =item L<CatalystX::Declare::Keyword::Action>
152 =item L<CatalystX::Declare::Keyword::Controller>
158 See L<CatalystX::Declare/AUTHOR> for author information.
162 This program is free software; you can redistribute it and/or modify it under
163 the same terms as perl itself.