private actions work again
Robert 'phaylon' Sedlacek [Mon, 11 May 2009 01:35:27 +0000 (03:35 +0200)]
lib/CatalystX/Declarative/Keyword/Action.pm
t/001_basic.t
t/lib/TestApp/Controller/Foo.pm

index c96f239..5621f24 100644 (file)
@@ -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} = [];
             }
         };
     }
index 2acc6df..a5d9214 100644 (file)
@@ -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';
index d3a29b9..9c7c085 100644 (file)
@@ -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});
+    }
 }