Primeval - terse variable dumping
version 0.02
use Primeval; my $foo = 5; my @bar = 1..10; our %baz = (a => 1, b => 2); prim{eval} '$foo @bar %baz';
prints:
$foo: 5 @bar: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] %baz: {a => 1, b => 2}
prim # always called as prim{eval}
prim{eval} LIST
takes a list of variable names, prints out the names along with their values. each element of the argument list is split on white-space.
while actually a subroutine named prim the block {eval} must always be passed to prim as the first argument. this code block is used to peek into the calling scope to fetch the values for lexical variables. using this code block to access the caller's scope allows this module to have no external dependencies (normally PadWalker would be required to peek into a lexical scope)
prim
{eval}
the arguments are checked to make sure they look like perl variable names, so you don't have to worry about anything accidentally making it into an eval that you wouldn't want to.
prim{eval} will normally only print the first level of an array or hash using a simple internal serialization routine. for full recursive printing, arrays and hashes can be passed to Data::Dumper by setting $Primeval::DUMP = 1
prim{eval}
$Primeval::DUMP = 1
prim{eval} will return a string instead of printing if $Primeval::RETURN is set to a true value.
$Primeval::RETURN
if you use prim{eval} in a subroutine with closed over variables, just make sure that you use every variable passed to prim{eval} somewhere else in the subroutine. otherwise, perl's garbage collector will sweep up the variables too early.
Eric Strom, <asg at cpan.org>
<asg at cpan.org>
prim{eval} only works correctly with closures in perl 5.10+
please report any bugs or feature requests to bug-primeval at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Primeval. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-primeval at rt.cpan.org
copyright 2011 Eric Strom.
this program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
see http://dev.perl.org/licenses/ for more information.
To install Primeval, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Primeval
CPAN shell
perl -MCPAN -e shell install Primeval
For more information on module installation, please visit the detailed CPAN module installation guide.