package TestWorker;

use strict;
use CWorker;
use vars qw(@ISA);
@ISA = qw( CWorker );


sub new {
    my ($this) = @_;
    my  $class = ref($this) || $this;
    my  $self = {};
    bless($self, $class);
    $self->initialize();

    return $self;
}


sub initialize {
    my( $self ) = @_;

    $self->SUPER::initialize();
    $self->{"Tester.result"} = undef;
    $self->{"Tester.execs"} = [];
}


sub abort {
    my( $self ) = @_;

    $self->{"Tester.result"} = 0;
    $self->{"Tester.execs"} = [];
    $self->inactivate();
}


sub result {
    my( $self ) = @_;
    return $self->{"Tester.result"};
}


sub do_next {
    my( $self, $code ) = @_;
    push( @{$self->{"Tester.execs"}}, $code );
}


sub do {
    my( $self ) = @_;

    while( 1 ) {
	my $next = $self->{"Tester.execs"}->[0];
	if( ! defined $next ) {
	    $self->finish();
	    last;
	}
	my $ret = $next->();
	if( ref($ret) ) {
	    $self->start_after( $ret );
	    last;
	}
	elsif( defined $ret ) {
	    shift @{$self->{"Tester.execs"}};
	    $self->{"Tester.result"} = $ret;
	}
	else {
	    last;
	}
    }
}

