in reply to A caller() by any other name
The debugger extends what caller() returns if caller is called from the DB:: namespace:
$package:
The package name the sub was in
$filename:
The filename it was defined in
$line:
The line number it was defined on
$subroutine:
The subroutine name; '(eval)' if an eval().
$hasargs:
1 if it has arguments, 0 if not
$wantarray:
1 if array context, 0 if scalar context
$evaltext:
The eval() text, if any (undefined for eval BLOCK)
$is_require:
frame was created by a use or require statement
$hints:
pragma information; subject to change between versions
$bitmask:
pragma information: subject to change between versions
@DB::args:
arguments with which the subroutine was invoked (which is what you want).
You may be able to do what you want by defining an xcaller function that does this:
This is of course pure evil. Localizing @DB::args may let you run this under the debugger, but be prepared for weird and wild situations. You may need to turn off single-stepping in DB::caller_caller if you do try running under the debugger using $DB::single.sub callers_args { return DB::caller_caller(@_); } sub DB::caller_caller { my($level) = @)_; local @DB::args; caller($level+1); return @DB::args; }
Again, if you used this in production code, you would be completely mad. And of course the other consideration: if you need to do this, you're not thinking about the problem the right way. What really needs to happen - forgetting completely about the implementation?
(correction 12/5/08: formatting was awful. Bad perlmonk. No biscuit.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: A caller() by any other name
by Bloodnok (Vicar) on Dec 05, 2008 at 10:55 UTC |