nadim khemir <[EMAIL PROTECTED]> writes:

> On Friday 02 May 2008 01.24.00 Eirik Berg Hanssen wrote:
>> use Test::More tests => 1;
>> use Test::Trap;
>> trap { warn "1\n2\n3" };
>> $trap->warn_like(0, qr/1\n2\n3/);
>
> Ah! I like this. How did I miss this module??

  Perhaps I just haven't been _quite_ shameless enough plugging it? ;-)

> is it possible to have trap{} return an object/sub/whatever that is created 
> by 
> the trap{}. The automagic $trap is too automagic for me.

  Possible?  Sure, if you wrap it up for that.  This is pure Perl,
after all.  :)

  Recommended?  Not really.  It kinda runs counter to the design.  The
idea was for trap{}/$trap to mimic eval{}/$@; for one thing
list/scalar/void context is propagated into the block; for another,
$trap is a (package, but still) global, so you may localize it.

  It seems to me any alternative interface will be either overly,
un-perly verbose or else severely restricted.  But, granted, the
severely restricted interface may be enough for you.


  As a slightly less automagic alternative, you could name your
function and scalar explicitly; trap{}/$trap is just the default,
though you could be explicit in importing them too:

use Test::More tests => 1;
use Test::Trap qw( trap $trap );
trap { warn "1\n2\n3" };
$trap->warn_like(0, qr/1\n2\n3/);


Eirik
-- 
Some people have told me they don't think a fat penguin really embodies the
grace of Linux, which just tells me they have never seen a angry penguin
charging at them in excess of 100mph.  They'd be a lot more careful about
what they say if they had.  -- Linus Torvalds, announcing Linux v2.0

Reply via email to