blib/lib/Game/Life/Faster.pm

filter: Statementstmt 97.7% 212 / 217 Branchbran 77.5% 62 / 80 Conditioncond 56.6% 30 / 53 MC/DCmcdc 27.5% 8 / 29 Subroutinesub 97.3% 36 / 37 Podpod 100% 22 / 22 totaltotal 84.4% 370 / 438 CC 76 SCAR 22.9
CC
76
Cov
87%
set_point_state
30.0
get_text_grid
10.2
get_used_grid_coord
9.4
CRAP 9.9
↑ Summary Build »
1 package Game::Life::Faster;
2  
3 2 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use List::Util qw{ max min };
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our $VERSION = '0.007_01';
12  
13 2 ▶use constant ARRAY_REF => ref [];
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use constant DEFAULT_BREED => [ 3 ];
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use constant DEFAULT_LIVE => [ 2, 3 ];
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use constant DEFAULT_SIZE => 100;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 2 ▶use constant NEW_LINE_RE => qr< \n >smx;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use constant NON_NEGATIVE_INTEGER_RE => qr< \A [0-9]+ \z >smx;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use constant POSITIVE_INTEGER_RE => qr< \A [1-9][0-9]* \z >smx;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 2 ▶use constant TOGGLE_STATE => do { bless \my $x, 'Toggle_State' };
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶use constant TOGGLE_STATE_REF => ref TOGGLE_STATE;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 sub new {
27 3 ▶ my ( $class, $size, $breed, $live ) = @_;
Subroutine new: called CC=8 SCAR=21.3
Pod documented
28  
29 3 my $self;
30  
31 3 my $ref = ref $size;
32 3 ▶ if ( ARRAY_REF eq $ref ) {
Branch: 2 branches
BranchTrueFalseTotal
if ('ARRAY' eq $ref) { } 1 2 3
elsif (not $ref) { } 2 0 2
33 1 $self->{size_x} = $size->[1];
34 1 $self->{size_y} = $size->[0];
35 } elsif ( ! $ref ) {
36 2 $self->{size_x} = $self->{size_y} = $size;
37 } else {
38 0 croak "Argument may not be $size";
39 }
40 3 ▶ $self->{size_x} ||= DEFAULT_SIZE;
Condition100%2/2
$self->{"size_x"} ||= 100
l!l
21
MC/DC100%1/1
$self->{"size_x"} ||= 100
$self->{"size_x"}
Truth table100%2/2
A
A= $self->{"size_x"}
Aresult
11
00
41 3 ▶ $self->{size_y} ||= DEFAULT_SIZE;
Condition100%2/2
$self->{"size_y"} ||= 100
l!l
21
MC/DC100%1/1
$self->{"size_y"} ||= 100
$self->{"size_y"}
Truth table100%2/2
A
A= $self->{"size_y"}
Aresult
11
00
42 $self->{size_x} =~ POSITIVE_INTEGER_RE
43 3 ▶ and $self->{size_y} =~ POSITIVE_INTEGER_RE
Branch: 1 branch
BranchTrueFalseTotal
$self->{"size_x"} =~ / \A [1-9][0-9]* \z /msx and $self->{"size_y"} =~ / \A [1-9][0-9]* \z /msx or croak("Sizes must be positive integers") 0 3 3
Condition33%1/3
$self->{"size_x"} =~ / \A [1-9][0-9]* \z /msx and $self->{"size_y"} =~ / \A [1-9][0-9]* \z /msx
!ll&&!rl&&r
003
MC/DC0%0/2
$self->{"size_x"} =~ / \A [1-9][0-9]* \z /msx and $self->{"size_y"} =~ / \A [1-9][0-9]* \z /msx
$self->{"size_x"} =~ / \A [1-9][0-9]* \z /msx $self->{"size_y"} =~ / \A [1-9][0-9]* \z /msx
Truth table33%1/3
A and B
A= $self->{"size_x"} =~ / \A [1-9][0-9]* \z /msxB= $self->{"size_y"} =~ / \A [1-9][0-9]* \z /msx
ABresult
0X0
100
111
44 or croak 'Sizes must be positive integers';
45 3 $self->{max_x} = $self->{size_x} - 1;
46 3 $self->{max_y} = $self->{size_y} - 1;
47  
48 3 ▶ bless $self, ref $class || $class;
Condition66%2/3
ref $class || $class
l!l&&r!l&&!r
120
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table66%2/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
49 3 $self->set_rules( $breed, $live );
50  
51 3 $self->clear();
52  
53 3 return $self;
54 }
55  
56 sub clear {
57 4 ▶ my ( $self ) = @_;
Subroutine clear: called CC=1 SCAR=0.0
Pod documented
58 4 delete $self->{grid};
59 4 delete $self->{changed};
60 4 $self->{living_x} = [];
61 4 $self->{living_y} = [];
62 4 $self->{change_count} = 0;
63 4 return $self;
64 }
65  
66 sub get_active_grid_coord {
67 2 ▶ my ( $self ) = @_;
Subroutine get_active_grid_coord: called CC=8 SCAR=20.8
Pod documented
68 my ( $min_x, $max_x, $min_y, $max_y ) = ( $self->{size_x}, 0,
69 2 $self->{size_y}, 0 );
70 2 foreach my $ix ( keys %{ $self->{changed} } ) {
71 10 ▶ $min_x = $ix if $ix < $min_x;
Branch: 1 branch
BranchTrueFalseTotal
if $ix < $min_x 2 8 10
72 10 ▶ $max_x = $ix if $ix > $max_x;
Branch: 1 branch
BranchTrueFalseTotal
if $ix > $max_x 4 6 10
73 10 foreach my $iy ( keys %{ $self->{changed}{$ix} } ) {
74 40 ▶ $min_y = $iy if $iy < $min_y;
Branch: 1 branch
BranchTrueFalseTotal
if $iy < $min_y 4 36 40
75 40 ▶ $max_y = $iy if $iy > $max_y;
Branch: 1 branch
BranchTrueFalseTotal
if $iy > $max_y 4 36 40
76 }
77 }
78 2 ▶ $max_x < $min_x
Branch: 1 branch
BranchTrueFalseTotal
$max_x < $min_x and croak("No active cells") 0 2 2
79 and croak 'No active cells';
80 2 return [ $min_x, $max_x, $min_y, $max_y ];
81 }
82  
83 sub get_breeding_rules {
84 1 ▶ my ( $self ) = @_;
Subroutine get_breeding_rules: called CC=1 SCAR=0.0
Pod documented
85 1 return $self->get_rule( 'breed' );
86 }
87  
88 sub get_grid {
89 1 ▶ my ( $self, $coord ) = @_;
Subroutine get_grid: called CC=8 SCAR=21.0
Pod documented
90 1 ▶ $coord ||= $self->get_grid_coord();
Condition33%1/3
$coord ||= $self->get_grid_coord
l!l&&r!l&&!r
010
MC/DC0%0/2
$coord ||= $self->get_grid_coord
$coord $self->get_grid_coord
Truth table33%1/3
A ||= B
A= $coordB= $self->get_grid_coord
ABresult
1X1
011
000
91 $self->{grid}
92 1 ▶ or return [ ( [ ( 0 ) x ( $coord->[3] - $coord->[2] + 1 ) ] ) x
Branch: 1 branch
BranchTrueFalseTotal
$self->{"grid"} or return [([(0) x ($coord->[3] - $coord->[2] + 1)]) x ($coord->[1] - $coord->[0] + 1)] 0 1 1
93 ( $coord->[1] - $coord->[0] + 1 ) ];
94 1 my @rslt;
95 1 foreach my $x ( $coord->[0] .. $coord->[1] ) {
96 10 ▶ if ( $self->{grid}{$x} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'grid'}{$x}) { } 7 3 10
97 7 push @rslt, [];
98 7 foreach my $y ( $coord->[2] .. $coord->[3] ) {
99 70 ▶ push @{ $rslt[-1] }, $self->{grid}{$x}{$y} ?
Branch: 2 branches
BranchTrueFalseTotal
$self->{'grid'}{$x}{$y} ? : 36 34 70
$self->{'grid'}{$x}{$y}[0] ? : 5 31 36
100 70 $self->{grid}{$x}{$y}[0] ? 1 : 0 : 0;
101 }
102 } else {
103 3 push @rslt, [ ( 0 ) x ( $coord->[3] - $coord->[2] + 1 ) ];
104 }
105 }
106 1 return \@rslt;
107 }
108  
109 sub get_grid_coord {
110 9 ▶ my ( $self ) = @_;
Subroutine get_grid_coord: called CC=1 SCAR=0.0
Pod documented
111 9 return [ 0, $self->{max_x}, 0, $self->{max_y} ];
112 }
113  
114 sub get_living_rules {
115 1 ▶ my ( $self ) = @_;
Subroutine get_living_rules: called CC=1 SCAR=0.0
Pod documented
116 1 return $self->get_rule( 'live' );
117 }
118  
119 sub get_text_grid {
120 10 ▶ my ( $self, $living, $dead, $coord ) = @_;
Subroutine get_text_grid: called CC=10 SCAR=23.2
Pod documented
121 10 ▶ $living ||= 'X';
Condition50%1/2
$living ||= "X"
l!l
010
MC/DC0%0/1
$living ||= "X"
$living
Truth table50%1/2
A
A= $living
Aresult
11
00
122 10 ▶ $dead ||= '.';
Condition50%1/2
$dead ||= "."
l!l
010
MC/DC0%0/1
$dead ||= "."
$dead
Truth table50%1/2
A
A= $dead
Aresult
11
00
123 10 ▶ $coord ||= $self->get_grid_coord();
Condition66%2/3
$coord ||= $self->get_grid_coord
l!l&&r!l&&!r
280
MC/DC0%0/2
$coord ||= $self->get_grid_coord
$coord $self->get_grid_coord
Truth table66%2/3
A ||= B
A= $coordB= $self->get_grid_coord
ABresult
1X1
011
000
124 10 my @rslt;
125 10 ▶ if ( $self->{grid} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'grid'}) { } 7 3 10
126 7 foreach my $x ( $coord->[0] .. $coord->[1] ) {
127 58 ▶ if ( $self->{grid}{$x} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'grid'}{$x}) { } 37 21 58
128 push @rslt, join '', map {
129 37 ▶ ( $self->{grid}{$x}{$_} && $self->{grid}{$x}{$_}[0]) ?
Branch: 1 branch
BranchTrueFalseTotal
$self->{'grid'}{$x}{$_} && $self->{'grid'}{$x}{$_}[0] ? : 47 277 324
Condition100%3/3
$self->{"grid"}{$x}{$_} and $self->{"grid"}{$x}{$_}[0]
!ll&&!rl&&r
11716047
MC/DC100%2/2
$self->{"grid"}{$x}{$_} and $self->{"grid"}{$x}{$_}[0]
$self->{"grid"}{$x}{$_} $self->{"grid"}{$x}{$_}[0]
Truth table100%3/3
A and B
A= $self->{"grid"}{$x}{$_}B= $self->{"grid"}{$x}{$_}[0]
ABresult
0X0
100
111
130 $living : $dead
131 } $coord->[2] .. $coord->[3];
132 } else {
133 21 push @rslt, $dead x ( $coord->[3] - $coord->[2] + 1 );
134 }
135 }
136 } else {
137 3 @rslt = ( $dead x ( $coord->[3] - $coord->[2] + 1 ) ) x (
138 $coord->[1] - $coord->[0] + 1 );
139 }
140 10 ▶ return wantarray ? @rslt : join '', map { "$_\n" } @rslt;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 10 10
141 }
142  
143 sub get_active_text_grid {
144 1 ▶ my ( $self, $living, $dead ) = @_;
Subroutine get_active_text_grid: called CC=1 SCAR=0.0
Pod documented
145 1 return $self->get_text_grid( $living, $dead,
146 $self->get_active_grid_coord() );
147 }
148  
149 sub get_used_text_grid {
150 1 ▶ my ( $self, $living, $dead ) = @_;
Subroutine get_used_text_grid: called CC=1 SCAR=0.0
Pod documented
151 1 return $self->get_text_grid( $living, $dead,
152 $self->get_used_grid_coord() );
153 }
154  
155 sub get_used_grid {
156 0 ▶ my ( $self ) = @_;
Subroutine get_used_grid: not called CC=1 SCAR=6.9
Pod documented
157 0 return $self->get_grid( $self->get_used_grid_coord() );
158 }
159  
160 sub get_used_grid_coord {
161 2 ▶ my ( $self ) = @_;
Subroutine get_used_grid_coord: called CC=9 SCAR=22.4
Pod documented
162 2 my $min_x = $self->{size_x};
163 2 ▶ for ( $min_x = 0; $min_x < $self->{size_x}; $min_x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($min_x < $self->{"size_x"}) 8 0 8
164 8 ▶ $self->{living_x}[$min_x]
Branch: 1 branch
BranchTrueFalseTotal
$self->{"living_x"}[$min_x] or next 6 2 8
165 or next;
166 2 my ( $max_x, $min_y, $max_y );
167 2 ▶ for ( $max_x = $self->{size_x}; $max_x >= $min_x; ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max_x >= $min_x) 10 0 10
168 10 ▶ $self->{living_x}[--$max_x]
Branch: 1 branch
BranchTrueFalseTotal
$self->{"living_x"}[--$max_x] and last 2 8 10
169 and last;
170 }
171 2 ▶ for ( $min_y = 0; $min_y < $self->{size_y}; $min_y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($min_y < $self->{"size_y"}) 6 0 6
172 6 ▶ $self->{living_y}[$min_y]
Branch: 1 branch
BranchTrueFalseTotal
$self->{"living_y"}[$min_y] and last 2 4 6
173 and last;
174 }
175 2 ▶ for ( $max_y = $self->{size_y}; $max_y >= $min_y; ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max_y >= $min_y) 12 0 12
176 12 ▶ $self->{living_y}[--$max_y]
Branch: 1 branch
BranchTrueFalseTotal
$self->{"living_y"}[--$max_y] and last 2 10 12
177 and last;
178 }
179 2 return [ $min_x, $max_x, $min_y, $max_y ];
180 }
181 0 croak 'No occupied cells';
182 }
183  
184 sub place_points {
185 1 ▶ my ( $self, $x, $y, $array ) = @_;
Subroutine place_points: called CC=3 SCAR=11.0
Pod documented
186 1 my $ix = $x;
187 1 foreach my $row ( @{ $array } ) {
188 1 my $iy = $y;
189 1 foreach my $state ( @{ $row } ) {
190 3 $self->set_point_state( $ix, $iy, $state );
191 3 $iy++;
192 }
193 1 $ix++;
194 }
195 1 return;
196 }
197  
198 sub place_text_points {
199 3 ▶ my ( $self, $x, $y, $living, @array ) = @_;
Subroutine place_text_points: called CC=5 SCAR=16.1
Pod documented
200 3 my $ix = $x;
201 3 ▶ 1 == @array
Branch: 1 branch
BranchTrueFalseTotal
1 == @array and $array[0] =~ / \n /msx and @array = split(qr" @{[qr/ \n /msx];} "msx, $array[0], 0) 2 1 3
Condition66%2/3
1 == @array and $array[0] =~ / \n /msx
!ll&&!rl&&r
102
MC/DC50%1/2
1 == @array and $array[0] =~ / \n /msx
1 == @array $array[0] =~ / \n /msx
Truth table66%2/3
A and B
A= 1 == @arrayB= $array[0] =~ / \n /msx
ABresult
0X0
100
111
202 and $array[0] =~ NEW_LINE_RE
203 2 and @array = split qr< @{[ NEW_LINE_RE ]} >smx, $array[0];
204 3 foreach my $line ( @array ) {
205 7 my $iy = $y;
206 7 foreach my $state ( map { $living eq $_ } split qr<>, $line ) {
207 17 $self->set_point_state( $ix, $iy, $state );
208 17 $iy++;
209 }
210 7 $ix++;
211 }
212 3 return;
213 }
214  
215 sub process {
216 4 ▶ my ( $self, $steps ) = @_;
Subroutine process: called CC=9 SCAR=22.0
Pod documented
217 4 ▶ $steps ||= 1;
Condition100%2/2
$steps ||= 1
l!l
22
MC/DC100%1/1
$steps ||= 1
$steps
Truth table100%2/2
A
A= $steps
Aresult
11
00
218  
219 4 foreach ( 1 .. $steps ) {
220  
221 13 my $changed = delete $self->{changed};
222 13 $self->{change_count} = 0;
223  
224 13 foreach my $x ( keys %{ $changed } ) {
225 60 foreach my $y ( keys %{ $changed->{$x} } ) {
226 253 my $cell = $self->{grid}{$x}{$y};
227 2 ▶ no warnings qw{ uninitialized };
Subroutine BEGIN: called CC=1 SCAR=0.0
228 253 ▶ if ( $cell->[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cell->[0]) { } 66 187 253
229 66 ▶ $self->{live}[ $changed->{$x}{$y} ]
Branch: 1 branch
BranchTrueFalseTotal
$self->{"live"}[$changed->{$x}{$y}] or $self->unset_point($x, $y) 24 42 66
230 or $self->unset_point( $x, $y );
231 } else {
232 187 ▶ $self->{breed}[ $changed->{$x}{$y} ]
Branch: 1 branch
BranchTrueFalseTotal
$self->{"breed"}[$changed->{$x}{$y}] and $self->set_point($x, $y) 24 163 187
233 and $self->set_point( $x, $y );
234 }
235 }
236 }
237  
238 $self->{change_count}
239 13 ▶ or last;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"change_count"} or last 2 11 13
240 }
241 4 return $self->{change_count};
242 }
243  
244 sub set_point {
245 26 ▶ my ( $self, $x, $y ) = @_;
Subroutine set_point: called CC=1 SCAR=0.0
Pod documented
246 26 return $self->set_point_state( $x, $y, 1 );
247 }
248  
249 sub set_point_state {
250 74 ▶ my ( $self, $x, $y, $state ) = @_;
Subroutine set_point_state: called CC=18 SCAR=34.0
Pod documented
251  
252 74 ▶ defined $x
Branch: 1 branch
BranchTrueFalseTotal
defined $x and defined $y and $x =~ / \A [0-9]+ \z /msx and $y =~ / \A [0-9]+ \z /msx or croak("Coordinates must be non-negative integers") 0 74 74
Condition33%3/9
defined $x and defined $y and $x =~ / \A [0-9]+ \z /msx and $y =~ / \A [0-9]+ \z /msx
!ll&&!rl&&r
0074
defined $x and defined $y and $x =~ / \A [0-9]+ \z /msx
!ll&&!rl&&r
0074
defined $x and defined $y
!ll&&!rl&&r
0074
MC/DC0%0/4
defined $x and defined $y and $x =~ / \A [0-9]+ \z /msx and $y =~ / \A [0-9]+ \z /msx
defined $x defined $y $x =~ / \A [0-9]+ \z /msx $y =~ / \A [0-9]+ \z /msx
Truth table20%1/5
A and B and C and D
A= defined $xB= defined $yC= $x =~ / \A [0-9]+ \z /msxD= $y =~ / \A [0-9]+ \z /msx
ABCDresult
0XXX0
10XX0
110X0
11100
11111
253 and defined $y
254 and $x =~ NON_NEGATIVE_INTEGER_RE
255 and $y =~ NON_NEGATIVE_INTEGER_RE
256 or croak 'Coordinates must be non-negative integers';
257 74 ▶ defined $state
Branch: 1 branch
BranchTrueFalseTotal
defined $state or return $state 0 74 74
258 or return $state;
259  
260 74 ▶ if ( $x >= 0 && $x < $self->{size_x} &&
Branch: 2 branches
BranchTrueFalseTotal
if ($x >= 0 and $x < $self->{'size_x'} and $y >= 0 and $y < $self->{'size_y'}) { } 74 0 74
elsif ($state) { } 0 0 0
Condition33%3/9
$x >= 0 and $x < $self->{"size_x"} and $y >= 0 and $y < $self->{"size_y"}
!ll&&!rl&&r
0074
$x >= 0 and $x < $self->{"size_x"} and $y >= 0
!ll&&!rl&&r
0074
$x >= 0 and $x < $self->{"size_x"}
!ll&&!rl&&r
0074
MC/DC0%0/4
$x >= 0 and $x < $self->{"size_x"} and $y >= 0 and $y < $self->{"size_y"}
$x >= 0 $x < $self->{"size_x"} $y >= 0 $y < $self->{"size_y"}
Truth table20%1/5
A and B and C and D
A= $x >= 0B= $x < $self->{"size_x"}C= $y >= 0D= $y < $self->{"size_y"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
261 $y >= 0 && $y < $self->{size_y}
262 ) {
263 # We're on-grid.
264  
265 # This autovivifies, but we're going to assign it anyway, so ...
266 74 ▶ my $prev_state = $self->{grid}{$x}{$y}[0] || 0;
Condition100%2/2
$self->{'grid'}{$x}{$y}[0] || 0
l!l
2747
MC/DC100%1/1
$self->{'grid'}{$x}{$y}[0] || 0
$self->{'grid'}{$x}{$y}[0]
Truth table100%2/2
A
A= $self->{'grid'}{$x}{$y}[0]
Aresult
11
00
267 74 ▶ $state = TOGGLE_STATE_REF eq ref $state ? 1 - $prev_state :
Branch: 2 branches
BranchTrueFalseTotal
'Toggle_State' eq ref $state ? : 2 72 74
$state ? : 42 30 72
268 $state ? 1 : 0;
269  
270 74 $self->{grid}{$x}{$y}[0] = $state;
271 74 ▶ $self->{grid}{$x}{$y}[1] ||= 0;
Condition100%2/2
$self->{"grid"}{$x}{$y}[1] ||= 0
l!l
6311
MC/DC100%1/1
$self->{"grid"}{$x}{$y}[1] ||= 0
$self->{"grid"}{$x}{$y}[1]
Truth table100%2/2
A
A= $self->{"grid"}{$x}{$y}[1]
Aresult
11
00
272 74 ▶ my $delta = $state - $prev_state
Branch: 1 branch
BranchTrueFalseTotal
my $delta = $state - $prev_state or return $state 6 68 74
273 or return $state;
274 68 $self->{living_x}[$x] += $delta;
275 68 $self->{living_y}[$y] += $delta;
276  
277 68 $self->{change_count}++;
278  
279 68 foreach my $ix ( max( 0, $x - 1 ) .. min( $self->{max_x}, $x + 1 ) ) {
280 197 foreach my $iy ( max( 0, $y - 1 ) .. min( $self->{max_y}, $y + 1 )
281 ) {
282 $self->{changed}{$ix}{$iy} =
283 563 $self->{grid}{$ix}{$iy}[1] += $delta;
284 }
285 }
286  
287 # A cell is not its own neighbor, but the above nested loops
288 # assumed that it was. We fix that here, rather than skip it
289 # inside the loops.
290 $self->{changed}{$x}{$y} =
291 68 $self->{grid}{$x}{$y}[1] -= $delta;
292  
293 } elsif ( $state ) {
294 0 croak 'Attempt to place living cell outside grid';
295 }
296  
297 68 return $state;
298 }
299  
300 {
301 2 my %dflt = (
302 breed => DEFAULT_BREED,
303 live => DEFAULT_LIVE,
304 );
305  
306 sub get_rule {
307 2 ▶ my ( $self, $kind ) = @_;
Subroutine get_rule: called CC=2 SCAR=7.0
Pod documented
308 2 ▶ $dflt{$kind}
Branch: 1 branch
BranchTrueFalseTotal
$dflt{$kind} or croak("'${kind}' is not a valid rule kind") 0 2 2
309 or croak "'$kind' is not a valid rule kind";
310 2 return( grep { $self->{$kind}[$_] } 0 .. $#{ $self->{$kind} } );
311 }
312  
313 sub set_rule {
314 6 ▶ my ( $self, $kind, $rule ) = @_;
Subroutine set_rule: called CC=6 SCAR=19.0
Pod documented
315 6 ▶ $dflt{$kind}
Branch: 1 branch
BranchTrueFalseTotal
$dflt{$kind} or croak("'${kind}' is not a valid rule name") 0 6 6
316 or croak "'$kind' is not a valid rule name";
317 6 ▶ $rule ||= $dflt{$kind};
Condition33%1/3
$rule ||= $dflt{$kind}
l!l&&r!l&&!r
060
MC/DC0%0/2
$rule ||= $dflt{$kind}
$rule $dflt{$kind}
Truth table33%1/3
A ||= B
A= $ruleB= $dflt{$kind}
ABresult
1X1
011
000
318 6 ▶ ARRAY_REF eq ref $rule
Branch: 1 branch
BranchTrueFalseTotal
"ARRAY" eq ref $rule or croak(ucfirst $kind . ' rule must be an array reference') 0 6 6
319 or croak "\u$kind rule must be an array reference";
320 6 $self->{$kind} = [];
321 6 foreach ( @{ $rule } ) {
322 9 ▶ $_ =~ NON_NEGATIVE_INTEGER_RE
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ / \A [0-9]+ \z /msx or croak(ucfirst $kind . ' rule must be a reference to an array of non-negative integers') 0 9 9
323 or croak "\u$kind rule must be a reference to an array of non-negative integers";
324 9 $self->{$kind}[$_] = 1;
325 }
326 6 return;
327 }
328 }
329  
330 2 sub set_rules {
331 3 ▶ my ( $self, $breed, $live ) = @_;
Subroutine set_rules: called CC=1 SCAR=0.0
Pod documented
332 3 $self->set_rule( breed => $breed );
333 3 $self->set_rule( live => $live );
334 3 return;
335 }
336  
337 sub toggle_point {
338 2 ▶ my ( $self, $x, $y ) = @_;
Subroutine toggle_point: called CC=1 SCAR=0.0
Pod documented
339 2 return $self->set_point_state( $x, $y, TOGGLE_STATE );
340 }
341  
342 sub unset_point {
343 26 ▶ my ( $self, $x, $y ) = @_;
Subroutine unset_point: called CC=1 SCAR=0.0
Pod documented
344 26 return $self->set_point_state( $x, $y, 0 );
345 }
346  
347 2 1;
348  
349 __END__
↑ Summary Build »