2048/Grid.pm

filter: Statementstmt 100% 31 / 31 Branchbran 100% 4 / 4 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 3 / 3 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 9 totaltotal 86.1% 56 / 65 SCAR 16.1
CC
5
Cov
100%
within_bounds
4.0
tile
2.0
BEGIN
1.0
CRAP 5.0
« 2048/Input.pm ↑ Summary 2048/Animation.pm »
1 package Games::2048::Grid;
2 4 ▶use 5.012;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 4 has size => is => 'ro', default => 4;
6 4 has _tiles => is => 'lazy';
7  
8 sub _build__tiles {
9 55 ▶ my $self = shift;
Subroutine _build__tiles: called CC=1 SCAR=0.0
10 55 [ map [ (undef) x $self->size ], 1..$self->size ];
11 }
12  
13 sub each_cell {
14 226 ▶ my $self = shift;
Subroutine each_cell: called CC=1 SCAR=0.0
Pod undocumented
15 map {
16 226 my $y = $_;
17 869 map [$_, $y], 0..$self->size-1;
18 } 0..$self->size-1;
19 }
20  
21 sub each_tile {
22 92 ▶ my $self = shift;
Subroutine each_tile: called CC=1 SCAR=0.0
Pod undocumented
23 92 map $self->tile($_), $self->tile_cells;
24 }
25  
26 sub tile_cells {
27 130 ▶ my $self = shift;
Subroutine tile_cells: called CC=1 SCAR=0.0
Pod undocumented
28 130 grep $self->tile($_), $self->each_cell;
29 }
30  
31 sub available_cells {
32 41 ▶ my $self = shift;
Subroutine available_cells: called CC=1 SCAR=0.0
Pod undocumented
33 41 grep !$self->tile($_), $self->each_cell;
34 }
35  
36 sub has_available_cells {
37 7 ▶ my $self = shift;
Subroutine has_available_cells: called CC=1 SCAR=0.0
Pod undocumented
38 7 !!scalar $self->available_cells;
39 }
40  
41 sub within_bounds {
42 6033 ▶ my ($self, $cell) = @_;
Subroutine within_bounds: called CC=4 SCAR=13.9
Pod undocumented
43 6033 ▶ $cell->[0] >= 0 and $cell->[0] < $self->size and
Branch: 1 branch
BranchTrueFalseTotal
$cell->[0] >= 0 and $cell->[0] < $self->size and $cell->[1] >= 0 and $cell->[1] < $self->size 5787 246 6033
Condition100%6/6
$cell->[0] >= 0 and $cell->[0] < $self->size and $cell->[1] >= 0
!ll&&!rl&&r
194525787
$cell->[0] >= 0 and $cell->[0] < $self->size
!ll&&!rl&&r
104905839
MC/DC100%3/3
$cell->[0] >= 0 and $cell->[0] < $self->size and $cell->[1] >= 0
$cell->[0] >= 0 $cell->[0] < $self->size $cell->[1] >= 0
Truth table100%4/4
A and B and C
A= $cell->[0] >= 0B= $cell->[0] < $self->sizeC= $cell->[1] >= 0
ABCresult
0XX0
10X0
1100
1111
44 $cell->[1] >= 0 and $cell->[1] < $self->size;
45 }
46  
47 sub tile {
48 5462 ▶ my ($self, $cell) = @_;
Subroutine tile: called CC=2 SCAR=6.9
Pod undocumented
49 5462 ▶ return if !$self->within_bounds($cell);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->within_bounds($cell) 151 5311 5462
50 5311 $self->_tiles->[$cell->[1]][$cell->[0]];
51 }
52  
53 sub clear_tile {
54 162 ▶ my ($self, $cell) = @_;
Subroutine clear_tile: called CC=1 SCAR=0.0
Pod undocumented
55 162 $self->_tiles->[$cell->[1]][$cell->[0]] = undef;
56 }
57  
58 sub set_tile {
59 636 ▶ my ($self, $cell, $tile) = @_;
Subroutine set_tile: called CC=1 SCAR=0.0
Pod undocumented
60 636 $self->_tiles->[$cell->[1]][$cell->[0]] = $tile;
61 }
62  
63 4 1;
« 2048/Input.pm ↑ Summary 2048/Animation.pm »