| 1 | 7 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 2 | 7 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | package Games::Board::Piece; | ||||||||||||||
| 4 | { | ||||||||||||||
| 5 | 7 | $Games::Board::Piece::VERSION = '1.013'; | |||||||||||||
| 6 | } | ||||||||||||||
| 7 | # ABSTRACT: a parent class for board game pieces | ||||||||||||||
| 8 | |||||||||||||||
| 9 | 7 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | |||||||||||||||
| 12 | |||||||||||||||
| 13 | sub new { | ||||||||||||||
| 14 | 3 | ▶ | my ($class, %args) = @_; | ||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||
| 15 | |||||||||||||||
| 16 | 3 | ▶ | return unless $args{id}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 17 | 3 | ▶ | return unless eval { $args{board}->isa('Games::Board') }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 18 | |||||||||||||||
| 19 | 3 | my $piece = { %args }; | |||||||||||||
| 20 | |||||||||||||||
| 21 | 3 | bless $piece => $class; | |||||||||||||
| 22 | } | ||||||||||||||
| 23 | |||||||||||||||
| 24 | |||||||||||||||
| 25 | sub id { | ||||||||||||||
| 26 | 4 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 27 | 4 | $self->{id}; | |||||||||||||
| 28 | } | ||||||||||||||
| 29 | |||||||||||||||
| 30 | |||||||||||||||
| 31 | sub board { | ||||||||||||||
| 32 | 4 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
board: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 33 | 4 | $self->{board}; | |||||||||||||
| 34 | } | ||||||||||||||
| 35 | |||||||||||||||
| 36 | |||||||||||||||
| 37 | sub current_space_id { | ||||||||||||||
| 38 | 6 | ▶ | my $piece = shift; | ||||||||||||
|
Subroutine
current_space_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 39 | 6 | $piece->{current_space}; | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | |||||||||||||||
| 42 | |||||||||||||||
| 43 | sub current_space { | ||||||||||||||
| 44 | 4 | ▶ | my $piece = shift; | ||||||||||||
|
Subroutine
current_space: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||
| 45 | 4 | ▶ | return unless $piece->{current_space}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 46 | 4 | $piece->board->space($piece->{current_space}); | |||||||||||||
| 47 | } | ||||||||||||||
| 48 | |||||||||||||||
| 49 | |||||||||||||||
| 50 | sub move { | ||||||||||||||
| 51 | 4 | ▶ | my $piece = shift; | ||||||||||||
|
Subroutine
move: called CC=6 SCAR=18.7
Pod
documented
| |||||||||||||||
| 52 | 4 | my ($how, $which) = @_; | |||||||||||||
| 53 | 4 | my $space; | |||||||||||||
| 54 | |||||||||||||||
| 55 | 4 | ▶ | if ($how eq 'dir') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 56 | 2 | ▶ | return unless $piece->current_space; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 57 | 2 | ▶ | return unless $space = $piece->current_space->dir($which); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 58 | } elsif ($how eq 'to') { | ||||||||||||||
| 59 | 2 | ▶ | return unless eval { $which->isa('Games::Board::Space') }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 60 | 2 | $space = $which; | |||||||||||||
| 61 | } else { | ||||||||||||||
| 62 | 0 | return; | |||||||||||||
| 63 | } | ||||||||||||||
| 64 | |||||||||||||||
| 65 | 4 | $space->receive($piece); | |||||||||||||
| 66 | } | ||||||||||||||
| 67 | |||||||||||||||
| 68 | 7 | 1; | |||||||||||||
| 69 | |||||||||||||||
| 70 | __END__ | ||||||||||||||