10

我通常可以通过随机尝试这两个选项的不同排列来获得我想要的行为,但我仍然不能说我确切地知道它们做了什么。有没有具体的例子可以证明这种差异?

4

2 回答 2

8

:CaptureArgs(N)如果至少有 N 个 args 则匹配。它用于非终端链式处理程序。

:Args(N)仅当恰好剩下 N 个 args 时才匹配。

例如,

sub catalog : Chained : CaptureArgs(1) {
    my ( $self, $c, $arg ) = @_;
    ...
}

sub item : Chained('catalog') : Args(2) {
    my ( $self, $c, $arg1, $arg2 ) = @_;
    ...
}

火柴

/catalog/*/item/*/*
于 2012-06-20T00:18:00.327 回答
5

CaptureArgs在 Catalyst 的链式方法中使用。

Args标志着链式方法的结束。

例如:

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)
{

}

以上链式方法匹配/account/org/*/*/edit/*

base_end是链的结束方法。使用标记链动作Args的结束。如果CaptureArgs使用表示链仍在进行中。

Args也用于催化剂的其他方法中,用于指定方法的参数。

同样来自 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.
于 2012-06-20T06:47:50.600 回答