Okay, a really twisted way of getting the information.

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:

sub callers_args { return DB::caller_caller(@_); } sub DB::caller_caller { my($level) = @)_; local @DB::args; caller($level+1); return @DB::args; }
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.

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.)


In reply to Re: A caller() by any other name by pemungkah
in thread A caller() by any other name by Bloodnok

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.