perl - Catalyst:将查询参数传递给 "forward"调用

标签 perl catalyst

我有一个 Catalyst Controller ,它以通常的方式响应参数 (/endpoint/foo/bar),但也采用安全 token 的查询参数。在发起对此 Controller 的 forward 调用之前,如何设置参数的值?它不允许我分配给 $c->req->param('token')

(不可能重写 Controller 来接受 token 作为参数而不是参数。)

最佳答案

$c->req->param('token') 不是 LValue,因此您不能分配给它。相反,您需要 to pass in the value .

$c->req->param('token', 1);

这种行为有记录:

Like CGI, and unlike earlier versions of Catalyst, passing multiple arguments to this method, like this:

 $c->request->param( 'foo', 'bar', 'gorch', 'quxx' );

will set the parameter foo to the multiple values bar, gorch and quxx. Previously this would have added bar as another value to foo (creating it if it didn't exist before), and quxx as another value for gorch.

考虑这个演示:

package MyApp::Controller::Root;
use base 'Catalyst::Controller';
__PACKAGE__->config(namespace => '');

sub default : Path {
    my ($self, $c) = @_;
    $c->req->param('foo', 1);
    $c->forward('bar');
}

sub bar : Path('foo') {
    my ($self, $c) = @_;

    if ($c->req->param('foo')) {
        $c->res->body("Secret param set!\n");
    }
    else {
        $c->res->body("Hello World\n");
    }
    return;
}

关于perl - Catalyst:将查询参数传递给 "forward"调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58935999/

相关文章:

perl - 如何在 Perl CGI 脚本中生成长时间运行的进程?

mysql - DBIx 迁移无法识别 MySQL

perl - Mojolicious url_for : absolute path

perl - 我应该如何使用 Catalyst 在 Perl 中进行 RPC?

ios - 复制 png 错误,退出代码为 5

json - "Fatal error: ' EXTERN.h ' file not found"安装 Perl 模块时

perl - 使用 Perl 写入文件的最简单方法是什么?

perl - "su"等效于 Web 应用程序身份验证,设计问题

mysql - Perl/DBIx::Class::Schema::Loader 后缀 _2 以复制关系名称

Perl 催化剂应用修改