in reply to Re: find all modules that "do" a role
in thread find all modules that "do" a role

You're right, Module::Pluggable would give me a good set to start checking. The thing is that I didn't want to depend on M::P, but also check things that were used or required.

I suppose that, wheather using %INC, or ${*::*}, I'll need to check if the class uses "moose" before invoking $class->meta.

Replies are listed 'Best First'.
Re^3: find all modules that "do" a role
by Corion (Patriarch) on Sep 07, 2009 at 15:55 UTC

    Module::Pluggable is core, so the only burden would be (again) upon the plugin author. Personally, I wouldn't check whether a class/package uses Moose but rather just do

    my $metaclass = eval { $class->meta }; if ($metaclass) { };

    that way non-Moose things have an option to work as plugins as well, as long as they have:

    sub meta { ... }

    which returns something "good enough". For example the following should work for your use case as a minimal class:

    package My::Plugin; sub meta { __PACKAGE }; sub does_role { my ($class,$role) = @_; $role eq 'chatbot' }; 1