Beefy Boxes and Bandwidth Generously Provided by pair Networks BBQ
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Any way to access the contents of a block eval?

by adrianh (Chancellor)
on Oct 12, 2007 at 12:56 UTC ( #644467=note: print w/ replies, xml ) Need Help??


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


Comment on Re^2: Any way to access the contents of a block eval?
Select or Download Code
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.

Re^3: Any way to access the contents of a block eval?
by ikegami (Pope) 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://644467]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (17)
As of 2014-04-18 18:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (471 votes), past polls