我通常可以通过随机尝试这两种选项的不同排列来获得我想要的行为,但我仍然不能说我确切地知道他们做了什么.是否有一个具体的例子来证明这种差异?
: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 ) = @_;
...
}
Run Code Online (Sandbox Code Playgroud)
火柴
/catalog/*/item/*/*
Run Code Online (Sandbox Code Playgroud)
小智 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)
{
}
Run Code Online (Sandbox Code Playgroud)
以上链式方法匹配/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.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1650 次 |
| 最近记录: |