Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: What package is the method in?

by moritz (Cardinal)
on May 14, 2010 at 16:07 UTC ( [id://840030]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://840030]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-26 04:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found