Greetings, I've got a class X. X has a metaclass M. I want M to make X do role Y. That's it. I have been banging my head against a half dozen Moose documentation pages but can't seem to puzzle out this seemingly simple operation.
Which one of these things do I need to use? Moose::Exporter, Moose::Util::MetaRole? (This seems to be about meta roles rather than roles, but I don't _think_ I need to use a meta role to just make a class consume a given role, or do I?) I also found this thing: Moose::Meta::Role::Application::ToClass which sounds really nice but has zero documentation. I looked at the source but, of course, I have no idea WTF is going on. Here is one thing I tried, which doesn't seem to complain, but also doesn't seem to apply the role. (In my test, the class does not cause an exception even though it fails to implement a method required by the role.) package MyApp; use Moose (); use Moose::Exporter; use MyApp::Meta::Class; Moose::Exporter->setup_import_methods( with_meta => [ 'handler' ], also => 'Moose', ); sub init_meta { my $class = shift; my $meta = Moose->init_meta( @_ , metaclass => 'MyApp::Meta::Class' ); Moose::Meta::Role->initialize( 'MyApp::Role::App' )->apply( $meta ); return $meta; } ... 1; Thanks, Mike