blib/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 SCAR 27.9
CC
16
Cov
90%
get_column
9.2
divide
4.0
_remove_column
3.0
CRAP 16.3
« blib/lib/Games/Bingo/Card.pm ↑ Summary blib/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.17';
13  
14 sub new {
15 432 ▶ my $class = shift;
Subroutine new: called CC=2 SCAR=6.9
Pod documented
16  
17 432 my $self = bless [], $class;
18
19 432 ▶ push @{$self}, @_ if (@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 5 427 432
20  
21 432 return $self;
22 }
23  
24 sub divide {
25 87 ▶ my $self = shift;
Subroutine divide: called CC=4 SCAR=13.9
Pod documented
26 87 my $number_of_columns = shift;
27 87 my @numbers = @_;
28  
29 87 ▶ for (my $number = 0; $number < $number_of_columns; $number++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($number < $number_of_columns) 783 87 870
30 783 my @s = ();
31 783 ▶ if ($number == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($number == 0) { } 87 696 783
elsif ($number == 8) { } 87 609 696
32 87 @s = splice(@numbers, 0, 9);
33 } elsif ($number == 8) {
34 87 @s = splice(@numbers, 0, 11);
35 } else {
36 609 @s = splice(@numbers, 0, 10);
37 }
38 783 my $column = Games::Bingo::Column->new($number, @s);
39  
40 783 $self->add_column($column);
41 }
42 }
43  
44 sub add_column {
45 2973 ▶ my ($self, $column, $index) = @_;
Subroutine add_column: called CC=2 SCAR=6.9
Pod documented
46
47 2973 ▶ if ($index) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index) { } 1 2972 2973
48 1 $self->[$index] = $column;
49 } else {
50 2972 push(@{$self}, $column);
51 }
52 }
53  
54 sub _remove_column {
55 1786 ▶ my ($self, $idx) = @_;
Subroutine _remove_column: called CC=3 SCAR=11.0
56  
57 1786 ▶ if ($idx < 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($idx < 0) { } 1 1785 1786
elsif ($idx > scalar @{$self;}) { } 1 1784 1785
58 1 carp "cannot remove column, index cannot be a negative number ($idx)\n";
59 1 return undef;
60 1785 } elsif ($idx > (scalar @{$self})) {
61 1 carp "cannot remove column, no column with that index ($idx)\n";
62 1 return undef;
63 }
64  
65 1784 splice(@{$self}, $idx, 1);
66 }
67  
68 sub get_column {
69 3096 ▶ my ($self, $index, $do_splice, $auto_splice) = @_;
Subroutine get_column: called CC=8 SCAR=22.2
Pod documented
70  
71 3096 ▶ if ($index !~ m/^(-)?\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($index =~ /^(-)?\d+$/) 1 3095 3096
72 1 carp "no or illegal index specified";
73 1 return undef;
74 }
75  
76 3095 ▶ if ($index < 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($index < 0) { } 1 3094 3095
elsif ($index > scalar @{$self;}) { } 1 3093 3094
77 1 carp "cannot get column, index cannot be a negative number ($index)\n";
78 1 return undef;
79 3094 } elsif ($index > (scalar @{$self})) {
80 1 carp "cannot get column, no columns with that index ($index)\n";
81 1 return undef;
82 }
83
84 3093 my $column = $self->[$index];
85
86 3093 ▶ if ($auto_splice and $column) {
Branch: 1 branch
BranchTrueFalseTotal
if ($auto_splice and $column) 0 3093 3093
Condition33%1/3
$auto_splice and $column
!ll&&!rl&&r
309300
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 3093 ▶ if ($do_splice) {
Branch: 1 branch
BranchTrueFalseTotal
if ($do_splice) 1783 1310 3093
96 1783 my $v = $self->_remove_column($index);
97 }
98 3093 return $column;
99 }
100  
101 sub get_random_column {
102 1783 ▶ my ($self, $do_splice, $auto_splice) = @_;
Subroutine get_random_column: called CC=2 SCAR=7.2
Pod documented
103
104 1783 my $index = $self->random(scalar @{$self});
105 1783 my $column;
106
107 1783 eval {
108 1783 $column = $self->get_column($index, $do_splice, $auto_splice);
109 };
110
111 1783 ▶ if (@!) {
Branch: 1 branch
BranchTrueFalseTotal
if (@!) { } 0 1783 1783
112 0 warn "unable to get random column: $@";
113 0 return undef;
114 } else {
115 1783 return $column;
116 }
117 }
118  
119 sub count_columns {
120 1 ▶ my $self = shift;
Subroutine count_columns: called CC=1 SCAR=0.0
Pod documented
121
122 1 return scalar(@{$self});
123 }
124  
125 19 1;
126  
127 __END__
« blib/lib/Games/Bingo/Card.pm ↑ Summary blib/lib/Games/Bingo.pm »