use strict; use warnings; use Devel::Peek(); BEGIN { #Many thanks to Thilosophy #see http://www.perlmonks.org/?node_id=743987 for original source #on which this is based sub getOriginalCodeRefName { my ($pkg, $ref) = @_; no strict 'refs'; while (my ($key,$val) = each(%{*{"$pkg\::"}})) { local(*ENTRY) = $val; if (defined $val && defined *ENTRY{CODE}) { next unless *ENTRY{CODE} eq $ref; # rewind "each" my $a = scalar keys %{*{"$pkg\::"}}; return $key; } } warn "Warning: could not find name for $ref"; return undef; } sub MODIFY_CODE_ATTRIBUTES { my $sPackage = shift @_; my $crSub = shift @_; print STDERR "Dumping $crSub in MODIFY_CODE_ATTRIBUTES:\n"; #Devel::Peek::Dump($crSub); my $sName = getOriginalCodeRefName($sPackage, $crSub); $sName = 'undef' unless defined($sName); print STDERR "Name via Thilosophy method: <$sName>\n"; return (); } } BEGIN { sub bar : Lion { print "Oh my!\n"; } print STDERR "\nDumping " . \&bar . " in BEGIN block after compilation.\n"; #Devel::Peek::Dump(\&bar); my $sName = getOriginalCodeRefName(__PACKAGE__, \&bar); $sName = 'undef' unless defined($sName); print STDERR "Name via Thilosophy method: <$sName>\n"; }