| 1 | package Game::Reversi::Error; | ||||||||||||||||||||||
| 2 | |||||||||||||||||||||||
| 3 | 17 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | 17 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | |||||||||||||||||||||||
| 6 | 17 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | 17 | our $VERSION = '0.04'; | |||||||||||||||||||||
| 9 | |||||||||||||||||||||||
| 10 | 17 | our (@FLAGS, %MESSAGE); | |||||||||||||||||||||
| 11 | |||||||||||||||||||||||
| 12 | 17 | ▶ | BEGIN { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 13 | 17 | @FLAGS = qw/ | |||||||||||||||||||||
| 14 | not_centre | ||||||||||||||||||||||
| 15 | square_taken | ||||||||||||||||||||||
| 16 | not_your_turn | ||||||||||||||||||||||
| 17 | no_flip | ||||||||||||||||||||||
| 18 | has_move | ||||||||||||||||||||||
| 19 | game_over | ||||||||||||||||||||||
| 20 | /; | ||||||||||||||||||||||
| 21 | |||||||||||||||||||||||
| 22 | 17 | %MESSAGE = ( | |||||||||||||||||||||
| 23 | not_centre => 'the first four discs go in the centre four', | ||||||||||||||||||||||
| 24 | square_taken => 'that square is already taken', | ||||||||||||||||||||||
| 25 | not_your_turn => 'it is not your turn', | ||||||||||||||||||||||
| 26 | no_flip => 'that move outflanks nothing', | ||||||||||||||||||||||
| 27 | has_move => 'you have a move, so your turn cannot be forfeited', | ||||||||||||||||||||||
| 28 | game_over => 'the game is over', | ||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||
| 31 | |||||||||||||||||||||||
| 32 | has [@FLAGS] => ( | ||||||||||||||||||||||
| 33 | is => 'ro' | ||||||||||||||||||||||
| 34 | 17 | ); | |||||||||||||||||||||
| 35 | |||||||||||||||||||||||
| 36 | has error => ( | ||||||||||||||||||||||
| 37 | is => 'ro', | ||||||||||||||||||||||
| 38 | default => 1 | ||||||||||||||||||||||
| 39 | 17 | ); | |||||||||||||||||||||
| 40 | |||||||||||||||||||||||
| 41 | has message => ( | ||||||||||||||||||||||
| 42 | is => 'ro', | ||||||||||||||||||||||
| 43 | isa => Str | ||||||||||||||||||||||
| 44 | 17 | ); | |||||||||||||||||||||
| 45 | |||||||||||||||||||||||
| 46 | has legal => ( | ||||||||||||||||||||||
| 47 | is => 'ro', | ||||||||||||||||||||||
| 48 | isa => ArrayRef, | ||||||||||||||||||||||
| 49 | default => [] | ||||||||||||||||||||||
| 50 | 17 | ); | |||||||||||||||||||||
| 51 | |||||||||||||||||||||||
| 52 | 102 | ▶ | sub throw { | ||||||||||||||||||||
|
Subroutine
throw: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 53 | 102 | my ($class, $flag, %extra) = @_; | |||||||||||||||||||||
| 54 | 102 | ▶ | die "'$flag' is not an error flag" unless $MESSAGE{$flag}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 55 | return $class->new( | ||||||||||||||||||||||
| 56 | $flag => 1, | ||||||||||||||||||||||
| 57 | 101 | message => $MESSAGE{$flag}, | |||||||||||||||||||||
| 58 | %extra | ||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||
| 61 | |||||||||||||||||||||||
| 62 | 103 | ▶ | sub code { | ||||||||||||||||||||
|
Subroutine
code: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||
| 63 | 103 | my ($self) = @_; | |||||||||||||||||||||
| 64 | 103 | for my $flag (@FLAGS) { | |||||||||||||||||||||
| 65 | 452 | ▶ | return $flag if $self->$flag; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||
| 67 | 0 | return undef; | |||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||
| 69 | |||||||||||||||||||||||
| 70 | 1 | ▶ | sub flags { return [@FLAGS] } | ||||||||||||||||||||
|
Subroutine
flags: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 71 | |||||||||||||||||||||||
| 72 | 5 | ▶ | sub stringify { | ||||||||||||||||||||
|
Subroutine
stringify: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||
| 73 | 5 | my ($self) = @_; | |||||||||||||||||||||
| 74 | 5 | ▶ | return ($self->code // 'error') . ': ' . ($self->message // ''); | ||||||||||||||||||||
|
Condition50%2/4
$self->code // "error"
$self->message // ""
MC/DC0%0/1
$self->code // "error"
$self->code
MC/DC0%0/1
$self->message // ""
$self->message
Truth table50%1/2
A
A= $self->code
Truth table50%1/2
A
A= $self->message
| |||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||
| 76 | |||||||||||||||||||||||
| 77 | 17 | 1; | |||||||||||||||||||||
| 78 | |||||||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||||