On Tue, Nov 12, 2002 at 11:04:53PM +0000, Adrian Howard wrote: > Ohhhh! Just had an idea prompted by reset(). How about having > > $builder->push_state; > $builder->pop_state; > > that would store and restore the complete state of the builder object > in a stack? Would make it easier to isolate a set of tests from the main > sequence.
I think I'll merge your $Test::Builder::default idea with this. Have a stack of Test::Builder objects rather than just the states. This way you can do something like the above. If you add a $tb->copy method which returns a carbon-copy of $tb then... $tb->push_state; # calls $tb->copy and pushes it into the stack # the copy will now be used by default $tb->pop_state; # pops the stack and tosses it, restoring the # original. but what if you want to use your own subclass? Well if you also add a $tb->state method which return the full internal state it makes it possible for subclasses to copy each other. So... $tb->push_state(My::Test::Builder->copy($tb)); ...my test code... $tb->pop_state; The problem there is the case where you want to override behaviors but still keep state between the two objects. So things like the test counter and test details would have to be preserved. I guess this is what chromatic was talking about when he suggested having only certain parts of the internal state be a singleton. So looking at the stuff in reset(): sub reset { my ($self) = @_; $Test_Died = 0; $Have_Plan = 0; $No_Plan = 0; $Curr_Test = 0; $Level = 1; $Original_Pid = $$; @Test_Results = (); @Test_Details = (); $Exported_To = undef; $Expected_Tests = 0; $Skip_All = 0; $Use_Nums = 1; ($No_Header, $No_Ending) = (0,0); $self->_dup_stdhandles unless $^C; return undef; } We can seperate them out into Test::Builder configuration and test state. This is test state and would be shared amongst the T::B objects in the default stack $Test_Died $Have_Plan $No_Plan $Curr_Test $Original_Pid @Test_Results @Test_Details $Expected_Tests $Skip_All and these are T::B configuration values and wouldn't be shared, though they would be initially copied. $Level $Exported_To $Use_Nums $No_Header $No_Ending the output filehandles So I guess we need several constructors. real constructor - a "normal" constructor singleton constructor - returns a single, default object. This object is actually a wrapper around the default object stack. copy - copies the state of one object to a new one copy & share state - like copy, but test state is shared between the original and the copy with those plus the push/pop_stack methods you can pick and choose what sort of state sharing you want. -- Michael G. Schwern <[EMAIL PROTECTED]> http://www.pobox.com/~schwern/ Perl Quality Assurance <[EMAIL PROTECTED]> Kwalitee Is Job One My enormous capacity for love is being WASTED on YOU guys -- http://www.angryflower.com/497day.gif