# chain base action with path part setting of ''
# body-less actions don't do anything by themselves
- action base as '';
+ action base as '' under '/';
# simple end-point action
action controller_class is final under base {
action foo;
-This would define a chain-part action chained to C</> with the name C<foo>
+This would define a chain-part action chained to nothing with the name C<foo>
and no arguments. Since it isn't followed by a block, the body of the action
will be empty.
To change that, use the C<as> option:
- action base as ''; # <empty>
- action something as 'foo/bar'; # foo/bar
- action barely as bareword; # bareword
+ under something {
+ action base as ''; # <empty>
+ action something as 'foo/bar'; # foo/bar
+ action barely as bareword; # bareword
+ }
=head2 Chaining Actions
Currently, L<CatalystX::Declare> is completely based on the concept of
L<chained actions|Catalyst::DispatchType::Chained>. Every action you declare is
-chained to something. No base specification means you chain to the root. You
-can specify the action you want to chain to with the C<under> option:
+chained or private. You can specify the action you want to chain to with the
+C<under> option:
- action foo; # chained to /
+ action foo; # chained to nothing
action foo under '/'; # also chained to /
action foo under bar; # chained to the local bar action
action foo under '/bar/baz'; # chained to baz in /bar
you want to highlight a single action with a significant diversion from what
is to be expected:
- action base;
+ action base under '/';
under '/the/sink' is final action foo;
to be picked up as end-point and available via a public path, you have to say
so explicitely by using the C<is final> option:
- action base;
+ action base under '/';
action foo under base is final; # /base/foo
You can also drop the C<is> part of the C<is final> option if you want:
You can make end-points more visually distinct by using the C<final> keyword
instead of the option:
- action base;
+ action base under '/';
final action foo under base; # /base/foo
And of course, the C<final>, C<under> and C<action> keywords can be used in
combination whenever needed:
- action base as '';
+ action base as '' under '/';
under base {
There is also one shorthand alternative for declaring chain targets. You can
specify an action after a C<E<lt>-> following the action name:
- action base;
+ action base under '/';
final action foo <- base; # /base/foo
=head2 Arguments
target:
# /foo/*
- final action foo <- base ($x) { ... }
+ final action foo <- base ($x) under '/' { ... }
Parameters may be specified on chain-parts and end-points:
# /base/*/foo/*
- action base (Str $lang);
+ action base (Str $lang) under '/';
final action page (Int $page_num) under base;
Named parameters will be populated with the values in the query parameters:
# /view/17/?page=3
- final action view (Int $id, Int :$page = 1);
+ final action view (Int $id, Int :$page = 1) under '/';
Your end-points can also take an unspecified amount of arguments by specifying
an array as a variable:
# /find/some/deep/path/spec
- final action find (@path);
+ final action find (@path) under '/';
=head2 Actions and Method Modifiers
controller MyApp::Web::Controller::Foo
with MyApp::Web::Controller::RichBase {
- action base as '';
+ action base as '' under '/';
action show, final under base {
$ctx->response->body(