D:D has fixed the method invocation issue now
[catagits/CatalystX-Declare.git] / t / lib / TestApp / Controller / Foo.pm
index d3a29b9..453581d 100644 (file)
@@ -1,24 +1,32 @@
-use CatalystX::Declarative;
+use CatalystX::Declare;
 
-role MyActionYes {
-    around match (@args) { $ENV{TESTAPP_ACTIONROLE} ? $self->$orig(@args) : undef }
-}
 
-role TestApp::Try::Aliasing::MyActionNo {
-    around match (@args) { $ENV{TESTAPP_ACTIONROLE} ? undef : $self->$orig(@args) }
-}
+controller TestApp::Controller::Foo with TestApp::TestRole {
+
+    use constant MyActionNo => 'TestApp::Try::Aliasing::MyActionNo';
 
-class TestApp::Action::Page extends Catalyst::Action {
+    class ::Messenger {
 
-    around execute ($controller, $ctx, @args) {
-        my $page = $ctx->request->params->{page} || 1;
-        return $self->$orig($controller, $ctx, @args, page => $page);
+        has message => (is => 'rw');
+
+        method format { uc $self->message }
     }
-}
 
-controller TestApp::Controller::Foo {
+    role MyActionYes {
+        around match (@args) { $ENV{TESTAPP_ACTIONROLE} ? $self->$orig(@args) : undef }
+    }
 
-    use constant MyActionNo => 'TestApp::Try::Aliasing::MyActionNo';
+    role TestApp::Try::Aliasing::MyActionNo {
+        around match (@args) { $ENV{TESTAPP_ACTIONROLE} ? undef : $self->$orig(@args) }
+    }
+
+    class TestApp::Action::Page extends Catalyst::Action {
+
+        around execute ($controller, $ctx, @args) {
+            my $page = $ctx->request->params->{page} || 1;
+            return $self->$orig($controller, $ctx, @args, page => $page);
+        }
+    }
 
     #
     #   look, a Moose!
@@ -128,6 +136,17 @@ controller TestApp::Controller::Foo {
                 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);
+                    }
+                }
             }
         }
     }
@@ -181,5 +200,54 @@ 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});
+    }
+
+
+    #
+    #   chain target specified via action
+    #
+
+    action pointed <- base ($what) is final { $ctx->response->body("Your $what is pointed!") }
+
+
+    #
+    #   targets for action modifiers
+    #
+
+    action modifier_target under base is final { $ctx->response->body($ctx->action->reverse) }
+
+    action surrounded_target under base is final { 
+        $ctx->response->body(join ' ', $ctx->action->reverse, $ctx->response->body || ());
+    }
+
+
+    #
+    #   inline classes
+    #
+
+    final action inline_class under base {
+        $ctx->response->body( TestApp::Controller::Foo::Messenger->new(message => 'Hello')->format );
+    }
+
+
+    #
+    #   validation test
+    #
+
+    final action wants_integer (Int $x) under base {
+        $ctx->response->body($x);
+    }
+
 }