use MooseX::Declare;
+use Catalyst::Controller;
-class CatalystX::Declare::Keyword::Controller
- extends MooseX::Declare::Syntax::Keyword::Class
- with CatalystX::Declare::DefaultSuperclassing {
-
+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::RegisterActionRoles';
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(
- 'use CLASS',
+ ['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 ' ',
- RegisterActionRoles,
DetermineActionClass,
+ ActionPreparation,
),
);
}
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(
map {
sprintf('Class::MOP::load_class(%s)', pp "$_"),
sprintf('%s->meta->apply(%s->meta)', $_, $package),
- } @$roles
+ } map { $ctx->qualify_namespace($_) } @$roles
);
$ctx->add_cleanup_code_parts(
sprintf '%s->meta->make_immutable', $package
) unless $options->{is}{mutable};
}
-
- 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'),
- ];
- }
}
__END__
=head1 DESCRIPTION
This handler module allows the declaration of Catalyst controllers. The
-C<controller> keyword is an extension of L<MooseX::Declare/class> with all the
+C<controller> keyword is an extension of the
+L<CatalystX::Declare::Keyword::Component>, which in turn is an extension
+of L<MooseX::Declare/class> with all the
bells and whistles, including C<extends>, C<with>, C<method> and modifier
declarations.
=over
-=item L<MooseX::Declare::Syntax::Keyword::Class>
-
-=back
-
-=head1 ROLES
-
-=over
-
-=item L<CatalystX::Declare::DefaultSuperclassing>
+=item L<CatalystX::Declare::Keyword::Component>
=back
Object->add_namespace_customizations (Object $ctx, Str $package)
This method modifier will initialise the controller with
-L<MooseX::MethodAttributes>, import L<CLASS> and add the
-L<CatalystX::Declare::Controller::RegisterActionRoles> and
+L<MooseX::MethodAttributes> and add the
+L<CatalystX::Declare::Controller::ActionPreparation> and
L<CatalystX::Declare::Controller::DetermineActionClass> controller roles
before calling the original.
Returns L<Catalyst::Controller> as the default superclass for all declared
controllers.
-=head2 auto_make_immutable
-
- Bool Object->auto_make_immutable ()
-
-Returns C<0>, indicating that L<MooseX::Declare> should not make this class
-immutable by itself. We will do that in the L</add_with_option_customizations>
-method ourselves.
-
=head2 add_with_option_customizations
Object->add_with_option_customizations (
This method will also add a callback to make the controller immutable to the
cleanup code parts unless C<is mutable> was specified.
+=head2 auto_make_immutable
+
+ Bool Object->auto_make_immutable ()
+
+Returns C<0>, indicating that L<MooseX::Declare> should not make this class
+immutable by itself. We will do that in the L</add_with_option_customizations>
+method ourselves.
+
=head2 default_inner
ArrayRef[Object] Object->default_inner ()
=item L<CatalystX::Declare::Keyword::Action>
+=item L<CatalystX::Declare::Keyword::Component>
+
=item L<MooseX::Declare/class>
=back