line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Bingo::ColumnCollection; |
2
|
|
|
|
|
|
|
|
3
|
17
|
|
|
17
|
|
5040
|
use strict; |
|
17
|
|
|
|
|
29
|
|
|
17
|
|
|
|
|
553
|
|
4
|
17
|
|
|
17
|
|
76
|
use warnings; |
|
17
|
|
|
|
|
22
|
|
|
17
|
|
|
|
|
535
|
|
5
|
17
|
|
|
17
|
|
2739
|
use integer; |
|
17
|
|
|
|
|
65
|
|
|
17
|
|
|
|
|
96
|
|
6
|
17
|
|
|
17
|
|
2328
|
use Games::Bingo; |
|
17
|
|
|
|
|
26
|
|
|
17
|
|
|
|
|
410
|
|
7
|
17
|
|
|
17
|
|
2758
|
use Games::Bingo::Column; |
|
17
|
|
|
|
|
40
|
|
|
17
|
|
|
|
|
453
|
|
8
|
17
|
|
|
17
|
|
80
|
use vars qw(@ISA $VERSION); |
|
17
|
|
|
|
|
20
|
|
|
17
|
|
|
|
|
827
|
|
9
|
17
|
|
|
17
|
|
77
|
use Carp; |
|
17
|
|
|
|
|
27
|
|
|
17
|
|
|
|
|
11976
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
@ISA = qw(Games::Bingo); |
12
|
|
|
|
|
|
|
$VERSION = '0.18'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
1002
|
|
|
1002
|
1
|
3348
|
my $class = shift; |
16
|
|
|
|
|
|
|
|
17
|
1002
|
|
|
|
|
1537
|
my $self = bless [], $class; |
18
|
|
|
|
|
|
|
|
19
|
1002
|
100
|
|
|
|
1950
|
push @{$self}, @_ if (@_); |
|
5
|
|
|
|
|
22
|
|
20
|
|
|
|
|
|
|
|
21
|
1002
|
|
|
|
|
1797
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub divide { |
25
|
201
|
|
|
201
|
1
|
239
|
my $self = shift; |
26
|
201
|
|
|
|
|
233
|
my $number_of_columns = shift; |
27
|
201
|
|
|
|
|
1167
|
my @numbers = @_; |
28
|
|
|
|
|
|
|
|
29
|
201
|
|
|
|
|
756
|
for (my $number = 0; $number < $number_of_columns; $number++) { |
30
|
1809
|
|
|
|
|
1785
|
my @s = (); |
31
|
1809
|
100
|
|
|
|
2992
|
if ($number == 0) { |
|
|
100
|
|
|
|
|
|
32
|
201
|
|
|
|
|
524
|
@s = splice(@numbers, 0, 9); |
33
|
|
|
|
|
|
|
} elsif ($number == 8) { |
34
|
201
|
|
|
|
|
413
|
@s = splice(@numbers, 0, 11); |
35
|
|
|
|
|
|
|
} else { |
36
|
1407
|
|
|
|
|
2261
|
@s = splice(@numbers, 0, 10); |
37
|
|
|
|
|
|
|
} |
38
|
1809
|
|
|
|
|
4295
|
my $column = Games::Bingo::Column->new($number, @s); |
39
|
|
|
|
|
|
|
|
40
|
1809
|
|
|
|
|
4232
|
$self->add_column($column); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub add_column { |
45
|
6899
|
|
|
6899
|
1
|
8210
|
my ($self, $column, $index) = @_; |
46
|
|
|
|
|
|
|
|
47
|
6899
|
100
|
|
|
|
8193
|
if ($index) { |
48
|
1
|
|
|
|
|
4
|
$self->[$index] = $column; |
49
|
|
|
|
|
|
|
} else { |
50
|
6898
|
|
|
|
|
5189
|
push(@{$self}, $column); |
|
6898
|
|
|
|
|
18110
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _remove_column { |
55
|
4180
|
|
|
4180
|
|
4638
|
my ($self, $idx) = @_; |
56
|
|
|
|
|
|
|
|
57
|
4180
|
100
|
|
|
|
5043
|
if ($idx < 0 ) { |
|
|
100
|
|
|
|
|
|
58
|
1
|
|
|
|
|
181
|
carp "cannot remove column, index cannot be a negative number ($idx)\n"; |
59
|
1
|
|
|
|
|
119
|
return undef; |
60
|
4179
|
|
|
|
|
8027
|
} elsif ($idx > (scalar @{$self})) { |
61
|
1
|
|
|
|
|
80
|
carp "cannot remove column, no column with that index ($idx)\n"; |
62
|
1
|
|
|
|
|
76
|
return undef; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
4178
|
|
|
|
|
3615
|
splice(@{$self}, $idx, 1); |
|
4178
|
|
|
|
|
7143
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub get_column { |
69
|
7200
|
|
|
7200
|
1
|
13094
|
my ($self, $index, $do_splice, $auto_splice) = @_; |
70
|
|
|
|
|
|
|
|
71
|
7200
|
100
|
|
|
|
45941
|
if ($index !~ m/^(-)?\d+$/) { |
72
|
1
|
|
|
|
|
240
|
carp "no or illegal index specified"; |
73
|
1
|
|
|
|
|
124
|
return undef; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
7199
|
100
|
|
|
|
10174
|
if ($index < 0 ) { |
|
|
100
|
|
|
|
|
|
77
|
1
|
|
|
|
|
124
|
carp "cannot get column, index cannot be a negative number ($index)\n"; |
78
|
1
|
|
|
|
|
138
|
return undef; |
79
|
7198
|
|
|
|
|
13085
|
} elsif ($index > (scalar @{$self})) { |
80
|
1
|
|
|
|
|
127
|
carp "cannot get column, no columns with that index ($index)\n"; |
81
|
1
|
|
|
|
|
121
|
return undef; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
7197
|
|
|
|
|
8217
|
my $column = $self->[$index]; |
85
|
|
|
|
|
|
|
|
86
|
7197
|
50
|
33
|
|
|
12110
|
if ($auto_splice and $column) { |
87
|
0
|
|
|
|
|
0
|
my $length = $column->count_numbers(); |
88
|
0
|
0
|
|
|
|
0
|
if ($length < 2) { |
89
|
0
|
|
|
|
|
0
|
$do_splice = 1; |
90
|
|
|
|
|
|
|
} else { |
91
|
0
|
|
|
|
|
0
|
$do_splice = 0; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
7197
|
100
|
|
|
|
9607
|
if ($do_splice) { |
96
|
4177
|
|
|
|
|
5966
|
my $v = $self->_remove_column($index); |
97
|
|
|
|
|
|
|
} |
98
|
7197
|
|
|
|
|
11661
|
return $column; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub get_random_column { |
102
|
4177
|
|
|
4177
|
1
|
4631
|
my ($self, $do_splice, $auto_splice) = @_; |
103
|
|
|
|
|
|
|
|
104
|
4177
|
|
|
|
|
3344
|
my $index = $self->random(scalar @{$self}); |
|
4177
|
|
|
|
|
8410
|
|
105
|
4177
|
|
|
|
|
4031
|
my $column; |
106
|
|
|
|
|
|
|
|
107
|
4177
|
|
|
|
|
3774
|
eval { |
108
|
4177
|
|
|
|
|
5649
|
$column = $self->get_column($index, $do_splice, $auto_splice); |
109
|
|
|
|
|
|
|
}; |
110
|
|
|
|
|
|
|
|
111
|
4177
|
50
|
|
|
|
5761
|
if (@!) { |
112
|
0
|
|
|
|
|
0
|
warn "unable to get random column: $@"; |
113
|
0
|
|
|
|
|
0
|
return undef; |
114
|
|
|
|
|
|
|
} else { |
115
|
4177
|
|
|
|
|
7993
|
return $column; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub count_columns { |
120
|
1
|
|
|
1
|
1
|
4
|
my $self = shift; |
121
|
|
|
|
|
|
|
|
122
|
1
|
|
|
|
|
2
|
return scalar(@{$self}); |
|
1
|
|
|
|
|
6
|
|
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
__END__ |