1 use CatalystX::Declare;
4 controller TestApp::Controller::Foo with TestApp::TestRole {
6 use constant MyActionNo => 'TestApp::Try::Aliasing::MyActionNo';
10 has message => (is => 'rw');
12 method format { uc $self->message }
16 around match (@args) { $ENV{TESTAPP_ACTIONROLE} ? $self->$orig(@args) : undef }
19 role TestApp::Try::Aliasing::MyActionNo {
20 around match (@args) { $ENV{TESTAPP_ACTIONROLE} ? undef : $self->$orig(@args) }
23 class TestApp::Action::Page extends Catalyst::Action {
25 around execute ($controller, $ctx, @args) {
26 my $page = $ctx->request->params->{page} || 1;
27 return $self->$orig($controller, $ctx, @args, page => $page);
43 # normal methods are very useful too
46 method welcome_message { sprintf 'Welcome to %s!', $self->title }
48 method greet (Str $name) { "Hello, $name!" }
55 action base under '/base' as 'foo';
57 action root under base as '' is final {
58 $ctx->response->body( $self->welcome_message );
66 action with_args under base;
68 action hello (Str $name) under with_args is final {
69 $ctx->response->body($self->greet(ucfirst $name));
72 action at_end (Int $x, Int $y) under with_args is final {
73 $ctx->response->body( $x * $y );
76 action in_the_middle (Int $x, Int $y) under with_args {
77 $ctx->stash(result => $x * $y);
79 action end_of_the_middle under in_the_middle is final {
80 $ctx->response->body($ctx->stash->{result} * 2);
83 action all_the_way (Int $x) under with_args as '' {
86 action through_the_sky (Int $y) under all_the_way as '' {
89 action and_beyond (@rest) under through_the_sky as fhtagn is final {
90 $ctx->response->body(join ', ',
99 # under is also a valid keyword
102 under base action under_base as under;
104 under under_base as '' action even_more_under (Int $i) is final {
105 $ctx->response->body("under $i");
110 # too many words? go comma go!
113 action comma_base, as '', under base;
115 under comma_base, is final, action comma ($str), as ',comma' {
116 $ctx->response->body($str);
124 action lower under base;
136 action stream is final {
137 $ctx->response->body($ctx->action->reverse);
153 { $ctx->res->body('YES') };
160 { $ctx->res->body('NO') };
167 action book (Str $title) under base {
168 $ctx->stash(title => $title);
171 action view (Str $format, Int :$page) under book isa Page is final {
172 $ctx->response->body(
173 sprintf 'Page %d of "%s" as %s',
175 $ctx->stash->{title},
182 # using final as syntax element
185 action final_base as 'finals' under base;
187 final action in_front under final_base { $ctx->response->body($ctx->action->reverse) }
189 under final_base, final action final_middle { $ctx->response->body($ctx->action->reverse) }
191 action final_at_end, final under final_base { $ctx->response->body($ctx->action->reverse) }
198 action not_really_here is private { $ctx->stash(foo => 23) }
200 action expose_not_really_here under base is final {
201 $ctx->forward('not_really_here');
202 $ctx->response->body($ctx->stash->{foo});
207 # chain target specified via action
210 action pointed <- base ($what) is final { $ctx->response->body("Your $what is pointed!") }
214 # targets for action modifiers
217 action modifier_target under base is final { $ctx->response->body($ctx->action->reverse) }
219 action surrounded_target under base is final {
220 $ctx->response->body(join ' ', $ctx->action->reverse, $ctx->response->body || ());
228 final action inline_class under base {
229 $ctx->response->body( TestApp::Controller::Foo::Messenger->new(message => 'Hello')->format );
237 final action wants_integer (Int $x) under base {
238 $ctx->response->body($x);