in reply to getting a subroutine's name
# obtain CODEref info sub coderef_info { my ($coderef) = @_; return () unless UNIVERSAL::isa($coderef, "CODE"); require B; require B::Deparse; my $cv = B::svref_2object($coderef); my $gv = $cv->GV; return $gv->STASH->NAME, $gv->NAME, $gv->FILE, $cv->START->line, B::Deparse->new->coderef2text($coderef); } use Data::Dumper; print Dumper(coderef_info(\&addem));
$VAR1 = 'main'; # package name $VAR2 = 'addem'; # subroutine name $VAR3 = 'coderef.pl'; # filename $VAR4 = 2; # line number where sub was defined $VAR5 = '{ # subroutine code as string ($value1, $value2) = @_; $value1 + $value2; print join(\':\', caller); ($package, $filename, $line) = caller; }';
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: getting a subroutine's name
by chromatic (Archbishop) on Jul 17, 2009 at 19:21 UTC |