| CatalystX-Declare documentation | Contained in the CatalystX-Declare distribution. |
CatalystX::Declare::Keyword::Controller - Declare Catalyst Controllers
controller MyApp::Web::Controller::Example
extends MyApp::Web::ControllerBase::CRUD
with MyApp::Web::ControllerRole::Caching {
$CLASS->config(option_name => 'value');
has attr => (is => 'rw', lazy_build => 1);
method _build_attr { 'Hello World' }
action base as '';
final action site, under base {
$ctx->response->body( $self->attr );
}
}
This handler module allows the declaration of Catalyst controllers. The
controller keyword is an extension of the
CatalystX::Declare::Keyword::Component, which in turn is an extension
of class in MooseX::Declare with all the
bells and whistles, including extends, with, method and modifier
declarations.
In addition to the keywords and features provided by MooseX::Declare, you can also specify your controller's actions declaratively. For the whole truth about the syntax refer to CatalystX::Declare::Keyword::Action.
For controller roles, please see CatalystX::Declare::Keyword::Role. You can
extend controllers with the extends keyword and consume roles via with as
usual.
These methods are implementation details. Unless you are extending or developing CatalystX::Declare, you should not be concerned with them.
Object->add_namespace_customizations (Object $ctx, Str $package)
This method modifier will initialise the controller with MooseX::MethodAttributes and add the CatalystX::Declare::Controller::ActionPreparation and CatalystX::Declare::Controller::DetermineActionClass controller roles before calling the original.
Str Object->default_superclasses ()
Returns Catalyst::Controller as the default superclass for all declared controllers.
Object->add_with_option_customizations (
Object $ctx,
Str $package,
ArrayRef $roles,
HashRef $options,
)
This hook method will be called by MooseX::Declare when with options were
encountered. Since 0.011 the roles will be applied all at once.
This method will also add a callback to make the controller immutable to the
cleanup code parts unless is mutable was specified.
Bool Object->auto_make_immutable ()
Returns 0, indicating that MooseX::Declare should not make this class
immutable by itself. We will do that in the add_with_option_customizations
method ourselves.
ArrayRef[Object] Object->default_inner ()
A method modifier around the original. The inner syntax handlers inherited by
MooseX::Declare::Syntax::Keyword::Class are extended with instances of the
CatalystX::Declare::Keyword::Action handler class for the action,
under and final identifiers.
See AUTHOR in CatalystX::Declare for author information.
This program is free software; you can redistribute it and/or modify it under the same terms as perl itself.
| CatalystX-Declare documentation | Contained in the CatalystX-Declare distribution. |
use MooseX::Declare; use Catalyst::Controller; class CatalystX::Declare::Keyword::Controller extends CatalystX::Declare::Keyword::Component { use MooseX::MethodAttributes (); use aliased 'CatalystX::Declare::Keyword::Action', 'ActionKeyword'; use aliased 'CatalystX::Declare::Controller::DetermineActionClass'; use aliased 'CatalystX::Declare::Controller::Meta::TypeConstraintMapping'; use aliased 'CatalystX::Declare::Controller::ActionPreparation'; use Data::Dump qw( pp ); before add_namespace_customizations (Object $ctx, Str $package) { MooseX::MethodAttributes->init_meta(for_class => $package); $ctx->add_preamble_code_parts( ['BEGIN', sprintf('Class::MOP::load_class(q(%s))', TypeConstraintMapping), sprintf('%s->meta->apply(%s->meta->meta)', TypeConstraintMapping, $package), ], ); } after add_extends_option_customizations (Object $ctx, Str $package, $superclasses, $options) { $ctx->add_scope_code_parts( sprintf('with qw( %s )', join ' ', DetermineActionClass, ActionPreparation, ), ); } method default_superclasses { 'Catalyst::Controller::ActionRole' } method auto_make_immutable { 0 } around default_inner { my @modifiers = qw( ); return [ ( grep { my $id = $_->identifier; not grep { $id eq $_ } @modifiers } @{ $self->$orig() || [] } ), ActionKeyword->new(identifier => 'action'), ActionKeyword->new(identifier => 'under'), ActionKeyword->new(identifier => 'final'), ]; } method add_with_option_customizations (Object $ctx, $package, ArrayRef $roles, HashRef $options) { $package = $ctx->qualify_namespace($package); $ctx->add_cleanup_code_parts('Moose::Util::apply_all_roles("' . $package . '", qw/' . join(' ', map { $ctx->qualify_namespace($_) } @$roles) . '/)') if scalar @$roles; $ctx->add_cleanup_code_parts( sprintf '%s->meta->make_immutable', $package ) unless $options->{is}{mutable}; } } __END__