of the chain specifies how many arguments it gets through the C<Args>
attribute. C<:Args(0)> would be none at all, C<:Args> without an integer
would be unlimited. The path parts that aren't endpoints are using
-C<Captures> to specify how many parameters they expect to receive. As an
+C<CaptureArgs> to specify how many parameters they expect to receive. As an
example setup:
package MyApp::Controller::Greeting;
use base qw/ Catalyst::Controller /;
# this is the beginning of our chain
- sub hello : PathPart('hello') Chained('/') Captures(1) {
+ sub hello : PathPart('hello') Chained('/') CaptureArgs(1) {
my ( $self, $c, $integer ) = @_;
$c->stash->{ message } = "Hello ";
$c->stash->{ arg_sum } = $integer;
}
- # this is our endpoint, because it has no :Captures
+ # this is our endpoint, because it has no :CaptureArgs
sub world : PathPart('world') Chained('hello') Args(1) {
my ( $self, $c, $integer ) = @_;
$c->stash->{ message } .= "World!";
As you can see, Catalyst only deals with chains as whole path and
builds one for each endpoint, which are the actions with C<:Chained>
-but without C<:Captures>.
+but without C<:CaptureArgs>.
Let's assume this application gets a request at the path
C</hello/23/world/12>, what happens then? First, Catalyst will dispatch
to the C<hello> action and pass the value C<23> as argument to it after
-the context. It does so because we have previously used C<:Captures(1)>
+the context. It does so because we have previously used C<:CaptureArgs(1)>
to declare that it has one path part after itself as it's argument. We
told Catalyst that this is the beginning of the chain by specifying
C<:Chained('/')>. Also note that instead of saying C<:PathPart('hello')>
After C<hello> has run, Catalyst goes on to dispatch to the C<world>
action. This is the last action to be called, as Catalyst knows this
-is an endpoint because we specified no C<:Captures> attribute. Nevertheless
+is an endpoint because we specified no C<:CaptureArgs> attribute. Nevertheless
we specify that this action expects an argument, but at this point we're
using C<:Args(1)> to do that. We could also have said C<:Args> or leave
it out alltogether, which would mean this action gets all arguments that
C</wiki/FooBarPage/rev/23/view>. This chain can be easily built with
these actions:
- sub wiki : PathPart('wiki') Chained('/') Captures(1) {
+ sub wiki : PathPart('wiki') Chained('/') CaptureArgs(1) {
my ( $self, $c, $page_name ) = @_;
# load the page named $page_name and put the object
# into the stash
}
- sub rev : PathPart('rev') Chained('wiki') Captures(1) {
+ sub rev : PathPart('rev') Chained('wiki') CaptureArgs(1) {
my ( $self, $c, $revision_id ) = @_;
# use the page object in the stash to get at it's
# revision with number $revision_id
If you want, for example, to have actions for the public paths
C</foo/12/edit> and C</foo/12>, just specify two actions with
C<:PathPart('foo')> and C<:Chained('/')>. The handler for the former
-path needs a C<:Captures(1)> attribute and a endpoint with
+path needs a C<:CaptureArgs(1)> attribute and a endpoint with
C<:PathPart('edit')> and C<:Chained('foo')>. For the latter path give
the action just a C<:Args(1)> to mark it as endpoint. This sums up to
this debugging output:
For example:
# in MyApp::Controller::Foo
- sub bar : Chained Captures(1) { ... }
+ sub bar : Chained CaptureArgs(1) { ... }
# in MyApp::Controller::Foo::Bar
sub baz : Chained('.') Args(1) { ... }
action chains directly to C</>, so the above chain comes out as end
product.
-=item Captures
+=item CaptureArgs
Also has to be specified for every part of the chain that is not an
endpoint. With this attribute Catalyst knows how many of the following
parts of the path (separated by C</>) this action wants to captures as
-it's arguments. If it doesn't expect any, just specify C<:Captures(0)>.
+it's arguments. If it doesn't expect any, just specify C<:CaptureArgs(0)>.
The captures get passed to the action's C<@_> right after the context,
but you can also find them as array reference in
C<$c-E<gt>request-E<gt>captures-E<gt>[$level]>. The C<$level> is the
level of the action in the chain that captured the parts of the path.
An action that is part of a chain (read: that has a C<:Chained> attribute)
-but has no C<:Captures> attribute is treated by Catalyst as a chain end.
+but has no C<:CaptureArgs> attribute is treated by Catalyst as a chain end.
=item Args
By default, endpoints receive the rest of the arguments in the path. You
can tell Catalyst through C<:Args> explicitly how many arguments your
-endpoint expects, just like you can with C<:Captures>. Note that this
+endpoint expects, just like you can with C<:CaptureArgs>. Note that this
also influences if this chain is invoked on a request. A chain with an
endpoint specifying one argument will only match if exactly one argument
exists in the path.
leaving it out alltogether: The chain is matched independent of the number
of path parts after the endpoint.
-Just like with C<:Captures>, the arguments get passed to the action in
+Just like with C<:CaptureArgs>, the arguments get passed to the action in
C<@_> after the context object. They can also be reached through
C<$c-E<gt>request-E<gt>arguments>.