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


in reply to Re^3: Getting file and line number where a subroutine is declared
in thread Getting file and line number where a subroutine is declared

Symbolic refs will do instead of eval.

{ no strict 'refs'; my $name = 'Foo::some_sub'; print B::svref_2object(\*$name)->LINE; print B::svref_2object(\&$name)->GV->LINE; $name->(); }

It can be done with strict refs too.

my $glob = $::{'Foo::'}{some_sub}; print B::svref_2object(\*$glob)->LINE; print B::svref_2object(\&$glob)->GV->LINE; $glob->();