fixed capture args error in under blocks
Robert 'phaylon' Sedlacek [Fri, 31 Jul 2009 22:58:11 +0000 (00:58 +0200)]
lib/CatalystX/Declare/Keyword/Action.pm
t/100_complex.t
t/lib/TestApp/Controller/Foo.pm

index 82b707d..be45235 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;
         };
     }
 
index 14539ae..91fb45f 100644 (file)
@@ -64,6 +64,8 @@ is get('/foo/inline_class'), 'HELLO', 'inline classes work as expected';
 # error handling
 is get('/foo/wants_integer/butdoesntgetone'), 'Bad Request', 'validation error causes bad request error';
 
+# fix bug with capture args below under { }
+is get('/foo/lower/down/the/param/3/road/5'), 8, 'capture args and block under work together';
 
 
 done_testing;
index 662f0ac..cbe81f7 100644 (file)
@@ -136,6 +136,17 @@ controller TestApp::Controller::Foo with TestApp::TestRole {
                 action stream is final {
                     $ctx->response->body($ctx->action->reverse);
                 }
+
+                action param (Int $x) { 
+                    $ctx->stash(param_x => $x);
+                }
+
+                under param {
+
+                    final action road (Int $y) {
+                        $ctx->response->body($ctx->stash->{param_x} + $y);
+                    }
+                }
             }
         }
     }