如果在Moose的构造函数调用中有额外的参数不是属性,有没有办法死?例如,这个:
package Shoe;
use Moose;
has 'size' => (is => 'ro', isa => 'Num');
has 'color' => (is => 'ro', isa => 'Str', default => 'brown');
1;
会死在
my $sneaker = Shoe->new(size => 11, colour => 'white');
因为colour
不是Shoe
的属性。
我可以发誓我已经看过一个模块或者其他什么来做这件事,但我找不到它。
答案 0 :(得分:6)
对我而言MooseX::StrictConstructor:
package Shoe;
use Moose;
use MooseX::StrictConstructor; # <-- that's all what need
has 'size' => (is => 'ro', isa => 'Num');
has 'color' => (is => 'ro', isa => 'Str');
1;
package main;
my $sneaker = Shoe->new(size => 11, colour => 'white'); #blows up