很酷的是,可以在子类中添加它们或者在角色中混合它们。我的问题是,当子类重新定义方法本身(而不是修饰符)时,来自基类的方法修饰符似乎被禁用了。也许我对方法修饰符的理解有误。例如:
use feature 'say';
package Foo;
use Moose;
has called => (is => 'rw', isa => 'Bool', default => 0);
sub call { 'Foo called' }
after call => sub { shift->called(1) };
my $foo = Foo->new();
say $foo->called; # 0
say $foo->call; # Foo called
say $foo->called; # 1
package Bar;
use Moose;
extends 'Foo';
sub call { 'Bar called' }
my $bar = Bar->new();
say $bar->called; # 0
say $bar->call; # Bar called
say $bar->called; # 0
我期望最后的输出结果像$foo
一样是1
。我错在哪里了?