fixed action signature error handling
[catagits/CatalystX-Declare.git] / lib / CatalystX / Declare / Keyword / Action.pm
index 82b707d..b60cc21 100644 (file)
@@ -85,6 +85,10 @@ class CatalystX::Declare::Keyword::Action
 
         AttributeRole->meta->apply($method);
 
+        my $count = $self->_count_positional_arguments($method);
+        $attributes{CaptureArgs} = $count
+            if defined $count;
+
         $_->($method)
             for @populators;
 
@@ -118,7 +122,7 @@ class CatalystX::Declare::Keyword::Action
         my @attributes;
         for my $attr (keys %attributes) {
             push @attributes, 
-                map { sprintf '%s(%s)', $attr, $_ }
+                map { sprintf '%s%s', $attr, defined($_) ? sprintf('(%s)', $_) : '' }
                     (ref($attributes{ $attr }) eq 'ARRAY') 
                     ? @{ $attributes{ $attr } }
                     : $attributes{ $attr };
@@ -234,8 +238,7 @@ class CatalystX::Declare::Keyword::Action
             my $method = shift;
 
             if ($what eq any qw( end endpoint final )) {
-                my $count = $self->_count_positional_arguments($method);
-                $attrs->{Args} = defined($count) ? $count : '';
+                $attrs->{Args} = delete $attrs->{CaptureArgs};
             }
             elsif ($what eq 'private') {
                 $attrs->{Private} = [];
@@ -263,10 +266,6 @@ class CatalystX::Declare::Keyword::Action
 
         return sub {
             my $method = shift;
-
-            my $count = $self->_count_positional_arguments($method);
-            $attrs->{CaptureArgs} = $count
-                if defined $count;
         };
     }
 
@@ -546,7 +545,8 @@ an array as a variable:
 
 Currently, when the arguments do not fit the signature because of a L<Moose>
 validation error, the response body will be set to C<Bad Request> and the
-status to C<400>.
+status to C<400>. This only applies when debug mode is off. If it is turned on,
+the error message will be prefixed with C<BAD REQUEST: >.
 
 =head2 Actions and Method Modifiers
 
@@ -559,7 +559,7 @@ C<base> action:
 
     use CatalystX::Declare;
 
-    controller_role MyApp::Web::ControllerRole::RichBase {
+    component_role MyApp::Web::ControllerRole::RichBase {
 
         before base (Object $ctx) {
             $ctx->stash(something => $ctx->model('Item'));