3 class CatalystX::Declare::Keyword::Controller
4 extends CatalystX::Declare::Keyword::Component {
6 use MooseX::MethodAttributes ();
7 use aliased 'CatalystX::Declare::Keyword::Action', 'ActionKeyword';
8 use aliased 'CatalystX::Declare::Controller::RegisterActionRoles';
9 use aliased 'CatalystX::Declare::Controller::DetermineActionClass';
10 use aliased 'CatalystX::Declare::Controller::Meta::TypeConstraintMapping';
12 use Data::Dump qw( pp );
15 before add_namespace_customizations (Object $ctx, Str $package) {
17 MooseX::MethodAttributes->init_meta(for_class => $package);
19 $ctx->add_preamble_code_parts(
21 sprintf('Class::MOP::load_class(q(%s))', TypeConstraintMapping),
22 sprintf('%s->meta->apply(%s->meta->meta)', TypeConstraintMapping, $package),
24 sprintf('with qw( %s )', join ' ',
31 method default_superclasses { 'Catalyst::Controller' }
33 method auto_make_immutable { 0 }
35 around default_inner () {
37 my @modifiers = qw( );
40 ( grep { my $id = $_->identifier; not grep { $id eq $_ } @modifiers } @{ $self->$orig() || [] } ),
41 ActionKeyword->new(identifier => 'action'),
42 ActionKeyword->new(identifier => 'under'),
43 ActionKeyword->new(identifier => 'final'),
47 method add_with_option_customizations (Object $ctx, $package, ArrayRef $roles, HashRef $options) {
49 $ctx->add_cleanup_code_parts(
51 sprintf('Class::MOP::load_class(%s)', pp "$_"),
52 sprintf('%s->meta->apply(%s->meta)', $_, $package),
56 $ctx->add_cleanup_code_parts(
57 sprintf '%s->meta->make_immutable', $package
58 ) unless $options->{is}{mutable};
66 CatalystX::Declare::Keyword::Controller - Declare Catalyst Controllers
70 controller MyApp::Web::Controller::Example
71 extends MyApp::Web::ControllerBase::CRUD
72 with MyApp::Web::ControllerRole::Caching {
75 $CLASS->config(option_name => 'value');
78 has attr => (is => 'rw', lazy_build => 1);
80 method _build_attr { 'Hello World' }
85 final action site, under base {
86 $ctx->response->body( $self->attr );
92 This handler module allows the declaration of Catalyst controllers. The
93 C<controller> keyword is an extension of the
94 L<CatalystX::Declare::Keyword::Component>, which in turn is an extension
95 of L<MooseX::Declare/class> with all the
96 bells and whistles, including C<extends>, C<with>, C<method> and modifier
99 In addition to the keywords and features provided by L<MooseX::Declare>, you
100 can also specify your controller's actions declaratively. For the whole truth
101 about the syntax refer to L<CatalystX::Declare::Keyword::Action>.
103 For controller roles, please see L<CatalystX::Declare::Keyword::Role>. You can
104 extend controllers with the C<extends> keyword and consume roles via C<with> as
111 =item L<CatalystX::Declare::Keyword::Component>
117 These methods are implementation details. Unless you are extending or
118 developing L<CatalystX::Declare>, you should not be concerned with them.
120 =head2 add_namespace_customizations
122 Object->add_namespace_customizations (Object $ctx, Str $package)
124 This method modifier will initialise the controller with
125 L<MooseX::MethodAttributes> and add the
126 L<CatalystX::Declare::Controller::RegisterActionRoles> and
127 L<CatalystX::Declare::Controller::DetermineActionClass> controller roles
128 before calling the original.
130 =head2 default_superclasses
132 Str Object->default_superclasses ()
134 Returns L<Catalyst::Controller> as the default superclass for all declared
137 =head2 add_with_option_customizations
139 Object->add_with_option_customizations (
146 This hook method will be called by L<MooseX::Declare> when C<with> options were
147 encountered. It will load the specified class and apply them to the controller
148 one at a time. This will change in the future, and they will be all applied
151 This method will also add a callback to make the controller immutable to the
152 cleanup code parts unless C<is mutable> was specified.
154 =head2 auto_make_immutable
156 Bool Object->auto_make_immutable ()
158 Returns C<0>, indicating that L<MooseX::Declare> should not make this class
159 immutable by itself. We will do that in the L</add_with_option_customizations>
164 ArrayRef[Object] Object->default_inner ()
166 A method modifier around the original. The inner syntax handlers inherited by
167 L<MooseX::Declare::Syntax::Keyword::Class> are extended with instances of the
168 L<CatalystX::Declare::Keyword::Action> handler class for the C<action>,
169 C<under> and C<final> identifiers.
175 =item L<CatalystX::Declare>
177 =item L<CatalystX::Declare::Keyword::Action>
179 =item L<CatalystX::Declare::Keyword::Component>
181 =item L<MooseX::Declare/class>
187 See L<CatalystX::Declare/AUTHOR> for author information.
191 This program is free software; you can redistribute it and/or modify it under
192 the same terms as perl itself.