我有我的舞者應用模塊下面的代碼:我可以在Dancer中實例化一個對象來返回一個值來顯示嗎?
package Deadlands;
use Dancer ':syntax';
use Dice;
our $VERSION = '0.1';
get '/' => sub {
my ($dieQty, $dieType);
$dieQty = param('dieQty');
$dieType = param('dieType');
if (defined $dieQty && defined $dieType) {
return Dice->new(dieType => $dieType, dieQty => $dieQty)->getStandardResult();
}
template 'index';
};
true;
我有一個名爲Dice.pm一個Moops類,如果我有一個特等文件來測試它的作品就好了,但是當我嘗試訪問它通過網絡瀏覽器,我得到以下錯誤:無法通過軟件包「Dice」找到對象方法「new」(也許你忘了加載「Dice」?)。
我可以和舞者一起做這個嗎?
這裏是Dice.pm相關代碼:
use 5.14.3;
use Moops;
class Dice 1.0 {
has dieType => (is => 'rw', isa => Int, required => 1);
has dieQty => (is => 'rw', isa => Int, required => 1);
has finalResult => (is => 'rw', isa => Int, required => 0);
method getStandardResult() {
$self->finalResult(int(rand($self->dieType()) + 1));
return $self->finalResult();
}
}
我想你'使用骰子;'? – ThisSuitIsBlackNot
@ThisSuitIsBlackNot錯誤消息表明他們*不*具有'使用骰子;' –
使用骰子確實在腳本的頂部。我更新了代碼以顯示整個腳本。 – BackPacker777