我目前正在尝试创建一个自定义舞者响应,以便在json中返回我的结果,但是当我运行以下代码时,会得到错误:
Can't locate object method "new" via package "Dancer::Response" (perhaps you forgot to load "Dancer::Response"?) at app.pl line 11./以下是代码:
#!/usr/bin/perl
use warnings;
use strict;
use Dancer2;
require './commacounter.pl';
print "Running";
Dancer::Response->new(
status => 200,
content => 'null'
);
my $response = Dancer2::SharedData->response;
Dancer2::SharedData->response->status; #200
get '/text=:string' => sub {
$response->content_type('application/json');
$response->content(commacounter(params->{string}));
return $response;
};
any qr{.*} => sub {
status 'not_found';
template 'special_404', { path => request->path};
};
dance;谁知道我为什么会出错,或者有没有更好的方法?非常感谢!
发布于 2021-12-13 21:13:21
Dancer::Response模块未加载。只需键入:
use Dancer::Response;发布于 2021-12-14 20:10:55
舞者:请求是原始舞者框架的一部分。如果您使用的是Dancer2,那么您应该使用Dancer2 2::核心::回应。
https://stackoverflow.com/questions/70319600
复制相似问题