package Guess; use Squatting; package Guess::Controllers; our @C = ( C( Home => [ '/' ], get => sub { my ($self) = @_; $self->redirect(R('Guess')); }, ), C( Guess => [ '/guess' ], get => sub { my ($self) = @_; my $cr = $self->cr; my $rand100 = sub { int(rand(100)) }; my $to_guess = $rand100->(); my $tries = 0; while(1) { my $n = $cr->param('n'); $cr->print(qq| |); $cr->print(qq| Guess a number from 0 to 100
|. sub { if ($n) { return "The guess is invalid." if $n !~ /\d+/; return ($n<$to_guess) ? "The answer is higher." : ($n>$to_guess) ? "The answer is lower." : "You guessed it in $tries tries"; } }->() . qq|
|. (($n!=$to_guess) ? (qq| |) : sub { $tries = 0; $to_guess = $rand100->(); return "start again" }->() ) . qq|
|); $cr->print(qq| |); $cr->next; $tries++; } # while }, continuity => 1, ), ); 1;