Devel::ArgNames(3pm)

๐Ÿ“ฆ
version 0.03 ยท 6 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

๐Ÿ’– Devel::ArgNames ๐Ÿ’–

okay bestie, welcome to Devel::ArgNames โ€” it's a Perl module (a 3pm page, we love that for it), it lives in the User Contributed Perl Documentation, and it does exactly one gorgeous thing: it figures out the names of variables passed into subroutines. that's the whole vibe. ๐ŸŽ€


โœจ NAME โœจ

Devel::ArgNames โ€” figure out the names of variables passed into subroutines. no cap, that's it, that's the job.


๐ŸŒธ SYNOPSIS ๐ŸŒธ

use Devel::ArgNames;

sub foo {
    warn "foo() called with arguments: "
        . join(", ", map { defined() ? $_ : "<unknown>" } arg_names(@_) );
}

foo($bar, $gorch, $blah[4]);

so like. you call arg_names(@_) and it just knows what the variables were called at the call site. it's giving psychic. ๐Ÿ”ฎ


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

okay so when you're print-debugging (we've all been there, no shame), you will often find yourself writing stuff like:

print "\$foo is $foo, \$bar is $bar"

and honestly? manually escaping all those \$ sigils is so tedious. exhausting. not the move. ๐Ÿ˜ญ

with this module you can just write a reusable subroutine instead, effortlessly:

sub my_print_vars {
    my %vars;

    @vars{arg_names()} = @_;

    foreach my $var ( keys %vars ) {
        warn "$var is $vars{$var}\n";
    }
}

my_print_vars($foo, $bar);

look at that. the variable names come for free from the caller's arguments. iconic behavior. ๐Ÿ‘‘

real talk though: this module doesn't provide dumping facilities, because there are way too many of those to choose from and it's not about to pick favorites. it's a DIY kit ;-) so you build your own little printer and it hands you the names.

๐Ÿ’… EXPORTS ๐Ÿ’…

  • arg_names [ $level ] โ€” this function returns the names associated with the variables it finds on @_, at the level $level. and if you don't pass $level? then arg_names's caller's caller gets used โ€” which is the $level == 2 case, for the people keeping score. ๐Ÿ’ฏ

๐Ÿงš VERSION CONTROL ๐Ÿงš

this module is maintained using Darcs. you can grab the latest version from http://nothingmuch.woobling.org/Devel-ArgNames/, and use darcs send to commit changes. old school but it works, okay? ๐Ÿซถ


๐Ÿ”ฅ SEE ALSO ๐Ÿ”ฅ

  • Data::Dumper::Simple
  • DB
  • Devel::Caller
  • Devel::Caller::Perl
  • PadWalker

go read those too, they're the friend group. ๐ŸŒˆ


๐Ÿ‘‘ AUTHORS ๐Ÿ‘‘

  • Ran Eilam
  • Yuval Kogman <nothingmuch@woobling.org>

Copyright (c) 2007 Yuval Kogman. All rights reserved
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.

okay and that's the whole page, bestie!! this little write-up is Devel::ArgNames(3pm), sitting in the User Contributed Perl Documentation, and the version living down at the bottom of the original is perl v5.36.0 from 2022-12-06. mwah. slay. periodt. ๐Ÿ’–โœจ๐ŸŽ€

๐Ÿ“ฆ where this page comes from