From: Robert 'phaylon' Sedlacek Date: Fri, 31 Jul 2009 22:58:11 +0000 (+0200) Subject: fixed capture args error in under blocks X-Git-Tag: 0.001~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalystX-Declare.git;a=commitdiff_plain;h=eb97acbbb8e45bd4ffb76c77b55127d3295e062b fixed capture args error in under blocks --- diff --git a/lib/CatalystX/Declare/Keyword/Action.pm b/lib/CatalystX/Declare/Keyword/Action.pm index 82b707d..be45235 100644 --- a/lib/CatalystX/Declare/Keyword/Action.pm +++ b/lib/CatalystX/Declare/Keyword/Action.pm @@ -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; }; } diff --git a/t/100_complex.t b/t/100_complex.t index 14539ae..91fb45f 100644 --- a/t/100_complex.t +++ b/t/100_complex.t @@ -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; diff --git a/t/lib/TestApp/Controller/Foo.pm b/t/lib/TestApp/Controller/Foo.pm index 662f0ac..cbe81f7 100644 --- a/t/lib/TestApp/Controller/Foo.pm +++ b/t/lib/TestApp/Controller/Foo.pm @@ -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); + } + } } } }