1 use CatalystX::Declare;
5 controller ::Controller::Foo with ::TestRole {
7 use constant MyActionNo => 'TestApp::Try::Aliasing::MyActionNo';
11 has message => (is => 'rw');
13 method format { uc $self->message }
17 around match (@args) { $ENV{TESTAPP_ACTIONROLE} ? $self->$orig(@args) : undef }
20 role TestApp::Try::Aliasing::MyActionNo {
21 around match (@args) { $ENV{TESTAPP_ACTIONROLE} ? undef : $self->$orig(@args) }
24 class TestApp::Action::Page extends Catalyst::Action {
26 around execute ($controller, $ctx, @args) {
27 my $page = $ctx->request->params->{page} || 1;
28 return $self->$orig($controller, $ctx, @args, page => $page);
44 # normal methods are very useful too
47 method welcome_message { sprintf 'Welcome to %s!', $self->title }
49 method greet (Str $name) { "Hello, $name!" }
56 action base under '/base' as 'foo';
58 action root under base as '' is final {
59 $ctx->response->body( $self->welcome_message );
67 action with_args under base;
69 action hello (Str $name) under with_args is final {
70 $ctx->response->body($self->greet(ucfirst $name));
73 action at_end (Int $x, Int $y) under with_args is final {
74 $ctx->response->body( $x * $y );
77 action in_the_middle (Int $x, Int $y) under with_args {
78 $ctx->stash(result => $x * $y);
80 action end_of_the_middle under in_the_middle is final {
81 $ctx->response->body($ctx->stash->{result} * 2);
84 action all_the_way (Int $x) under with_args as '' {
87 action through_the_sky (Int $y) under all_the_way as '' {
90 action and_beyond (@rest) under through_the_sky as fhtagn is final {
91 $ctx->response->body(join ', ',
100 # under is also a valid keyword
103 under base action under_base as under;
105 under under_base as '' action even_more_under (Int $i) is final {
106 $ctx->response->body("under $i");
111 # too many words? go comma go!
114 action comma_base, as '', under base;
116 under comma_base, is final, action comma ($str), as ',comma' {
117 $ctx->response->body($str);
125 action lower under base;
137 action stream is final {
138 $ctx->response->body($ctx->action->reverse);
141 action param (Int $x) {
142 $ctx->stash(param_x => $x);
147 final action road (Int $y) {
148 $ctx->response->body($ctx->stash->{param_x} + $y);
165 { $ctx->res->body('YES') };
172 { $ctx->res->body('NO') };
179 action book (Str $title) under base {
180 $ctx->stash(title => $title);
183 action view (Str $format, Int :$page) under book isa Page is final {
184 $ctx->response->body(
185 sprintf 'Page %d of "%s" as %s',
187 $ctx->stash->{title},
194 # using final as syntax element
197 action final_base as 'finals' under base;
199 final action in_front under final_base { $ctx->response->body($ctx->action->reverse) }
201 under final_base, final action final_middle { $ctx->response->body($ctx->action->reverse) }
203 action final_at_end, final under final_base { $ctx->response->body($ctx->action->reverse) }
210 action not_really_here is private { $ctx->stash(foo => 23) }
212 action expose_not_really_here under base is final {
213 $ctx->forward('not_really_here');
214 $ctx->response->body($ctx->stash->{foo});
219 # chain target specified via action
222 action pointed <- base ($what) is final { $ctx->response->body("Your $what is pointed!") }
226 # targets for action modifiers
229 action modifier_target under base is final { $ctx->response->body($ctx->action->reverse) }
231 action surrounded_target under base is final {
232 $ctx->response->body(join ' ', $ctx->action->reverse, $ctx->response->body || ());
240 final action inline_class under base {
241 $ctx->response->body( TestApp::Controller::Foo::Messenger->new(message => 'Hello')->format );
249 final action wants_integer (Int $x) under base {
250 $ctx->response->body($x);
253 final action wants_integer_fail (Any $x) as 'wants_integer' under base {
254 $ctx->response->body('no integer');