Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is no way to set the superclass for a class once it's been created #153

Open
tobyink opened this issue Nov 19, 2013 · 4 comments
Open

Comments

@tobyink
Copy link
Contributor

tobyink commented Nov 19, 2013

It would be nice to be able to do:

mop::meta("Foo::Baz")->set_superclass("Foo::Bar");

Setting a class' superclass in normal runtime code is (naturally) insanity. But setting it within a class trait is vaguely sensible. For example:

class Foo::Baz is myplugin { }

Might want to set the superclass for Foo::Baz, or might add roles to it, before registering it in some plugin list.

@tobyink
Copy link
Contributor Author

tobyink commented Nov 19, 2013

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));

@doy
Copy link
Collaborator

doy commented Nov 19, 2013

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).

@tobyink
Copy link
Contributor Author

tobyink commented Nov 19, 2013

Super-d'oh!

@tobyink
Copy link
Contributor Author

tobyink commented Nov 19, 2013

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants