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 as caller_vars( $level, $names ) =item called_with($level, $names) β€” that stray =item is 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 caller as described in "caller" in perlfunc.
  • The deparsing of the optree performed by called_with is 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 (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