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 クラスがあり、.pl ファイルでテストすると問題なく動作しますが、Web ブラウザからアクセスしようとすると、次のエラーが表示されます:オブジェクト メソッド "new" が見つかりませんパッケージ "Dice" 経由 (おそらく "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();
}
}