Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

statico (5018)

statico
  ian.langworthNO@SPAMgmail.com
http://langworth.com/
AOL IM: eisforian (Add Buddy, Send Message)

PAUSE-ID: IAN [cpan.org]

Co-author of Perl Testing: A Developer's Notebook [oreilly.com]

Journal of statico (5018)

Thursday March 31, 2005
11:39 PM

Error, i woe thee

[ #23966 ]

This bit us. This bit us hard and I blame myself for not catching it. Looking at it after a good night's sleep sets off tons of loud, Star Trek-esque "red alert" klaxons. Why it's bad is left as an exercise for the reader.

################################################################################
# contract: Player, index -> Turn
# let the player take its turn and do validation/contract checking/timeouts
sub give_turn_to_player {
    my ($self, $player, $index) = @_;
 
    my $turn = Game::Turn->new({
        index => $index,
        player => $player,
        admin => $self,
    });
 
    try {
        local $SIG{ALRM} = sub {
            throw Game::Exception::PlayerTimeout(
                'Player timed out after '.PLAYER_TIMEOUT.' seconds' );
        };
        alarm PLAYER_TIMEOUT;
 
        $player->is_taking_turn(1);
        $player->take_turn($turn);
        $player->is_taking_turn(0);
    }
 
    catch Game::Exception::ContractViolation with {
        $self->kick_out_player($player, "You have violated a contract: ".shift);
        return;
    }
 
    catch Game::Exception::PlayerTimeout with {
        $self->kick_out_player($player, "You have timed out after ".PLAYER_TIMEOUT." seconds.");
        return;
    }
 
    otherwise {
        die "asking the player to take a turn failed: ".shift;
    }
 
    finally {
        alarm 0;
    };
 
    unless ($turn->chosen_tile) {
        $self->kick_out_player($player, "You have attempted to place an undefined tile.");
        return;
    }
 
    return $turn;
}

(Still not sure? Here's a hint [PDF]. I swear I remember Matt Sergeant telling me so.)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.