Open tobyink opened 10 years ago
PS: I have tried the below. It doesn't work, but I have no idea why it does not.
mop::meta(ref $class)
->get_attribute('$!superclass')
->store_data_in_slot_for($class, $parent);
mop::apply_metaclass($class, mop::meta($parent));
It doesn't work because you're setting the metaclass for mop::class
in that snippet. The first line should just be $class
, not mop::meta(ref $class)
.
Super-d'oh!
I take that back: I believe mop::meta(ref $class)
is correct. This gets the $!superclass
attribute for mop::class itself, and then calls store_data_in_slot_for
on that attribute passing $class
(i.e. the meta object for the class I'm wanting to set the superclass of) as the instance.
It would be nice to be able to do:
Setting a class' superclass in normal runtime code is (naturally) insanity. But setting it within a class trait is vaguely sensible. For example:
Might want to set the superclass for Foo::Baz, or might add roles to it, before registering it in some plugin list.