Aw
view release on metacpan or search on metacpan
bin/apache/site_perl/Apache/Toe.pm view on Meta::CPAN
</body>
</html>
END
}
sub updateBoard
{
if ( ref($_[0]) eq "Aw::Event" ) {
#
# Remote Move
#
$board [ $_[0]->getIntegerField('Coordinate') ] = 'O';
} else {
#
# Local Move
#
$board [ $_[0] ] = 'X';
}
$moves++;
}
sub handler
{
my $r = new Apache::Request (shift);
$r->content_type('text/html');
$r->send_http_header;
# my $host = $r->get_remote_host;
# $r->print ("<h1>Client[$$]</h1>\n");
unless ( ref($c) ) {
$r->print ("<h1>Client Died: $message</h1>\n");
return OK;
}
$eventTypeName = undef;
#
# Make sure an adapter is present:
#
unless ( ref ( $ter) ) {
$r->print ("Ter has no REF!" );
return OK;
}
unless ( ref ( $te) ) {
$r->print ("Te has no REF!" );
return OK;
}
$r->print ( "<h1>Publish Error!</h1>\n" ) if ( $c->publish ( $ter ) );
my $reply = $c->getEvent( AW_INFINITE );
if ( ($eventTypeName = $reply->getTypeName) eq "Adapter::ack" ) {
#
# Adapter is alive, proceed:
#
if ( my $cgiBoard = $r->param( 'board' ) ) {
$cgiBoard =~ s/([eXO])/'$1'/g;
$cgiBoard =~ s/,\)/)/;
@board = eval ( $cgiBoard );
$moves = 0;
for (my $i=0; $i<9; $i++) {
$moves++ if ( $board[$i] =~ /[XO]/ );
}
if ( $moves < 9 ) {
$te->setCharSeqField ( 'Board', 0, 0, \@board );
# my $pubId = $reply->getPubId;
# $c->deliver ( $pubId, $te );
$c->deliver ( "TicTacToe Adapter", $te );
my $move = $c->getEvent( AW_INFINITE );
if ( $move->getTypeName eq $tttEvent ) {
updateBoard ( $move );
}
else {
$r->printf ("<h3>Got Some Debugging to do: %s</h3>", $move->getTypename);
}
}
printForm ( $r );
}
else {
#
# If we have no CGI data then this is our first round
#
@board = ( 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e');
printForm ( $r );
}
}
OK;
}
#########################################################
# Do not change this, Do not put anything below this.
# File must return "true" value at termination
1;
##########################################################
__END__
=head1 NAME
Apache::Toe - A mod_perl Web Client for Playing TicTacToe Against An ActiveWorks Adapter.
=head1 SYNOPSIS
See the apache/conf/perl.conf and apache/conf/startup.pl files.
=head1 DESCRIPTION
( run in 1.908 second using v1.01-cache-2.11-cpan-df04353d9ac )