Aw

 view release on metacpan or  search on metacpan

bin/apache/site_perl/Apache/Toe.pm  view on Meta::CPAN

	elsif ( $status == $LOSE ) {
		$title = "You Lose!";
	}
	else {
		$title = "Stalemate!  Noone Wins!";
	}
}

$r->print(<<TABLE);
<html>
<head>
  <title>TicTacToe</title>
</head>
<body bgcolor="#f0f0f0">
<h1 align="center">$title</h1>
<center><div align="center">
<table border>
TABLE

for (my $j=0; $j<3; $j++) {
	$r->print ( "  <tr align=\"center\">\n" );
	for (my $i=0; $i<3; $i++) {
		if ( $status == OK && $board[$j*3+$i] eq "e" ) {
  			$r->print ( "    <td><a href=\"/TicTacToe?board=(" );
			for (my $k=0; $k<9; $k++) {
				if ( $k == ($j*3+$i) ) {
					$r->print ("X,");
				}
				else {
					$r->print ("$board[$k],");
				}
			}
			$r->print ( ")\"><img border=0 $Images{'e'}></a></td>" );
		}
		else {
	  		$r->print ( "    <td><img border=0 $Images{$board[$j*3+$i]}></td>\n" );
		}
	}
	$r->print ( "  </tr>\n" );
}

$r->print(<<ENDTABLE);
</table>
</div></center>
ENDTABLE

$r->print ( "<hr><h4 align=\"center\"><i><a href=\"/TicTacToe\">Play Again?</a></i></h4>" ) if ( $status != $OK );

$r->print(<<END);
<hr>
<p align="center"><strong>According to Apache Server $$</strong></p>

</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++) {



( run in 3.111 seconds using v1.01-cache-2.11-cpan-df04353d9ac )