Ovid has asked for the wisdom of the Perl Monks concerning the following question:

Given a subroutine reference, is there a way to find out the file and line number where the subroutine was declared? warn and friends seems to get this right, but I need this externally. Here's my test program:

#!/usr/bin/perl -l use strict; use warnings; use B; # line 99 'bin/' { no strict 'refs'; print B::svref_2object(\*{'Foo::some_sub'})->LINE; print B::svref_2object(\&Foo::some_sub)->GV->LINE; } Foo::some_sub(); package Foo; # line 23 'bin/' sub some_sub { warn "Got to here"; }

That outputs:

102 102 Got to here at 'bin/' line 24.

The line information is not what I'm expecting, so I assume I'm doing something wrong (B::GV has a corresponding FILE method, but until I get LINE working, it's not much use to me).