accessing action in tests now, needs D:D fix
[catagits/CatalystX-Declare.git] / t / lib / TestApp / Controller / Foo.pm
CommitLineData
918fb36e 1use CatalystX::Declarative;
2
3controller 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
e10b92dd 94
95 #
96 # subnamespacing
97 #
98
99 action lower under base;
100
101 under lower {
102
103 action down;
104
105 under down {
106
107 action the;
108
109 under the {
110
111 action stream is final {
3187b9aa 112 $ctx->response->body($ctx->action->reverse);
e10b92dd 113 }
114 }
115 }
116 }
117
918fb36e 118}
119