cleanups and tests
[catagits/CatalystX-Declare.git] / t / lib / TestApp / Controller / Foo.pm
index 60f2a18..4a5091a 100644 (file)
@@ -2,22 +2,94 @@ use CatalystX::Declarative;
 
 controller TestApp::Controller::Foo {
 
-    has bar => (is => 'rw');
 
-    method baz { }
+    #
+    #   look, a Moose!
+    #
 
-    under '/', action base, as '';
+    has title => (
+        is      => 'ro',
+        isa     => 'Str',
+        default => 'TestApp',
+    );
 
-    action root under base as '' is final { }
 
-    action list under base is final { }
+    #
+    #   normal methods are very useful too
+    #
 
-    under base, as 'id', action object ($id) { }
+    method welcome_message { sprintf 'Welcome to %s!', $self->title }
 
-    action view under object is final { $ctx->res->body('Hello World!') }
+    method greet (Str $name) { "Hello, $name!" }
 
-    action edit under object is final { }
 
-    action tag (@tags) under object is final { }
+    #
+    #   the simple stuff
+    #
+
+    action base under '/base' as 'foo';
+
+    action root under base as '' is final {
+        $ctx->response->body( $self->welcome_message );
+    }
+
+    
+    #
+    #   with arguments
+    #
+
+    action with_args under base;
+
+    action hello (Str $name) under with_args is final {
+        $ctx->response->body($self->greet(ucfirst $name));
+    }
+
+    action at_end (Int $x, Int $y) under with_args is final { 
+        $ctx->response->body( $x * $y );
+    }
+
+    action in_the_middle (Int $x, Int $y) under with_args {
+        $ctx->stash(result => $x * $y);
+    }
+    action end_of_the_middle under in_the_middle is final {
+        $ctx->response->body($ctx->stash->{result} * 2);
+    }
+
+    action all_the_way (Int $x) under with_args as '' {
+        $ctx->stash(x => $x);
+    }
+    action through_the_sky (Int $y) under all_the_way as '' {
+        $ctx->stash(y => $y);
+    }
+    action and_beyond (@rest) under through_the_sky as fhtagn is final {
+        $ctx->response->body(join ', ', 
+            $ctx->stash->{x},
+            $ctx->stash->{y},
+            @rest,
+        );
+    }
+
+
+    #
+    #   under is also a valid keyword
+    #
+
+    under base action under_base as under;
+
+    under under_base as '' action even_more_under (Int $i) is final {
+        $ctx->response->body("under $i");
+    }
+
+
+    #
+    #   too many words? go comma go!
+    #
+
+    action comma_base, as '', under base;
+
+    under comma_base, is final, action comma ($str), as ',comma' {
+        $ctx->response->body($str);
+    }
+
 }