Acme-RTB

 view release on metacpan or  search on metacpan

RTB/RTB.pm  view on Meta::CPAN

=head3 GameFinishes

Current game is finished, get prepared for the next!

=head3 ExitRobot

Exit from the program immediately! Otherwise it will be killed forcefully.

=over 4

=head2 process_lines

=back

This is the method that reads (if it can) from the server and execute
the apropiate method. You can manage yourself, or let the module to
do it itself.

while(1)
{
        # Read stdin

RTB/RTB.pm  view on Meta::CPAN

sub modify_action
{
        my ($self, $key , $code) = @_;
        if(exists $actions{$key} and ref($code) eq "CODE")
        {
                $actions{$key} = $code;
        }
}

###
sub process_lines
{
        my $self = shift;
        while(my @l = $select->can_read(0.1))
        {
                my $hd = $l[0];
                my $msg = <$hd>;
                chomp($msg);
                print LOG "<--- $msg\n" if $self->{Log};
                my ($cmd, @options) = split' ',$msg;
                $cmd = 'Unknown' unless exists $actions{ $cmd };

RTB/RTB.pm  view on Meta::CPAN

        my ($self, $a,$r1,$r2) = @_;
        print "DebugCircle $a $r1 $r2\n";
        print LOG "DebugCircle $a $r1 $r2\n" if $self->{Log};
}

sub Start
{
        my $self = shift;
        while(1)
        {
                $self->process_lines;
                sleep 1;
        }
}

sub Log
{
        my ($self, $msg) = @_;
        print LOG "$msg\n" if $self->{Log};
}



( run in 0.230 second using v1.01-cache-2.11-cpan-8d75d55dd25 )