如何进行与根目录中的单个文件匹配的 Catalyst 操作?

发布于 2024-07-22 05:11:06 字数 298 浏览 8 评论 0原文

我在创建与根目录中的单个文件匹配的 Catalyst 操作时遇到问题。 我想匹配如下所示的 URL:

http://foo:3000/about.html

我已在根控制器中编写了以下操作:

sub static :Path :Args(1)
{
    my ($self, $c, $file) = @_;
    …
}

但该操作不匹配,Catalyst 改为运行 default 操作。 我究竟做错了什么?

I have trouble creating a Catalyst action that would match a single file in the root directory. I would like to match URLs that look like this:

http://foo:3000/about.html

I have written the following action in the root controller:

sub static :Path :Args(1)
{
    my ($self, $c, $file) = @_;
    …
}

But the action does not match, Catalyst runs the default action instead. What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酒中人 2024-07-29 05:11:06

Catalyst subversion 中的 rev 10406 对于您的问题测试失败,我们可以确认这是一个错误。 这已经被永远打破了,不幸的是,没有人向我们提供错误报告或之前“正式”发现它:/

本周我将尝试修复该问题(或让其他人修复它),我们将发货 5.80005一旦完成,因为主干中已经准备好了足够的其他修复,所以这是值得的。

感谢所有让核心团队注意到这一点的人,singfish++

rev 10406 in the Catalyst subversion is a failing test for your issue, we can confirm that it's a bug. This has been broken forever, it's unfortunate that nobody has given us a bug report or 'officially' discovered it before :/

I'll try to fix that (or get someone else to fix it) this week, and we'll ship 5.80005 once that's done as there are enough other fixes ready in trunk for that to be worthwhile.

Thanks everyone who brought this to the core team's attention, singingfish++

酒解孤独 2024-07-29 05:11:06

好吧,这似乎是某种向后兼容性错误。 以下工作有效(只需在控制器中的其他操作之前声明 handle_404 操作:

package TestApp::Controller::Root;

use strict;
use warnings;
use parent 'Catalyst::Controller';

__PACKAGE__->config->{namespace} = '';

sub handle_404 :Path {
    my ( $self, $c ) = @_;
    $c->response->body( 'Page not found' );
    $c->response->status(404);
}

sub anaction :Path : Args(1) {
    my ($self, $c, $arg) = @_;
    $c->res->body($arg);
}

sub end : ActionClass('RenderView') {}

1;

然后运行测试脚本:

$ CATALYST_DEBUG=0 script/testapp_test.pl /foo
foo

OK, this seems to be some kind of backwards compatibility bug. The following works (just declare the handle_404 action before the other actions in the controller:

package TestApp::Controller::Root;

use strict;
use warnings;
use parent 'Catalyst::Controller';

__PACKAGE__->config->{namespace} = '';

sub handle_404 :Path {
    my ( $self, $c ) = @_;
    $c->response->body( 'Page not found' );
    $c->response->status(404);
}

sub anaction :Path : Args(1) {
    my ($self, $c, $arg) = @_;
    $c->res->body($arg);
}

sub end : ActionClass('RenderView') {}

1;

and then run the test script:

$ CATALYST_DEBUG=0 script/testapp_test.pl /foo
foo
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文