From: Robert 'phaylon' Sedlacek Date: Mon, 11 May 2009 01:35:27 +0000 (+0200) Subject: private actions work again X-Git-Tag: 0.001~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalystX-Declare.git;a=commitdiff_plain;h=aae7ad1f7d0ecdc1fc9407679ccf27aa60a1ca3b private actions work again --- diff --git a/lib/CatalystX/Declarative/Keyword/Action.pm b/lib/CatalystX/Declarative/Keyword/Action.pm index c96f239..5621f24 100644 --- a/lib/CatalystX/Declarative/Keyword/Action.pm +++ b/lib/CatalystX/Declarative/Keyword/Action.pm @@ -86,14 +86,22 @@ class CatalystX::Declarative::Keyword::Action $_->($method) for @populators; - $attributes{PathPart} ||= "'$name'"; + unless ($attributes{Private}) { + $attributes{PathPart} ||= "'$name'"; - delete $attributes{CaptureArgs} - if exists $attributes{Args}; + delete $attributes{CaptureArgs} + if exists $attributes{Args}; - $attributes{CaptureArgs} = 0 - unless exists $attributes{Args} - or exists $attributes{CaptureArgs}; + $attributes{CaptureArgs} = 0 + unless exists $attributes{Args} + or exists $attributes{CaptureArgs}; + } + + if ($attributes{Private}) { +# warn "PRIVATE $name"; + delete $attributes{ $_ } + for qw( Args CaptureArgs Chained Signature Subname Action ); + } if ($ctx->peek_next_char eq '{') { $ctx->inject_if_block($ctx->scope_injector_call . $method->injectable_code); @@ -109,13 +117,14 @@ class CatalystX::Declarative::Keyword::Action my @attributes = map { join('', $_, - sprintf('(%s)', - ref($attributes{ $_ }) eq 'ARRAY' - ? join(' ', @{ $attributes{ $_ } }) - : $attributes{ $_ } - ), + ref($attributes{ $_ }) eq 'ARRAY' + ? ( scalar(@{ $attributes{ $_ } }) + ? sprintf('(%s)', join(' ', @{ $attributes{ $_ } })) + : '' ) + : "($attributes{ $_ })" ); } keys %attributes; +# warn "ATTRS[ @attributes ]\n"; return $ctx->shadow(sub (&) { my $class = caller; @@ -178,6 +187,7 @@ class CatalystX::Declarative::Keyword::Action $attrs->{Subname} = $name; $attrs->{Signature} = $proto; + $attrs->{Action} = []; if (defined $CatalystX::Declarative::SCOPE::UNDER) { $attrs->{Chained} ||= $CatalystX::Declarative::SCOPE::UNDER; @@ -209,7 +219,7 @@ class CatalystX::Declarative::Keyword::Action $attrs->{Args} = defined($count) ? $count : ''; } elsif ($what eq 'private') { - $attrs->{Private} = 1; + $attrs->{Private} = []; } }; } diff --git a/t/001_basic.t b/t/001_basic.t index 2acc6df..a5d9214 100644 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -5,7 +5,7 @@ use warnings; use FindBin; use lib "$FindBin::Bin/lib"; -use Test::More tests => 15; +use Test::More tests => 16; use Catalyst::Test 'TestApp'; # simple stuff @@ -44,3 +44,6 @@ is get('/foo/book/Fnord/view/html?page=7'), 'Page 7 of "Fnord" as HTML', 'action is get('/foo/finals/in_front'), 'foo/in_front', 'final syntax element as declarator'; is get('/foo/finals/final_middle'), 'foo/final_middle', 'final syntax element in the middle'; is get('/foo/finals/final_at_end'), 'foo/final_at_end', 'final syntax element at the end'; + +# privates +is get('/foo/expose_not_really_here'), 23, 'private action works'; diff --git a/t/lib/TestApp/Controller/Foo.pm b/t/lib/TestApp/Controller/Foo.pm index d3a29b9..9c7c085 100644 --- a/t/lib/TestApp/Controller/Foo.pm +++ b/t/lib/TestApp/Controller/Foo.pm @@ -181,5 +181,17 @@ controller TestApp::Controller::Foo { under final_base, final action final_middle { $ctx->response->body($ctx->action->reverse) } action final_at_end, final under final_base { $ctx->response->body($ctx->action->reverse) } + + + # + # privates + # + + action not_really_here is private { $ctx->stash(foo => 23) } + + action expose_not_really_here under base is final { + $ctx->forward('not_really_here'); + $ctx->response->body($ctx->stash->{foo}); + } }