http://www.perlmonks.org?node_id=1015364


in reply to Find out who redefined a subroutine

Ta da!

sub sub::source { require Sub::Identify; my ($class, $func) = @_; my $code = $class->can($func) or return; return Sub::Identify::stash_name($code); } { package MyApp; use Time::HiRes qw(time); use Carp; } # Where do MyApp's subs come from? # print MyApp->sub::source('carp'), "\n"; print MyApp->sub::source('time'), "\n"; # Where do Carp's subs come from? # print Carp->sub::source('carp'), "\n"; print Carp->sub::source('import'), "\n";

Though it's worth noting that Sub::Name is able to fool Sub::Identify. Also, Moose/Moo/etc do stringy eval stuff that fools Sub::Identify (deliberately).

package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name