| 1 | package Games::Bingo::ColumnCollection; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 19 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 19 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 19 | ▶ | use integer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 19 | ▶ | use Games::Bingo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 19 | ▶ | use Games::Bingo::Column; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 19 | ▶ | use vars qw(@ISA $VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 19 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 19 | @ISA = qw(Games::Bingo); | |||||||||||||||||||||||||||
| 12 | 19 | $VERSION = '0.18'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 732 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 15 | 732 | my $class = shift; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 732 | my $self = bless [], $class; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 732 | ▶ | push @{$self}, @_ if (@_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 732 | return $self; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 147 | ▶ | sub divide { | ||||||||||||||||||||||||||
|
Subroutine
divide: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 147 | my $self = shift; | |||||||||||||||||||||||||||
| 26 | 147 | my $number_of_columns = shift; | |||||||||||||||||||||||||||
| 27 | 147 | my @numbers = @_; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 147 | ▶ | for (my $number = 0; $number < $number_of_columns; $number++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 1323 | my @s = (); | |||||||||||||||||||||||||||
| 31 | 1323 | ▶ | if ($number == 0) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 32 | 147 | @s = splice(@numbers, 0, 9); | |||||||||||||||||||||||||||
| 33 | } elsif ($number == 8) { | ||||||||||||||||||||||||||||
| 34 | 147 | @s = splice(@numbers, 0, 11); | |||||||||||||||||||||||||||
| 35 | } else { | ||||||||||||||||||||||||||||
| 36 | 1029 | @s = splice(@numbers, 0, 10); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 1323 | my $column = Games::Bingo::Column->new($number, @s); | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1323 | $self->add_column($column); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 5037 | ▶ | sub add_column { | ||||||||||||||||||||||||||
|
Subroutine
add_column: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 5037 | my ($self, $column, $index) = @_; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 5037 | ▶ | if ($index) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 1 | $self->[$index] = $column; | |||||||||||||||||||||||||||
| 49 | } else { | ||||||||||||||||||||||||||||
| 50 | 5036 | push(@{$self}, $column); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 3046 | ▶ | sub _remove_column { | ||||||||||||||||||||||||||
|
Subroutine
_remove_column: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 55 | 3046 | my ($self, $idx) = @_; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 3046 | ▶ | if ($idx < 0 ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 58 | 1 | carp "cannot remove column, index cannot be a negative number ($idx)\n"; | |||||||||||||||||||||||||||
| 59 | 1 | return undef; | |||||||||||||||||||||||||||
| 60 | 3045 | } elsif ($idx > (scalar @{$self})) { | |||||||||||||||||||||||||||
| 61 | 1 | carp "cannot remove column, no column with that index ($idx)\n"; | |||||||||||||||||||||||||||
| 62 | 1 | return undef; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 3044 | splice(@{$self}, $idx, 1); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 5256 | ▶ | sub get_column { | ||||||||||||||||||||||||||
|
Subroutine
get_column: called CC=8 SCAR=22.2
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 5256 | my ($self, $index, $do_splice, $auto_splice) = @_; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 5256 | ▶ | if ($index !~ m/^(-)?\d+$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 1 | carp "no or illegal index specified"; | |||||||||||||||||||||||||||
| 73 | 1 | return undef; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 5255 | ▶ | if ($index < 0 ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 77 | 1 | carp "cannot get column, index cannot be a negative number ($index)\n"; | |||||||||||||||||||||||||||
| 78 | 1 | return undef; | |||||||||||||||||||||||||||
| 79 | 5254 | } elsif ($index > (scalar @{$self})) { | |||||||||||||||||||||||||||
| 80 | 1 | carp "cannot get column, no columns with that index ($index)\n"; | |||||||||||||||||||||||||||
| 81 | 1 | return undef; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 5253 | my $column = $self->[$index]; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 5253 | ▶ | if ($auto_splice and $column) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$auto_splice and $column
MC/DC0%0/2
$auto_splice and $column
$auto_splice
$column
Truth table33%1/3
A and B
A= $auto_spliceB= $column
| |||||||||||||||||||||||||||||
| 87 | 0 | my $length = $column->count_numbers(); | |||||||||||||||||||||||||||
| 88 | 0 | ▶ | if ($length < 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | $do_splice = 1; | |||||||||||||||||||||||||||
| 90 | } else { | ||||||||||||||||||||||||||||
| 91 | 0 | $do_splice = 0; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 5253 | ▶ | if ($do_splice) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 3043 | my $v = $self->_remove_column($index); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | 5253 | return $column; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 3043 | ▶ | sub get_random_column { | ||||||||||||||||||||||||||
|
Subroutine
get_random_column: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||
| 102 | 3043 | my ($self, $do_splice, $auto_splice) = @_; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 3043 | my $index = $self->random(scalar @{$self}); | |||||||||||||||||||||||||||
| 105 | 3043 | my $column; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 3043 | eval { | |||||||||||||||||||||||||||
| 108 | 3043 | $column = $self->get_column($index, $do_splice, $auto_splice); | |||||||||||||||||||||||||||
| 109 | }; | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 3043 | ▶ | if (@!) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | warn "unable to get random column: $@"; | |||||||||||||||||||||||||||
| 113 | 0 | return undef; | |||||||||||||||||||||||||||
| 114 | } else { | ||||||||||||||||||||||||||||
| 115 | 3043 | return $column; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 1 | ▶ | sub count_columns { | ||||||||||||||||||||||||||
|
Subroutine
count_columns: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 120 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 1 | return scalar(@{$self}); | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 19 | 1; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | __END__ | ||||||||||||||||||||||||||||