in reply to Identify the package a subroutine is being called from

You can get more information by calling caller in list context:
package Test: sub package_name { my @c = caller(0); $c[3]; }
Although, the way you have set things up, this will return Test::package_name for both Calling->package_name and Calling2->package_name. Technically this is correct so you could add information about $_[0] in the result.
sub package_name { my @c = caller(0); "$c[3] (with self = $_[0])" }

Replies are listed 'Best First'.
Re^2: Identify the package a subroutine is being called from
by moritz (Cardinal) on Jun 06, 2008 at 17:21 UTC
    You can get more information by calling caller in list context

    Actually (caller)[0] does call it in list context. The number of arguments to caller matters, though:

    $ perl -wle 'sub foo { my @l = caller(); return scalar @l }; print foo +()' 3 $ perl -wle 'sub foo { my @l = caller(0); return scalar @l }; print fo +o()' 10
      You're right. How may we invoke caller? Let us count the ways:
      $package = caller; @info = caller; # -> ($package, $file, $line) $package = caller($i); @extra_info = caller($i); # -> ($pack, $file, $line, $sub, $hasargs, ...)