-use CatalystX::Declarative;
+use CatalystX::Declare;
+
+role MyActionYes {
+ around match (@args) { $ENV{TESTAPP_ACTIONROLE} ? $self->$orig(@args) : undef }
+}
+
+role TestApp::Try::Aliasing::MyActionNo {
+ around match (@args) { $ENV{TESTAPP_ACTIONROLE} ? undef : $self->$orig(@args) }
+}
+
+class TestApp::Action::Page extends Catalyst::Action {
+
+ around execute ($controller, $ctx, @args) {
+ my $page = $ctx->request->params->{page} || 1;
+ return $self->$orig($controller, $ctx, @args, page => $page);
+ }
+}
controller TestApp::Controller::Foo {
+ use constant MyActionNo => 'TestApp::Try::Aliasing::MyActionNo';
#
# look, a Moose!
$ctx->response->body($str);
}
+
+ #
+ # subnamespacing
+ #
+
+ action lower under base;
+
+ under lower {
+
+ action down;
+
+ under down {
+
+ action the;
+
+ under the {
+
+ action stream is final {
+ $ctx->response->body($ctx->action->reverse);
+ }
+ }
+ }
+ }
+
+
+ #
+ # action roles
+ #
+
+ action with_role_yes
+ is final
+ as with_role
+ under base
+ with MyActionYes
+ { $ctx->res->body('YES') };
+
+ action with_role_no
+ is final
+ as with_role
+ under base
+ with MyActionNo
+ { $ctx->res->body('NO') };
+
+
+ #
+ # action classes
+ #
+
+ action book (Str $title) under base {
+ $ctx->stash(title => $title);
+ }
+
+ action view (Str $format, Int :$page) under book isa Page is final {
+ $ctx->response->body(
+ sprintf 'Page %d of "%s" as %s',
+ $page,
+ $ctx->stash->{title},
+ uc($format),
+ );
+ }
+
+
+ #
+ # using final as syntax element
+ #
+
+ action final_base as 'finals' under base;
+
+ final action in_front under final_base { $ctx->response->body($ctx->action->reverse) }
+
+ under final_base, final action final_middle { $ctx->response->body($ctx->action->reverse) }
+
+ action final_at_end, final under final_base { $ctx->response->body($ctx->action->reverse) }
+
+
+ #
+ # privates
+ #
+
+ action not_really_here is private { $ctx->stash(foo => 23) }
+
+ action expose_not_really_here under base is final {
+ $ctx->forward('not_really_here');
+ $ctx->response->body($ctx->stash->{foo});
+ }
+
+
+ #
+ # chain target specified via action
+ #
+
+ action pointed <- base ($what) is final { $ctx->response->body("Your $what is pointed!") }
}