Jonathan Rockway <[EMAIL PROTECTED]> writes: > I think the most sane interface would be: > > my $trap = trap { ... }; > is $trap->foo, 'foo'; > is $trap->bar, 'bar';
Test::Trap already provides: trap { ... }; is $trap->foo, 'foo'; # for certain values of foo is $trap->bar, 'bar'; # ... and bar Difference being in one less (explicit) assignment, and one less headache about declarations. (Avoiding those '"my" variable $trap masks earlier declaration' upon cut-and-paste, as well as those 'Global symbol "$trap" requires explicit package name' upon moving tests around.) I have my coworkers writing more tests that way. In all probability, _I_ am writing more tests that way. > You said you're trying to emulate $@, but $@ can be changed out from > under you rather easily, so instead of: It is not _quite_ as easy changing $trap out from under you. Yes, I'm making it harder for those that use trap {} in DESTROY etc, but it is still possible to get it right, and I'd rather keep simple things simple. > Anyway, automatically setting variables should always be avoided, > regardless of whether or not it is "perlish". I want correct tests, not > "perlish" tests. Personally, I'll take one broken along with 99 correct tests any day, if the alternative is ten tests, be they correct or not. But I have yet to encounter (as opposed to deliberately construct) a _single_ test broken due to the automatic setting of $trap. Having said all that, it is tempting to give you this alternative interface on an import option: use Test::Trap qw(:return_trap); my $trap = trap { ... }; is $trap->foo, 'foo'; is $trap->bar, 'bar'; Tempting because it is easy, and because I'm all too fond of interfaces and MTOWTDI. But on the other hand, this will confuse those that expect trap { ... } to return the last value in the block, and those will be all that _don't_ use this import option. So, I don't think so. Perhaps a subclass though ... Eirik -- Skill without imagination is craftsmanship and gives us many useful objects such as wickerwork picnic baskets. Imagination without skill gives us modern art. -- Tom Stoppard