On 13 Feb 2008, at 00:10, Michael G Schwern wrote:
[snip]
Data::Dump::Streamer can decompile a code reference, complete with
attached lexicals. But as has been pointed out by Yuval, the real
trick is to show the value of all variables used in the block.
[snip]
Yeah... hadn't considered globals, let alone inlined methods. This
hacked on to T::E:
sub ok_if (&;$) {
my ( $coderef, $description ) = @_;
my $ok = eval { $coderef->() };
my $exception = $@;
$Tester->ok( $ok, $description );
unless ( $ok ) {
$Tester->diag( _exception_as_string( "died:",
$exception ) )
if _is_exception( $exception );
$Tester->diag( DumpVars( code => $coderef )->Out );
}
$@ = $exception;
return $ok;
}
called like:
my $answer = 41;
ok_if { $answer == 42 };
gives me:
not ok 1
# Failed test at t/ok_if.t line 10.
# my ($answer);
# $answer = 41;
# $code = sub {
# use warnings;
# use strict 'refs';
# $answer == 42;
# };
which isn't _too_ shabby, but doesn't help much with things like:
ok_if { Foo->new->answer == 42 };
or
ok_if { $Some_dynamic_var == 42 };
So I don't really think it's worth pursuing.
Cheers,
Adrian