默认情况下,穆斯非常宽容.您可以拥有一个名为的类Cucumber,并将未声明的属性(如wheels)传递给构造函数.Moose默认不会抱怨.但我可能更喜欢穆斯而die不是接受未申报的属性.我怎样才能做到这一点?我似乎记得读过它是可能的,但是在文档中找不到它所说的地方.
package Gurke;
use Moose;
has color => is => 'rw', default => 'green';
no Moose;
__PACKAGE__->meta->make_immutable;
package main; # small test for the above package
use strict;
use warnings;
use Test::More;
use Test::Exception;
my $gu = Gurke->new( color => 'yellow' );
ok $gu->color, 'green';
if ( 1 ) {
my $g2 = Gurke->new( wheels => 55 );
ok ! exists $g2->{wheels}, 'Gurke has not accepted wheels :-)';
# But the caller might not …Run Code Online (Sandbox Code Playgroud)