Subject: | In a subclass which overrides an attribute and its builder, the overridden builder is ignored |
Moo 2.003
If an attribute is overridden in a subclass, an overridden builder is ignored.
Here's example code.
* Foo is the base class with an attribute with a builder.
* Bar extends Foo, overriding both the attribute and its builder
* Blg extends Foo, overriding only the builder.
{
package Foo;
use Moo;
has 'attr' => (
is => 'ro',
builder => sub { print __PACKAGE__, "\n" }
);
}
{
package Bar;
use Moo;
extends 'Foo';
has '+attr' => ( init_arg => undef );
sub _build_attr { print __PACKAGE__, "\n" }
}
{
package Blg;
use Moo;
extends 'Foo';
sub _build_attr { print __PACKAGE__, "\n" }
}
Foo->new->attr;
Bar->new->attr;
Blg->new->attr;
I expect the output to be
Foo
Bar
Blg
however, it's
Foo
Foo
Blg
Thanks,
Diab