http://www.perlmonks.org?node_id=644467


in reply to Re: Any way to access the contents of a block eval?
in thread Any way to access the contents of a block eval?

However, I don't see the use of this. The contents of an eval BLOCK doesn't change. What's the point of printing out something you already know?

I was thinking of nicer default diagnostic messages for Test::Exception - so instead of writing:

lives_ok { $o->something } 'something worked';

you could just write

lives_ok { $o->something };

And still get a vaguely nice diagnostic

ok - $o->something lived

Replies are listed 'Best First'.
Re^3: Any way to access the contents of a block eval?
by ikegami (Patriarch) on Oct 12, 2007 at 17:00 UTC

    In that case, chromatic's code simplifies to

    use B::Deparse qw( ); my $deparse = B::Deparse->new(); sub lives_ok(&;$) { my ($code, $desc) = @_; $desc = $deparse->coderef2text($code) if !defined($desc); return Text::Exception::lives_ok($code, $desc); }

    Be careful to avoid accidently overriding your own functions with those from the module you are extending.

      D'oh! I knew about that.
Re^3: Any way to access the contents of a block eval?
by chromatic (Archbishop) on Oct 12, 2007 at 16:29 UTC

    Ah, so you already have the sub reference. Even easier.