Perl Catalyst 控制器链

Perl Catalyst Controller chains

我在创建 'flexible' 端点时遇到问题。是否有可能遵循这些思路:

# 1) List all Microarrays for this species
/regulatory/species/:species/microarray
sub microarray_list: Chained('species') PathPart('microarray') ActionClass('REST') { }

# 2) Information about a specific array
/regulatory/species/:species/microarray/:microarray
sub microarray_single: Chained('species') PathPart('microarray') CaptureArgs(1) ActionClass('REST') { }

# 3) Information about a probe on the array
/regulatory/species/:species/microarray/:microarray/probe/:probe
sub microarray_probe: Chained('microarray_single') PathPart('probe') Args(1) ActionClass('REST')

启动时 1) 未注册:

| /regulatory/species/*/id/*          | /regulatory/species (1)              |
|                                     | => /regulatory/id (1)                |
| /regulatory/species/*/microarray    | /regulatory/species (1)              |
|                                     | => /regulatory/microarray_list (...) |
| /regulatory/species/*/microarray/*- | /regulatory/species (1)              |
| /probe/*                            | 

任何帮助都将不胜感激!

是的,有可能,您的问题只是您没有microarray_single 的端点。你可能想要

sub microarray_list :Chained('species') PathPart('microarray')
                     ActionClass('REST') { }

# this is the chain midpoint, it can load the microarray for the endpoints to use
sub microarray :Chained('species') PathPart('microarray')
                CaptureArgs(1) { }

# this is an endpoint with the same path as the midpoint it chains off of
sub microarray_single :Chained('microarray') PathPart('')
                       Args(0) ActionClass('REST') { }

# and this is an endpoint that adds .../probe/*
sub microarray_probe :Chained('microarray') PathPart('probe')
                      Args(1) ActionClass('REST') { }

如果在 .../microarray/*/probe/* 之后还有其他事情,那么您也可以这样做,将 microarray_probeArgs(1) ActionClass('REST')(端点)更改为 CaptureArgs(1),然后添加具有 :Chained('microarray_probe') PathPart('') Args(0) ActionClass('REST') 的端点,用于处理没有其他路径部分的情况。

要记住的重要一点是,只有链 端点 (即没有 CaptureArgs 的操作)对应于有效的 URL 路径。