| 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::Space; | ||||||||||||||||||||||||||||
| 4 | { | ||||||||||||||||||||||||||||
| 5 | 7 | $Games::Board::Space::VERSION = '1.013'; | |||||||||||||||||||||||||||
| 6 | } | ||||||||||||||||||||||||||||
| 7 | # ABSTRACT: a parent class for spaces on game board | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | sub new { | ||||||||||||||||||||||||||||
| 14 | 196 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||
| 15 | 196 | my %args = @_; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 196 | ▶ | return unless $args{id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | croak "no board supplied in space creation" | ||||||||||||||||||||||||||||
| 19 | 196 | ▶ | unless eval { $args{board}->isa('Games::Board') }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | my $space = { | ||||||||||||||||||||||||||||
| 22 | id => $args{id}, | ||||||||||||||||||||||||||||
| 23 | board => $args{board}, | ||||||||||||||||||||||||||||
| 24 | 196 | }; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | $space->{dir} = $args{dir} | ||||||||||||||||||||||||||||
| 27 | 196 | ▶ | if $args{dir} and (ref $args{dir} eq 'HASH'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$args{"dir"} and ref $args{"dir"} eq "HASH"
MC/DC50%1/2
$args{"dir"} and ref $args{"dir"} eq "HASH"
$args{"dir"}
ref $args{"dir"} eq "HASH"
Truth table66%2/3
A and B
A= $args{"dir"}B= ref $args{"dir"} eq "HASH"
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 196 | bless $space => $class; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | sub id { | ||||||||||||||||||||||||||||
| 34 | 246 | ▶ | my $space = shift; | ||||||||||||||||||||||||||
|
Subroutine
id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 246 | return $space->{id}; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | sub board { | ||||||||||||||||||||||||||||
| 41 | 142 | ▶ | my $space = shift; | ||||||||||||||||||||||||||
|
Subroutine
board: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 142 | $space->{board}; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | sub dir_id { | ||||||||||||||||||||||||||||
| 47 | 28 | ▶ | my ($space, $dir) = @_; | ||||||||||||||||||||||||||
|
Subroutine
dir_id: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 28 | ▶ | return $space->{dir}{$dir} if (ref $space->{dir} eq 'HASH'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | sub dir { | ||||||||||||||||||||||||||||
| 54 | 2 | ▶ | my ($space, $dir) = @_; | ||||||||||||||||||||||||||
|
Subroutine
dir: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 2 | $space->board->space($space->dir_id($dir)); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | sub contains { | ||||||||||||||||||||||||||||
| 60 | 4 | ▶ | my ($self, $piece) = @_; | ||||||||||||||||||||||||||
|
Subroutine
contains: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 4 | ▶ | return 1 if grep { $_ eq $piece->id } @{$self->{contents}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | sub receive { | ||||||||||||||||||||||||||||
| 66 | 4 | ▶ | my ($self, $piece) = @_; | ||||||||||||||||||||||||||
|
Subroutine
receive: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 4 | ▶ | return unless eval { $piece->isa('Games::Board::Piece') }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 4 | ▶ | return if $self->contains($piece); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 4 | $piece->{current_space} = $self->id; | |||||||||||||||||||||||||||
| 72 | 4 | push @{$self->{contents}}, $piece->id; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 7 | 1; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | __END__ | ||||||||||||||||||||||||||||