Subject: | Inheritance is broken when applying metaclass trait to parent class' metaclass |
Hello.
I have two classes:
package C1;
use Moose;
no Moose;
-1;
package C2;
use Moose;
__PACKAGE__ -> meta() -> add_method( asd => sub{ return; } );
__PACKAGE__ -> meta() -> add_attribute( qwe => ( is => 'rw', isa => 'Any' ) );
extends 'C1';
no Moose;
-1;
...which are working very well until a following role apprears:
package T1;
use Moose::Role;
no Moose::Role;
-1;
...which in it's case is applied to metaclass of C1, which transforms to this:
package C1;
use Moose -traits => [ 'T1' ];
no Moose;
-1;
. Having that role applied, I'm getting following error message:
Can't fix metaclass incompatibility for C2 because it is not pristine
. But if I remove the line
__PACKAGE__ -> meta() -> add_attribute( qwe => ( is => 'rw', isa => 'Any' ) );
from C2 - the error goes away. The error also goes away if I move "extends" rigth under "use Moose", like this:
package C2;
use Moose;
extends 'C1';
__PACKAGE__ -> meta() -> add_method( asd => sub{ return; } );
__PACKAGE__ -> meta() -> add_attribute( qwe => ( is => 'rw', isa => 'Any' ) );
no Moose;
-1;
. This workaround is pretty easy, yes, but in my real case it will lead to modifications of some amount of separate modules, which apparently could be not so easy.
Is there anything I can do besides changing a lot of stuff, or is it a bug which will be fixed?