可以将它们添加到子类中或将它们混合在角色中,这很酷。我的问题是,当子类重新定义方法本身(而不是修饰符)时,基类中的方法修饰符似乎被停用。也许我理解方法修饰符是错误的。例子:
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
我希望最后一个输出1
与$foo
. 我究竟做错了什么?