implemented action dispatching by type
[catagits/CatalystX-Declare.git] / lib / CatalystX / Declare / Keyword / Controller.pm
index 56c8b6c..8d8aaca 100644 (file)
@@ -1,14 +1,14 @@
 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 );
 
@@ -16,11 +16,21 @@ class CatalystX::Declare::Keyword::Controller
     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,
             ),
         );
     }
@@ -29,31 +39,33 @@ class CatalystX::Declare::Keyword::Controller
 
     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__
@@ -87,7 +99,9 @@ CatalystX::Declare::Keyword::Controller - Declare Catalyst Controllers
 =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.
 
@@ -103,15 +117,7 @@ usual.
 
 =over
 
-=item L<MooseX::Declare::Syntax::Keyword::Class>
-
-=back
-
-=head1 ROLES
-
-=over
-
-=item L<CatalystX::Declare::DefaultSuperclassing>
+=item L<CatalystX::Declare::Keyword::Component>
 
 =back
 
@@ -125,8 +131,8 @@ developing L<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 
-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.
 
@@ -137,14 +143,6 @@ 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 (
@@ -162,6 +160,14 @@ together.
 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 ()
@@ -179,6 +185,8 @@ C<under> and C<final> identifiers.
 
 =item L<CatalystX::Declare::Keyword::Action>
 
+=item L<CatalystX::Declare::Keyword::Component>
+
 =item L<MooseX::Declare/class>
 
 =back