I can usually get the behavior I desire by just randomly trying different permutations of these two options, but I still can't say I know precisely what they do. Is there a concrete example that demonstrates the difference?
What's the difference between :Args and :CaptureArgs in Catalyst?
:CaptureArgs(N)
matches if there are at least N args left. It is used for non-terminal Chained handlers.
:Args(N)
only matches if there are exactly N args left.
For example,
sub catalog : Chained : CaptureArgs(1) {
my ( $self, $c, $arg ) = @_;
...
}
sub item : Chained('catalog') : Args(2) {
my ( $self, $c, $arg1, $arg2 ) = @_;
...
}
matches
/catalog/*/item/*/*
CaptureArgs
is used in Chained methods in Catalyst.
Args
marks the end of chained method.
For ex:
sub base_method : Chained('/') :PathPart("account") :CaptureArgs(0)
{
}
sub after_base : Chained('base_method') :PathPart("org") :CaptureArgs(2)
{
}
sub base_end : Chained('after_base') :PathPart("edit") :Args(1)
{
}
Above chained methods match /account/org/*/*/edit/*
.
Here base_end
is end method of chain.To mark end of chained action Args
is used.If CaptureArgs
is used that means chain is still going on.
Args
is also used in other methods of catalyst for specifying arguments to method.
Also from cpan Catalyst::DispatchType::Chained:
The endpoint of the chain specifies how many arguments it
gets through the Args attribute. :Args(0) would be none at all,
:Args without an integer would be unlimited. The path parts that
aren't endpoints are using CaptureArgs to specify how many parameters
they expect to receive.
© 2022 - 2024 — McMap. All rights reserved.