package Test;

use strict;
use warnings;

use AnyEvent;
use AnyEvent::Run;


sub new {

    my $class = shift;
    my $self = {};

    bless $self, $class;

    return $self;
}


sub start {

    my $self = shift;

    $self->run_it();
}

sub run_it() {
    my $self = shift;
    my @command = ('sleep', '3');

    $self->{runner} = AnyEvent::Run->new(
        cmd => \@command,
        on_read => sub {
            my $handle = shift;

        },
        on_eof => sub {
	    my $handle = shift;

            undef $self->{runner};
	    
            $self->{timer} = AnyEvent->timer(
                after => 2,
                cb => sub {
		    undef $self->{timer};
                    $self->run_it();
                },
                );
        },
        );
    
    
}

package main;

use AnyEvent::Impl::POE;
use AnyEvent;

my $test = Test->new();

$test->start();

AnyEvent->condvar->recv;
