I haven't done anything with Moose, but I suppose that using Module::Pluggable to find all candidates and then using some part of the Moose API to inspect $package->metaclass is the approach I'd use. Actually, looking at Moose::Meta::Class, the following should tell you whether a class does a role:
package App; use Module::Pluggable sub_name => 'plugins'; my @candidates = App->plugins; for my $class (@candidates) { if ($class->meta->does_role( $role ) { print "$class does $role\n"; }; };
Of course, with this unchecked approach, you force all plugins into the Moose tarpit, which imposes a burden+learning curve on plugin authors. You might want to be more defensive, by wrapping $class->meta in an eval block or by providing a base class for plugins which sets up enough routines for a bare-bones plugin that does no harm.
Update: Upon rereading, I see that you only want to look at the classes that have been loaded - then, I'd stay with the defensive approach outlined above, but fill the @candidates from %INC instead via Module::Pluggable, if you want to avoid setting up Module::Pluggable with the correct search paths or want to avoid (re)loading failing modules.
In reply to Re: find all modules that "do" a role
by Corion
in thread find all modules that "do" a role
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |