package Sims::Controller;
use strict;
use warnings;
use AnyEvent;
use Data::Dump qw(dump);
my @sims;
sub new{
my $class = shift;
my $self = {
INTERVAL => 5
,SIMS => []
};
bless $self, $class;
return $self;
}
sub go{
my ($self,$params) = @_;
$self->{INTERVAL} = $params->{INTERVAL} || $self->{INTERVAL};
$self->{TIMER} = AE::timer 0, $self->{INTERVAL}, sub{
for my $sim ($self->{SIMS}){
$sim->RUN;
}
};
$self->{READY} = AE::cv;
$self->{READY}->recv;
return !0;
}
sub add_sim{
my ($self,$sim) = @_;
push(@{$self->{SIMS}}, $sim);
return !0;
}
1;
package Sims::SimCore;
use strict;
use warnings;
sub new{
my $class = shift;
my $self = {
_ID => shift
};
$self->{RUN} = sub{
print "R$self->{ID}\n";
};
bless $self, $class;
return $self;
};
1;
use strict;
use warnings;
use Data::Dump qw(dump);
use Sims::Controller;
use Sims::SimCore;
my $controller = new Sims::Controller();
my @sims;
push(@sims, new Sims::SimCore(0));
$controller->add_sim($sims[0]);
$controller->go({
INTERVAL => 6
});