added example application
[catagits/CatalystX-Declare.git] / examples / MyApp-Web / lib / MyApp / Web / Controller / Foo.pm
1 use CatalystX::Declare;
2
3 # a normal controller example
4 controller MyApp::Web::Controller::Foo {
5
6     # this local base action chains to the root /base action
7     action base under '/base' as 'foo';
8
9     # all that's below base
10     under base {
11
12         # say hello
13         final action hello {
14             $ctx->stash(hello => 'rendering via root controller role');
15         }
16
17         # collecto two ints from the uri
18         action nums (Int $x, Int $y) as '' under base {
19
20             # stash the two values
21             $ctx->stash(x => $x, y => $y);
22         }
23
24         # the nums action above has to two chain parts below it
25         under nums {
26
27             # one end-point where we add the numbers
28             final action add { $ctx->res->body( $ctx->stash->{x} + $ctx->stash->{y} ) }
29
30             # and one end-point where we multiply them
31             final action multiply { $ctx->res->body( $ctx->stash->{x} * $ctx->stash->{y} ) }
32         }
33     }
34 }