line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Game::Life::NDim::Dim; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Created on: 2010-01-08 18:43:32 |
4
|
|
|
|
|
|
|
# Create by: Ivan Wills |
5
|
|
|
|
|
|
|
# $Id$ |
6
|
|
|
|
|
|
|
# $Revision$, $HeadURL$, $Date$ |
7
|
|
|
|
|
|
|
# $Revision$, $Source$, $Date$ |
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
53414
|
use Moose; |
|
4
|
|
|
|
|
448627
|
|
|
4
|
|
|
|
|
32
|
|
10
|
4
|
|
|
4
|
|
19313
|
use warnings; |
|
4
|
|
|
|
|
39
|
|
|
4
|
|
|
|
|
118
|
|
11
|
4
|
|
|
4
|
|
911
|
use version; |
|
4
|
|
|
|
|
2411
|
|
|
4
|
|
|
|
|
30
|
|
12
|
4
|
|
|
4
|
|
258
|
use Carp; |
|
4
|
|
|
|
|
29
|
|
|
4
|
|
|
|
|
299
|
|
13
|
4
|
|
|
4
|
|
17
|
use Data::Dumper qw/Dumper/; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
160
|
|
14
|
4
|
|
|
4
|
|
704
|
use English qw/ -no_match_vars /; |
|
4
|
|
|
|
|
15265
|
|
|
4
|
|
|
|
|
35
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use overload |
17
|
2034
|
|
|
2034
|
|
2363
|
'""' => sub { '[' . ( join ',', @{ $_[0]->elements } ) . ']' }, |
|
2034
|
|
|
|
|
67362
|
|
18
|
13450
|
|
|
13450
|
|
453584
|
'@{}' => sub { $_[0]->elements }, |
19
|
0
|
0
|
|
0
|
|
0
|
'==' => sub { for (0..@{$_->[0]}-1) { return 0 if $_[0][$_] != $_[1][$_] } return 1 }, |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
20
|
4
|
|
|
4
|
|
2380
|
'+' => \&sum_list; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
77
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = version->new('0.0.4'); |
23
|
|
|
|
|
|
|
our @EXPORT_OK = qw//; |
24
|
|
|
|
|
|
|
our %EXPORT_TAGS = (); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has elements => ( |
27
|
|
|
|
|
|
|
is => 'rw', |
28
|
|
|
|
|
|
|
isa => 'ArrayRef', |
29
|
|
|
|
|
|
|
required => 1, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has max => ( |
33
|
|
|
|
|
|
|
is => 'rw', |
34
|
|
|
|
|
|
|
isa => 'ArrayRef[Int]', |
35
|
|
|
|
|
|
|
weak_ref => 1, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
around new => sub { |
39
|
|
|
|
|
|
|
my ($new, $class, @args) = @_; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
if ( @args == 1 && ref $args[0] eq 'ARRAY' ) { |
42
|
|
|
|
|
|
|
@args = ( elements => $args[0] ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { |
45
|
|
|
|
|
|
|
my %params = @args; |
46
|
|
|
|
|
|
|
if (!exists $params{elements} && exists $params{max}) { |
47
|
|
|
|
|
|
|
$params{elements} = [ @{ $params{max} } ]; |
48
|
|
|
|
|
|
|
return $new->($class, %params)->zero; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
return $new->($class, @args); |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub increment { |
56
|
1033
|
|
|
1033
|
1
|
1495
|
my ($self, $max) = @_; |
57
|
1033
|
|
|
|
|
1096
|
my $last; |
58
|
|
|
|
|
|
|
|
59
|
1033
|
|
|
|
|
1370
|
for my $i ( reverse 0 .. @{ $max } - 1 ) { |
|
1033
|
|
|
|
|
2230
|
|
60
|
1156
|
50
|
|
|
|
2287
|
die "max[$i] == 0 which is not allowed!" if $max->[$i] == 0; |
61
|
1156
|
100
|
|
|
|
2148
|
if ( $self->[$i] + 1 <= $max->[$i] ) { |
62
|
1028
|
|
|
|
|
1793
|
$self->[$i]++; |
63
|
1028
|
|
|
|
|
1487
|
$last = $i; |
64
|
1028
|
|
|
|
|
1465
|
last; |
65
|
|
|
|
|
|
|
} |
66
|
128
|
|
|
|
|
260
|
$self->[$i] = 0; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
1033
|
100
|
|
|
|
2634
|
return if !defined $last; |
70
|
|
|
|
|
|
|
|
71
|
1028
|
|
|
|
|
3964
|
return $self; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub clone { |
75
|
3
|
|
|
3
|
1
|
5
|
my ($self) = @_; |
76
|
|
|
|
|
|
|
|
77
|
3
|
|
|
|
|
5
|
return $self->new(elements => [ @{ $self } ]); |
|
3
|
|
|
|
|
11
|
|
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub zero { |
81
|
2
|
|
|
2
|
1
|
1950
|
my ($self) = @_; |
82
|
|
|
|
|
|
|
|
83
|
2
|
|
|
|
|
3
|
for my $item (@{ $self }) { |
|
2
|
|
|
|
|
7
|
|
84
|
6
|
|
|
|
|
8
|
$item = 0; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
2
|
|
|
|
|
38
|
return $self; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub sum_list { |
91
|
36
|
|
|
36
|
1
|
62
|
my ($self, $list) = @_; |
92
|
|
|
|
|
|
|
|
93
|
36
|
|
|
|
|
35
|
my @new; |
94
|
36
|
|
|
|
|
38
|
for my $i ( 0 .. @{ $self } - 1 ) { |
|
36
|
|
|
|
|
76
|
|
95
|
96
|
50
|
33
|
|
|
154
|
die Dumper $i, $self, $list if !defined $self->[$i] || !defined $list->[$i]; |
96
|
96
|
|
|
|
|
164
|
$new[$i] = $self->[$i] + $list->[$i]; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
36
|
|
|
|
|
859
|
return __PACKAGE__->new(\@new); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 NAME |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Game::Life::NDim::Dim - The dimension of a board? |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 VERSION |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
This documentation refers to Game::Life::NDim::Dim version 0.0.4. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 SYNOPSIS |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
use Game::Life::NDim::Dim; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# Brief but working code example(s) here showing the most common usage(s) |
120
|
|
|
|
|
|
|
# This section will be as far as many users bother reading, so make it as |
121
|
|
|
|
|
|
|
# educational and exemplary as possible. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 DESCRIPTION |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 C<increment ( )> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 C<clone ( )> |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 C<zero ( )> |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 C<sum_list ( )> |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 INCOMPATIBILITIES |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
There are no known bugs in this module. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Please report problems to Ivan Wills (ivan.wills@gmail.com). |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Patches are welcome. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 AUTHOR |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Ivan Wills - (ivan.wills@gmail.com) |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Copyright (c) 2010 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). |
159
|
|
|
|
|
|
|
All rights reserved. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under |
162
|
|
|
|
|
|
|
the same terms as Perl itself. See L<perlartistic>. This program is |
163
|
|
|
|
|
|
|
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
164
|
|
|
|
|
|
|
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
165
|
|
|
|
|
|
|
PARTICULAR PURPOSE. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=cut |