prepping for release
[catagits/CatalystX-Declare.git] / lib / CatalystX / Declare / Controller / ActionPreparation.pm
index 16ad629..66052fe 100644 (file)
@@ -5,17 +5,6 @@ role CatalystX::Declare::Controller::ActionPreparation {
     use aliased 'CatalystX::Declare::Action::CatchValidationError';
     use aliased 'CatalystX::Declare::Dispatching::ChainTypeSensitivity';
 
-
-    method _apply_action_roles (Object $action, @roles) {
-
-        for my $role (CatchValidationError, @roles) {
-            my $fq_role = $self->_qualify_class_name(ActionRole => $role);
-
-            Class::MOP::load_class($fq_role);
-            $fq_role->meta->apply($action);
-        }
-    }
-
     method _find_method_type_constraint (Str $name) {
 
         $self->meta->find_method_type_constraint($name)
@@ -27,6 +16,16 @@ role CatalystX::Declare::Controller::ActionPreparation {
             };
     }
 
+    method _find_method_named_params (Str $name) {
+
+        return $self->meta->find_method_named_params($name);
+    }
+
+    method _find_method_named_type_constraint (Str $method, Str $param) {
+
+        return $self->meta->find_method_named_type_constraint($method, $param);
+    }
+
     method _ensure_applied_dispatchtype_roles {
 
         my $type = $self->_app->dispatcher->dispatch_type('Chained');
@@ -53,27 +52,39 @@ role CatalystX::Declare::Controller::ActionPreparation {
         $self->_ensure_applied_dispatchtype_roles;
     }
 
-    around create_action (%args) {
-
-        my @action_roles = @{ delete($args{attributes}{CatalystX_Declarative_ActionRoles}) || [] };
+    around gather_action_roles(%args) {
+        return (
+            $self->$orig(%args),
+            @{ delete($args{attributes}{CatalystX_Declarative_ActionRoles}) || [] },
+        );
+    }
 
+    around create_action (%args) {
         my $action = $self->$orig(%args);
 
         return $action
             if $args{attributes}{Private};
 
-        $self->_apply_action_roles($action, @action_roles);
-
         return $action 
             unless $action->DOES(CatchValidationError);
 
         my $tc = $self->_find_method_type_constraint($action->name);
+        my $np = $self->_find_method_named_params($action->name);
 
         return $action
             unless $tc;
 
-        $action->method_type_constraint($tc);
         $action->controller_instance($self);
+        $action->method_type_constraint($tc);
+
+        if ($np) {
+
+            $action->method_named_params($np);
+            $action->method_named_type_constraint({
+                map +($_, $self->_find_method_named_type_constraint($action->name, $_)),
+                    @$np,
+            });
+        }
 
         return $action;
     }