lib/Games/Bingo/ColumnCollection.pm

filter: Statementstmt 93.0% 80 / 86 Branchbran 85.7% 24 / 28 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 14 / 14 Podpod 100% 6 / 6 totaltotal 89.9% 125 / 139 CC 16 SCAR 14.1
CC
16
Cov
90%
get_column
9.2
divide
4.0
_remove_column
3.0
CRAP 4.1
« lib/Games/Bingo/Card.pm ↑ Summary lib/Games/Bingo.pm »
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
BranchTrueFalseTotal
if @_ 5 727 732
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
BranchTrueFalseTotal
if ($number < $number_of_columns) 1323 147 1470
30 1323 my @s = ();
31 1323 ▶ if ($number == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($number == 0) { } 147 1176 1323
elsif ($number == 8) { } 147 1029 1176
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
BranchTrueFalseTotal
if ($index) { } 1 5036 5037
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
BranchTrueFalseTotal
if ($idx < 0) { } 1 3045 3046
elsif ($idx > scalar @{$self;}) { } 1 3044 3045
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
BranchTrueFalseTotal
unless ($index =~ /^(-)?\d+$/) 1 5255 5256
72 1 carp "no or illegal index specified";
73 1 return undef;
74 }
75  
76 5255 ▶ if ($index < 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($index < 0) { } 1 5254 5255
elsif ($index > scalar @{$self;}) { } 1 5253 5254
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
BranchTrueFalseTotal
if ($auto_splice and $column) 0 5253 5253
Condition33%1/3
$auto_splice and $column
!ll&&!rl&&r
525300
MC/DC0%0/2
$auto_splice and $column
$auto_splice $column
Truth table33%1/3
A and B
A= $auto_spliceB= $column
ABresult
0X0
100
111
87 0 my $length = $column->count_numbers();
88 0 ▶ if ($length < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length < 2) { } 0 0 0
89 0 $do_splice = 1;
90 } else {
91 0 $do_splice = 0;
92 }
93 }
94
95 5253 ▶ if ($do_splice) {
Branch: 1 branch
BranchTrueFalseTotal
if ($do_splice) 3043 2210 5253
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
BranchTrueFalseTotal
if (@!) { } 0 3043 3043
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__
« lib/Games/Bingo/Card.pm ↑ Summary lib/Games/Bingo.pm »