in reply to Re^4: Identify the package a subroutine is being called from
in thread Identify the package a subroutine is being called from
sub calling_object { my @a = do { package DB; @DB::args = (); caller(2); }; $DB::args[0]; }
It definitely doesn't work for me the way you had it.
Oh, I got it. After much fiddling, it's the scalar context. The trick does not work when you $foo=caller(2); Must be ($foo) = caller(2); or caller() doesn't populate args. I can't tell if you changed it to @foo or if I transcribed it wrong, but my original cut and paste had $foo = caller(2).
Also, in my previous post, I had assumed $DB::args was pure black magic. I had no idea it was documented grey magic.
-Paul
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Identify the package a subroutine is being called from
by chromatic (Archbishop) on Jun 07, 2008 at 04:38 UTC | |
by jettero (Monsignor) on Jun 07, 2008 at 23:36 UTC |