in reply to Re: how to get a subroutine name?
in thread how to get a subroutine name?
Sorry, which historic reasons?
If you don't like caller's interface - where I sympathize - I'd rather propose something more flexible like returning a hashref:
orDB<116> sub __CALLER__ { my $level = shift; my %hash; @hash{qw/package filename line subroutine hasargs wantarray + evaltext is_require hints bitmask hinthash/} = caller($level+1); return \%hash } DB<130> sub tst { print __CALLER__->{subroutine} } DB<131> tst() main::tst
Though not sure about using this underscore __NAMESPACE__...DB<136> use Data::Dump qw/dd/ DB<137> sub tst { dd __CALLER__ } DB<138> tst() { bitmask => "\0\0\0\0\0\0\0\0\0\0\0\0", evaltext => undef, filename => "(eval 108)[multi_perl5db.pl:644]", hasargs => 1, hinthash => undef, hints => 256, is_require => undef, line => 2, "package" => "main", subroutine => "main::tst", "wantarray" => 1, }
And I'm pretty sure about reinventing the wheel ...
... CPAN is so big and I'm so lazy ;-)
Cheers Rolf
( addicted to the Perl Programming Language)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: how to get a subroutine name?
by hdb (Monsignor) on Jun 26, 2013 at 12:25 UTC |