in reply to Name of caller if aliased?

I don't know how far you want to go to get the names but this seems to work well in my limited testing.

Foo.pm:
package Foo; use strict; use warnings; use Sub::Name; # forward declarations so AUTOLOAD can limit what works use subs qw( func funk ); $\ = "\n"; sub show { print join "\t", (caller(0))[0..3]; } sub AUTOLOAD { my ( $name ) = our $AUTOLOAD =~ /::(\w+)$/; return unless __PACKAGE__->can( $name ); # only allow those subs l +isted above my $fullname = __PACKAGE__ . '::' . $name; no strict 'refs'; *{ $fullname } = Sub::Name::subname $fullname => *show; goto &$fullname; } 1;
foo.pl:
#!/bin/env perl use strict; use warnings; use Foo(); Foo::show(); Foo::func(); Foo::funk();

Output:

main    ./foo.pl        7       Foo::show
main    ./foo.pl        8       Foo::func
main    ./foo.pl        9       Foo::funk

Replies are listed 'Best First'.
Re^2: Name of caller if aliased?
by LanX (Saint) on Feb 25, 2015 at 22:43 UTC
    Hi

    Don't wanna install Sub::Name now but I doubt this really works cause you are renaming the original sub.

    Try to call func again and it should show the last name assigned.

    Anyway thanks, I was asking for an easy way, I'll rather stick with generating different closures for each symbol now. :)

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)

    PS: Je suis Charlie!

      D'oh. You're absolutely right but I did warn you that I had done minimal testing. :)