blib/lib/Games/Bingo.pm

filter: Statementstmt 100% 76 / 76 Branchbran 100% 10 / 10 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 15 / 15 Podpod 100% 8 / 8 totaltotal 100% 112 / 112 SCAR 23.0
CC
10
Cov
100%
pulled
4.0
_all_pulled
4.0
new
2.0
CRAP 10.0
« blib/lib/Games/Bingo/ColumnCollection.pm ↑ Summary Build »
1 package Games::Bingo;
2  
3 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 36 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 36 ▶use POSIX qw(floor);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 36 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 36 ▶use Games::Bingo::Constants qw(NUMBER_OF_NUMBERS);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 36 $VERSION = '0.17';
11  
12 sub new {
13 100 ▶ my $class = shift;
Subroutine new: called CC=2 SCAR=6.9
Pod documented
14 100 ▶ my $ceiling = shift || NUMBER_OF_NUMBERS;
Condition100%2/2
shift() || 90
l!l
298
MC/DC100%1/1
shift() || 90
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
15
16 100 my $self = bless {
17 _numbers => [],
18 _pulled => [[],[],[],[],[],[],[],[],[],],
19 game => 1,
20 }, $class;
21  
22 100 my @ary;
23 100 $self->init(\@ary, $ceiling);
24 100 push @{$self->{'_numbers'}}, @ary;
25
26 100 return $self;
27 }
28  
29 sub init {
30 189 ▶ my ($self, $numbers, $ceiling) = @_;
Subroutine init: called CC=2 SCAR=6.9
Pod documented
31
32 189 ▶ for(my $i = 1; $i < ($ceiling + 1); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $ceiling + 1) 16850 189 17039
33 16850 push @{$numbers}, $i;
34 }
35
36 189 return 1;
37 }
38  
39 sub play {
40 113 ▶ my ($self, $numbers) = @_;
Subroutine play: called CC=2 SCAR=6.9
Pod documented
41  
42 113 my $number;
43 113 ▶ if ($numbers) {
Branch: 1 branch
BranchTrueFalseTotal
if ($numbers) { } 10 103 113
44 10 my $index = $self->random(scalar @{$numbers});
45 10 $number = $numbers->[$index];
46 10 splice(@{$numbers}, $index, 1);
47 } else {
48 103 my $index = $self->random(scalar @{$self->{'_numbers'}});
49 103 $number = $self->{'_numbers'}->[$index];
50 103 splice(@{$self->{'_numbers'}}, $index, 1);
51 }
52 113 $self->pull($number);
53
54 113 return $number;
55 }
56  
57 sub pulled {
58 32 ▶ my ($self, $number) = @_;
Subroutine pulled: called CC=4 SCAR=13.9
Pod documented
59
60 32 my $found = 0;
61 32 foreach my $n ($self->_all_pulled()) {
62 694 ▶ if ($n == $number) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n == $number) 16 678 694
63 16 $found++;
64 16 last;
65 };
66 }
67
68 32 ▶ if ($found) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found) { } 16 16 32
69 16 return 1;
70 } else {
71 16 return 0;
72 }
73 }
74  
75 sub _all_pulled {
76 37 ▶ my $self = shift;
Subroutine _all_pulled: called CC=4 SCAR=13.9
77
78 37 my @pulled = ();
79 37 foreach my $row (@{$self->{'_pulled'}}) {
80 348 foreach my $number (@{$row}) {
81 1390 ▶ push(@pulled, $number) if $number;
Branch: 1 branch
BranchTrueFalseTotal
if $number 1356 34 1390
82 }
83 }
84
85 37 return @pulled;
86 }
87  
88 sub pull {
89 116 ▶ my ($self, $number) = @_;
Subroutine pull: called CC=1 SCAR=0.0
Pod documented
90
91 116 return $self->take($self->{'_pulled'}, $number);
92 }
93  
94 sub take {
95 117 ▶ my ($self, $taken, $take) = @_;
Subroutine take: called CC=1 SCAR=0.0
Pod documented
96  
97 117 my ($x, $y, $take_modified) = $self->splitnumber($take);
98  
99 117 return $taken->[$x][$y] = $take_modified;
100 }
101  
102 sub random {
103 3204 ▶ my ($self, $number) = @_;
Subroutine random: called CC=1 SCAR=0.0
Pod documented
104  
105 3204 return POSIX::floor(rand($number));
106 }
107  
108 sub splitnumber {
109 119 ▶ my ($self, $number) = @_;
Subroutine splitnumber: called CC=1 SCAR=0.0
Pod documented
110
111 119 my $modified = sprintf("%02d", $number);
112 119 my ($x, $y) = $modified =~ m/^(\d{1})(\d{1})$/o;
113  
114 119 return ($x, $y, $modified);
115 }
116  
117 36 1;
118  
119 __END__
« blib/lib/Games/Bingo/ColumnCollection.pm ↑ Summary Build »