caller
- caller
Returns the context of the current pure perl subroutine call. In scalar context, returns the caller's package name if there is a caller (that is, if we're in a subroutine or eval or require) and the undefined value otherwise. caller never returns XS subs and they are skipped. The next pure perl sub will appear instead of the XS sub in caller's return values. In list context, caller returns
With EXPR, it returns some extra information that the debugger uses to print a stack trace. The value of EXPR indicates how many call frames to go back before the current one.
Here, $subroutine is the function that the caller called (rather than the function containing the caller). Note that $subroutine may be
(eval)if the frame is not a subroutine call, but an eval. In such a case additional elements $evaltext and$is_requireare set:$is_requireis true if the frame is created by a require or use statement, $evaltext contains the text of theeval EXPRstatement. In particular, for aneval BLOCKstatement, $subroutine is(eval), but $evaltext is undefined. (Note also that each use statement creates a require frame inside aneval EXPRframe.) $subroutine may also be(unknown)if this particular subroutine happens to have been deleted from the symbol table.$hasargsis true if a new instance of @_ was set up for the frame.$hintsand$bitmaskcontain pragmatic hints that the caller was compiled with.$hintscorresponds to $^H , and$bitmaskcorresponds to ${^WARNING_BITS} . The$hintsand$bitmaskvalues are subject to change between versions of Perl, and are not meant for external use.$hinthashis a reference to a hash containing the value of %^H when the caller was compiled, or undef if %^H was empty. Do not modify the values of this hash, as they are the actual values stored in the optree.Furthermore, when called from within the DB package in list context, and with an argument, caller returns more detailed information: it sets the list variable
@DB::argsto be the arguments with which the subroutine was invoked.Be aware that the optimizer might have optimized call frames away before caller had a chance to get the information. That means that
caller(N)might not return information about the call frame you expect it to, forN > 1. In particular,@DB::argsmight have information from the previous time caller was called.Be aware that setting
@DB::argsis best effort, intended for debugging or generating backtraces, and should not be relied upon. In particular, as @_ contains aliases to the caller's arguments, Perl does not take a copy of @_ , so@DB::argswill contain modifications the subroutine makes to @_ or its contents, not the original values at call time.@DB::args, like @_ , does not hold explicit references to its elements, so under certain cases its elements may have become freed and reallocated for other variables or temporary values. Finally, a side effect of the current implementation is that the effects ofshift @_can normally be undone (but notpop @_or other splicing, and not if a reference to @_ has been taken, and subject to the caveat about reallocated elements), so@DB::argsis actually a hybrid of the current state and initial state of @_ . Buyer beware.