情况似乎是这样的:
class Foo { has $!bar }; say Foo.new( :3bar ).perl # OUTPUT: «Foo.new»
文档说it's implementation dependent,但我想知道这是否真的有意义。
.perl
输出是正确的。 Foo.new( :3bar )
不按你的想法行事。如果你添加一个method bar() { $!bar }
,你会发现私有属性$!bar
没有设置:
class Foo {
has $!bar;
method bar() { $!bar }
}
say Foo.new( :3bar ).bar; # (Any)
say Foo.new( :3bar ).perl; # Foo.new
命名参数:3bar
(aka bar => 3
)被默默忽略,因为没有名为bar
的公共属性。
如果你想让它抱怨这种情况,那么也许https://modules.perl6.org/dist/StrictNamedArguments适合你。