in reply to What package is the method in?

ikegami's solution is pretty good, but in the spirit of TIMTOWTDI...

With UNIVERSAL::can you can obtain a code ref to the module, and Sub::Identify tells you where it's from:

use Sub::Identify qw(stash_name); print stash_name($obj->can('method_name'));

Note that this might not be reliable, because sub names can be changed with Sub::Name.

Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^2: What package is the method in?
by ikegami (Patriarch) on May 14, 2010 at 16:34 UTC
    That was my first thought, but it doesn't work given my understanding of the question. It provides the package where the method was compiled, and that's not necessarily the class/package that provides the method.
    $ perl -le' { package Role; use Moose::Role; sub m {} } { package Class; use Moose; with "Role"; } use Sub::Identify qw( stash_name ); print stash_name( Class->new->can("m") ); ' Role

    Your method returns Role even though Class->new->m() would call Class::m. find_implementor returns Class.