Devel::Caller(3)
π
Devel::Caller β meatier versions of caller
ok so bestie, this is Devel::Caller, and it lives in the perl world under User Contributed Perl Documentation (perl v5.42.0, dated 2023-04-12, iykyk). Basically it's caller but with so much more going on β meatier, juicier, the main character of introspection modules β¨
πΈ SYNOPSIS πΈ
use Devel::Caller qw(caller_cv);
$foo = sub { print "huzzah\n" if $foo == caller_cv(0) };
$foo->(); # prints huzzah
use Devel::Caller qw(called_with);
sub foo { print called_with(0,1); }
foo( my @foo ); # should print '@foo'
like, look at that second one β it literally snitches on the name of the variable you passed in. iconic behaviour, no notes π
π¦ DESCRIPTION π¦
π caller_cv($level)
caller_cv hands you the coderef of the subroutine being invoked at the call frame indicated by the value of $level. like it slides you the actual sub itself. very generous of it π«Ά
π caller_args($level)
Returns the arguments passed into the caller at level $level. that's it, that's the whole vibe β all the args, right there π«
π caller_vars( $level, $names ) / called_with($level, $names)
heads up bestie: in the original page this line is literally written ascaller_vars( $level, $names ) =item called_with($level, $names)β that stray=itemis a little POD oopsie in the source. keeping it here because we don't lie about the source π
So: called_with returns a list of references to the original arguments to the subroutine at $level. and if $names is true, the names of the variables will be returned instead β not the refs, the names. that's the party trick π
constants are returned as undef in both cases. both. cases. undef. πββοΈ
π called_as_method($level)
called_as_method returns true if the subroutine at $level was called as a method. was it invoked with that method-y energy? this tells you. periodt π
π BUGS π
ok so, real talk, none of this is magic:
- All of these routines are susceptible to the same limitations as
calleras described in"caller" in perlfunc. - The deparsing of the optree performed by
called_withis fairly simple-minded and so a bit flaky. lowkey flaky. it's doing its best but it is flaky, that's just the truth π - As a version 2.0 of Devel::Caller we no longer maintain compatibility with versions of perl earlier than 5.8.2. Older versions continue to be available from CPAN and backpan. so if you're on ancient perl, go dig through the archives, she's there ποΈ
π₯ SEE ALSO π₯
"caller" in perlfunc, PadWalker, Devel::Peek β the whole friend group, go say hi π
π AUTHOR π
Richard Clamp <richardc@unixbeard.net> with close reference to PadWalker by Robin Houston. collab of the century, honestly π«Άβ¨
πΈ COPYRIGHT πΈ
Copyright (c) 2002, 2003, 2006, 2007, 2008, 2010, 2013, 2023 Richard Clamp. All Rights Reserved.
This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself. slay, free software, we love to see it π
and that's the whole page bestie!! brought to you by perl v5.42.0, dated 2023-04-12 β mwah, go introspect something beautiful π ππ¦
π¦ where this page comes from
- opensuse-leap 16.0: perl-Devel-Caller 2.07-bp160.1.11 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Devel-Caller 2.07-bp160.1.11 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Devel-Caller 2.07-bp160.1.11 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Devel-Caller 2.07-bp160.1.11 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms