af904ee9fbc24254dacd913fdb266fdb1f803e83
[catagits/CatalystX-Declare.git] / lib / CatalystX / Declare / Keyword / Role.pm
1 use MooseX::Declare;
2
3 class CatalystX::Declare::Keyword::Role
4     extends MooseX::Declare::Syntax::Keyword::Role {
5
6
7     use aliased 'MooseX::MethodAttributes::Role::Meta::Role';
8     use aliased 'CatalystX::Declare::Keyword::Action', 'ActionKeyword';
9
10
11     before add_namespace_customizations (Object $ctx, Str $package) {
12
13         $ctx->add_preamble_code_parts(
14             'use CLASS',
15             'use Moose::Role -traits => q(MethodAttributes)',
16         );
17     }
18
19     around default_inner {
20
21         my @modifiers = qw( );
22
23         return [ 
24             ( grep { my $id = $_->identifier; not grep { $id eq $_ } @modifiers } @{ $self->$orig() || [] } ),
25             ActionKeyword->new(identifier => 'action'),
26             ActionKeyword->new(identifier => 'under'),
27             ActionKeyword->new(identifier => 'final'),
28         ];
29     }
30 }
31
32 __END__
33
34 =head1 NAME
35
36 CatalystX::Declare::Keyword::Role - Declare Catalyst Controller Roles
37
38 =head1 SYNOPSIS
39
40     use CatalystX::Declare;
41
42     controller_role MyApp::Web::ControllerRole::Foo {
43
44         method provided_method { ... }
45
46         action foo, under base, is final { ... }
47
48         around bar_action (Object $ctx) { ... }
49     }
50
51 =head1 DESCRIPTION
52
53 This handler provides the C<controller_role> keyword. It is an extension of the
54 L<MooseX::Declare::Syntax::Keyword::Role> handler. Like with declared 
55 controllers, the C<method> keyword and the modifiers are provided. For details
56 on the syntax for action declarations have a look at
57 L<CatalystX::Declare::Keyword::Action>, which also documents the effects of
58 method modifiers on actions.
59
60 =head1 SUPERCLASSES
61
62 =over
63
64 =item L<MooseX::Declare::Syntax::Keyword::Role>
65
66 =back
67
68 =head1 METHODS
69
70 =head2 add_namespace_customizations
71
72     Object->add_namespace_customizations (Object $ctx, Str $package)
73
74 This hook is called by L<MooseX::Declare> and will set the package up as a role
75 and apply L<MooseX::MethodAttributes>.
76
77 =head2 default_inner
78
79     ArrayRef[Object] Object->default_inner ()
80
81 Same as L<CatalystX::Declare::Keyword::Class/default_inner>.
82
83 =head1 SEE ALSO
84
85 =over
86
87 =item L<CatalystX::Declare>
88
89 =item L<MooseX::Declare/role>
90
91 =item L<CatalystX::Declare::Keyword::Action>
92
93 =item L<CatalystX::Declare::Keyword::Controller>
94
95 =back
96
97 =head1 AUTHOR
98
99 See L<CatalystX::Declare/AUTHOR> for author information.
100
101 =head1 LICENSE
102
103 This program is free software; you can redistribute it and/or modify it under 
104 the same terms as perl itself.
105
106 =cut