[英]Trying to create Dancer2 custom response
I'm currently trying to create a custom dancer response so that I can return my result in json, however when I run the following code, I get the error:我目前正在尝试创建一个自定义舞者响应,以便我可以在 json 中返回我的结果,但是当我运行以下代码时,我得到了错误:
Can't locate object method "new" via package "Dancer::Response" (perhaps you forgot to load "Dancer::Response"?) at app.pl line 11./
Here is the code:这是代码:
#!/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;
Anyone know why I'm getting an error, or if there's a better way to do this?任何人都知道我为什么会出错,或者是否有更好的方法来做到这一点? Many thanks!
非常感谢!
Dancer::Response
module not loaded. Dancer::Response
模块未加载。 Just type:只需输入:
use Dancer::Response;
Dancer::Request is part of the original Dancer framework. Dancer::Request 是原始 Dancer 框架的一部分。 If you're using Dancer2 , then you should be using Dancer2::Core::Response instead.
如果您使用的是Dancer2 ,那么您应该使用Dancer2::Core::Response 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.