Commit | Line | Data |
918fb36e |
1 | use CatalystX::Declarative; |
2 | |
3 | controller TestApp::Controller::Foo { |
4 | |
918fb36e |
5 | |
a0ebba1d |
6 | # |
7 | # look, a Moose! |
8 | # |
918fb36e |
9 | |
a0ebba1d |
10 | has title => ( |
11 | is => 'ro', |
12 | isa => 'Str', |
13 | default => 'TestApp', |
14 | ); |
918fb36e |
15 | |
918fb36e |
16 | |
a0ebba1d |
17 | # |
18 | # normal methods are very useful too |
19 | # |
918fb36e |
20 | |
a0ebba1d |
21 | method welcome_message { sprintf 'Welcome to %s!', $self->title } |
918fb36e |
22 | |
a0ebba1d |
23 | method greet (Str $name) { "Hello, $name!" } |
918fb36e |
24 | |
918fb36e |
25 | |
a0ebba1d |
26 | # |
27 | # the simple stuff |
28 | # |
29 | |
30 | action base under '/base' as 'foo'; |
31 | |
32 | action root under base as '' is final { |
33 | $ctx->response->body( $self->welcome_message ); |
34 | } |
35 | |
36 | |
37 | # |
38 | # with arguments |
39 | # |
40 | |
41 | action with_args under base; |
42 | |
43 | action hello (Str $name) under with_args is final { |
44 | $ctx->response->body($self->greet(ucfirst $name)); |
45 | } |
46 | |
47 | action at_end (Int $x, Int $y) under with_args is final { |
48 | $ctx->response->body( $x * $y ); |
49 | } |
50 | |
51 | action in_the_middle (Int $x, Int $y) under with_args { |
52 | $ctx->stash(result => $x * $y); |
53 | } |
54 | action end_of_the_middle under in_the_middle is final { |
55 | $ctx->response->body($ctx->stash->{result} * 2); |
56 | } |
57 | |
58 | action all_the_way (Int $x) under with_args as '' { |
59 | $ctx->stash(x => $x); |
60 | } |
61 | action through_the_sky (Int $y) under all_the_way as '' { |
62 | $ctx->stash(y => $y); |
63 | } |
64 | action and_beyond (@rest) under through_the_sky as fhtagn is final { |
65 | $ctx->response->body(join ', ', |
66 | $ctx->stash->{x}, |
67 | $ctx->stash->{y}, |
68 | @rest, |
69 | ); |
70 | } |
71 | |
72 | |
73 | # |
74 | # under is also a valid keyword |
75 | # |
76 | |
77 | under base action under_base as under; |
78 | |
79 | under under_base as '' action even_more_under (Int $i) is final { |
80 | $ctx->response->body("under $i"); |
81 | } |
82 | |
83 | |
84 | # |
85 | # too many words? go comma go! |
86 | # |
87 | |
88 | action comma_base, as '', under base; |
89 | |
90 | under comma_base, is final, action comma ($str), as ',comma' { |
91 | $ctx->response->body($str); |
92 | } |
93 | |
918fb36e |
94 | } |
95 | |