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