Board/Space.pm

filter: Statementstmt 97.4% 38 / 39 Branchbran 57.1% 8 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 10 / 10 Podpod 100% 7 / 7 totaltotal 88.0% 66 / 75 SCAR 22.2
CC
9
Cov
86%
new
5.1
receive
3.1
contains
2.1
CRAP 9.2
« Board/Piece.pm ↑ Summary Board.pm »
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
BranchTrueFalseTotal
unless $args{"id"} 0 196 196
18 croak "no board supplied in space creation"
19 196 ▶ unless eval { $args{board}->isa('Games::Board') };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $args{"board"}->isa("Games::Board") } } 0 196 196
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
BranchTrueFalseTotal
if $args{"dir"} and ref $args{"dir"} eq "HASH" 68 128 196
Condition66%2/3
$args{"dir"} and ref $args{"dir"} eq "HASH"
!ll&&!rl&&r
128068
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ref $space->{"dir"} eq "HASH" 28 0 28
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
BranchTrueFalseTotal
if grep {$_ eq $piece->id;} @{$$self{"contents"};} 0 4 4
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
BranchTrueFalseTotal
unless eval { do { $piece->isa("Games::Board::Piece") } } 0 4 4
69 4 ▶ return if $self->contains($piece);
Branch: 1 branch
BranchTrueFalseTotal
if $self->contains($piece) 0 4 4
70  
71 4 $piece->{current_space} = $self->id;
72 4 push @{$self->{contents}}, $piece->id;
73 }
74  
75 7 1;
76  
77 __END__
« Board/Piece.pm ↑ Summary Board.pm »