1Devel::Caller(3) User Contributed Perl Documentation Devel::Caller(3)
2
3
4
6 Devel::Caller - meatier versions of "caller"
7
9 use Devel::Caller qw(caller_cv);
10 $foo = sub { print "huzzah\n" if $foo == caller_cv(0) };
11 $foo->(); # prints huzzah
12
13 use Devel::Caller qw(called_with);
14 sub foo { print called_with(0,1); }
15 foo( my @foo ); # should print '@foo'
16
18 caller_cv($level)
19 "caller_cv" gives you the coderef of the subroutine being invoked
20 at the call frame indicated by the value of $level
21
22 caller_args($level)
23 Returns the arguments passed into the caller at level $level
24
25 caller_vars( $level, $names ) =item called_with($level, $names)
26 "called_with" returns a list of references to the original argu‐
27 ments to the subroutine at $level. if $names is true, the names of
28 the variables will be returned instead
29
30 constants are returned as "undef" in both cases
31
32 called_as_method($level)
33 "called_as_method" returns true if the subroutine at $level was
34 called as a method.
35
37 All of these routines are susceptible to the same limitations as "call‐
38 er" as described in "caller" in perlfunc
39
40 The deparsing of the optree perfomed by called_with is fairly simple-
41 minded and so a bit flaky.
42
43 * The code is currently inaccurate in this case:
44
45 print foo( $bar ), baz( $quux );
46
47 When returning answers about the invocation of baz it will mis‐
48 takenly return the answers for the invocation of foo so you'll
49 see '$bar' where you expected '$quux'.
50
51 A workaround is to rewrite the code like so:
52
53 print foo( $bar );
54 print bar( $baz );
55
56 A more correct fix is left as a TODO item.
57
58 * Under perl 5.005_03
59
60 use vars qw/@bar/;
61 foo( @bar = qw( some value ) );
62
63 will not deparse correctly as it generates real split ops
64 rather than optimising it into a constant assignment at compile
65 time as in later releases of perl.
66
67 * On perl 5.8.x compiled with ithreads it's not currently sup‐
68 ported to retrieve package variables from the past. Instead
69 the empty string is returned for the name, and undef is
70 returned when the value is requested.
71
72 Though crappy, this is an improvement on causing your applica‐
73 tion to segfault.
74
76 "caller" in perlfunc, PadWalker, Devel::Peek
77
79 Richard Clamp <richardc@unixbeard.net> with close reference to Pad‐
80 Walker by Robin Houston
81
83 Copyright (c) 2002, 2003, 2006 Richard Clamp. All Rights Reserved.
84 This module is free software. It may be used, redistributed and/or mod‐
85 ified under the same terms as Perl itself.
86
87
88
89perl v5.8.8 2007-03-13 Devel::Caller(3)