我目前正在嘗試創建一個自定義的舞者回應,以便我可以在 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;
任何人都知道為什么我會收到錯誤,或者是否有更好的方法來做到這一點?非常感謝!
uj5u.com熱心網友回復:
Dancer::Response模塊未加載。只需輸入:
use Dancer::Response;
uj5u.com熱心網友回復:
Dancer::Request 是原始 Dancer 框架的一部分。如果您使用的是Dancer2,那么您應該使用Dancer2::Core::Response代替。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/381744.html
