2 use Catalyst::Controller;
4 class CatalystX::Declare::Keyword::Controller
5 extends CatalystX::Declare::Keyword::Component {
7 use MooseX::MethodAttributes ();
8 use aliased 'CatalystX::Declare::Keyword::Action', 'ActionKeyword';
9 use aliased 'CatalystX::Declare::Controller::DetermineActionClass';
10 use aliased 'CatalystX::Declare::Controller::Meta::TypeConstraintMapping';
11 use aliased 'CatalystX::Declare::Controller::ActionPreparation';
13 use Data::Dump qw( pp );
16 before add_namespace_customizations (Object $ctx, Str $package) {
18 MooseX::MethodAttributes->init_meta(for_class => $package);
20 $ctx->add_preamble_code_parts(
22 sprintf('Class::MOP::load_class(q(%s))', TypeConstraintMapping),
23 sprintf('%s->meta->apply(%s->meta->meta)', TypeConstraintMapping, $package),
28 after add_extends_option_customizations (Object $ctx, Str $package, $superclasses, $options) {
30 $ctx->add_scope_code_parts(
31 sprintf('with qw( %s )', join ' ',
38 method default_superclasses { 'Catalyst::Controller' }
40 method auto_make_immutable { 0 }
42 around default_inner {
44 my @modifiers = qw( );
47 ( grep { my $id = $_->identifier; not grep { $id eq $_ } @modifiers } @{ $self->$orig() || [] } ),
48 ActionKeyword->new(identifier => 'action'),
49 ActionKeyword->new(identifier => 'under'),
50 ActionKeyword->new(identifier => 'final'),
54 method add_with_option_customizations (Object $ctx, $package, ArrayRef $roles, HashRef $options) {
56 $package = $ctx->qualify_namespace($package);
58 $ctx->add_cleanup_code_parts(
60 sprintf('Class::MOP::load_class(%s)', pp "$_"),
61 sprintf('%s->meta->apply(%s->meta)', $_, $package),
62 } map { $ctx->qualify_namespace($_) } @$roles
65 $ctx->add_cleanup_code_parts(
66 sprintf '%s->meta->make_immutable', $package
67 ) unless $options->{is}{mutable};
75 CatalystX::Declare::Keyword::Controller - Declare Catalyst Controllers
79 controller MyApp::Web::Controller::Example
80 extends MyApp::Web::ControllerBase::CRUD
81 with MyApp::Web::ControllerRole::Caching {
84 $CLASS->config(option_name => 'value');
87 has attr => (is => 'rw', lazy_build => 1);
89 method _build_attr { 'Hello World' }
94 final action site, under base {
95 $ctx->response->body( $self->attr );
101 This handler module allows the declaration of Catalyst controllers. The
102 C<controller> keyword is an extension of the
103 L<CatalystX::Declare::Keyword::Component>, which in turn is an extension
104 of L<MooseX::Declare/class> with all the
105 bells and whistles, including C<extends>, C<with>, C<method> and modifier
108 In addition to the keywords and features provided by L<MooseX::Declare>, you
109 can also specify your controller's actions declaratively. For the whole truth
110 about the syntax refer to L<CatalystX::Declare::Keyword::Action>.
112 For controller roles, please see L<CatalystX::Declare::Keyword::Role>. You can
113 extend controllers with the C<extends> keyword and consume roles via C<with> as
120 =item L<CatalystX::Declare::Keyword::Component>
126 These methods are implementation details. Unless you are extending or
127 developing L<CatalystX::Declare>, you should not be concerned with them.
129 =head2 add_namespace_customizations
131 Object->add_namespace_customizations (Object $ctx, Str $package)
133 This method modifier will initialise the controller with
134 L<MooseX::MethodAttributes> and add the
135 L<CatalystX::Declare::Controller::ActionPreparation> and
136 L<CatalystX::Declare::Controller::DetermineActionClass> controller roles
137 before calling the original.
139 =head2 default_superclasses
141 Str Object->default_superclasses ()
143 Returns L<Catalyst::Controller> as the default superclass for all declared
146 =head2 add_with_option_customizations
148 Object->add_with_option_customizations (
155 This hook method will be called by L<MooseX::Declare> when C<with> options were
156 encountered. It will load the specified class and apply them to the controller
157 one at a time. This will change in the future, and they will be all applied
160 This method will also add a callback to make the controller immutable to the
161 cleanup code parts unless C<is mutable> was specified.
163 =head2 auto_make_immutable
165 Bool Object->auto_make_immutable ()
167 Returns C<0>, indicating that L<MooseX::Declare> should not make this class
168 immutable by itself. We will do that in the L</add_with_option_customizations>
173 ArrayRef[Object] Object->default_inner ()
175 A method modifier around the original. The inner syntax handlers inherited by
176 L<MooseX::Declare::Syntax::Keyword::Class> are extended with instances of the
177 L<CatalystX::Declare::Keyword::Action> handler class for the C<action>,
178 C<under> and C<final> identifiers.
184 =item L<CatalystX::Declare>
186 =item L<CatalystX::Declare::Keyword::Action>
188 =item L<CatalystX::Declare::Keyword::Component>
190 =item L<MooseX::Declare/class>
196 See L<CatalystX::Declare/AUTHOR> for author information.
200 This program is free software; you can redistribute it and/or modify it under
201 the same terms as perl itself.