Component/Base.pm

filter: Statementstmt 95.9% 47 / 49 Branchbran 75.0% 18 / 24 Conditioncond 77.7% 28 / 36 MC/DCmcdc 60.0% 12 / 20 Subroutinesub 90.9% 10 / 11 Podpod 100% 4 / 4 totaltotal 82.6% 119 / 144 CC 26 SCAR 24.0
CC
26
Cov
85%
new
19.0
_check0
4.8
_check
4.0
CRAP 11.0
« Component/Controller.pm ↑ Summary Component/Result.pm »
1 package Games::Sudoku::Component::Base;
2 {
3 7 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶ use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 7 our $VERSION = '0.01';
8
9 1159 ▶ sub new {
Subroutine new: called CC=18 SCAR=29.5
Pod documented
10 1159 my $class = shift;
11 1159 ▶ my $this = bless {}, (ref $class || $class);
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
011590
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
12
13 0 ▶ my %options = ref $_[0] ? %{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 1159 1159
14
15 1159 ▶ my $size = $options{size} || 0;
Condition100%2/2
$options{'size'} || 0
l!l
101149
MC/DC100%1/1
$options{'size'} || 0
$options{'size'}
Truth table100%2/2
A
A= $options{'size'}
Aresult
11
00
16 1159 ▶ my $bl_width = $options{block_width} || 0;
Condition100%2/2
$options{'block_width'} || 0
l!l
113623
MC/DC100%1/1
$options{'block_width'} || 0
$options{'block_width'}
Truth table100%2/2
A
A= $options{'block_width'}
Aresult
11
00
17 1159 ▶ my $bl_height = $options{block_height} || 0;
Condition100%2/2
$options{'block_height'} || 0
l!l
113623
MC/DC100%1/1
$options{'block_height'} || 0
$options{'block_height'}
Truth table100%2/2
A
A= $options{'block_height'}
Aresult
11
00
18
19 1159 ▶ if ($bl_width and $bl_height and $bl_width && $bl_height) {
Branch: 3 branches
BranchTrueFalseTotal
if ($bl_width and $bl_height and ($bl_width and $bl_height)) { } 1133 26 1159
elsif ($size and $size == int(sqrt $size) ** 2) { } 7 19 26
elsif ($size or $bl_width or $bl_height) { } 9 10 19
Condition66%6/9
$bl_width and $bl_height and ($bl_width and $bl_height)
!ll&&!rl&&r
2601133
$bl_width and $bl_height
!ll&&!rl&&r
2331133
$bl_width and $bl_height
!ll&&!rl&&r
001133
MC/DC50%2/4
$bl_width and $bl_height and ($bl_width and $bl_height)
$bl_width $bl_height $bl_width $bl_height
Truth table60%3/5
A and B and C and D
A= $bl_widthB= $bl_heightC= $bl_widthD= $bl_height
ABCDresult
0XXX0
10XX0
110X0
11100
11111
20 1133 $size = $bl_width * $bl_height;
21 }
22 ▶ elsif ($size and $size == int(sqrt($size)) ** 2) {
Condition100%3/3
$size and $size == int(sqrt $size) ** 2
!ll&&!rl&&r
1637
MC/DC100%2/2
$size and $size == int(sqrt $size) ** 2
$size $size == int(sqrt $size) ** 2
Truth table100%3/3
A and B
A= $sizeB= $size == int(sqrt $size) ** 2
ABresult
0X0
100
111
23 7 $bl_width = $bl_height = int(sqrt($size));
24 }
25 ▶ elsif ($size or $bl_width or $bl_height) {
Condition100%6/6
$size or $bl_width or $bl_height
l!l&&r!l&&!r
6310
$size or $bl_width
l!l&&r!l&&!r
3313
MC/DC100%3/3
$size or $bl_width or $bl_height
$size $bl_width $bl_height
Truth table100%4/4
A or B or C
A= $sizeB= $bl_widthC= $bl_height
ABCresult
1XX1
01X1
0011
0000
26 9 ▶ croak "Invalid size: $size" if $size;
Branch: 1 branch
BranchTrueFalseTotal
if $size 3 6 9
27 6 ▶ croak "Invalid block: width $bl_width, height $bl_height"
Branch: 1 branch
BranchTrueFalseTotal
if $bl_width or $bl_height 6 0 6
Condition66%2/3
$bl_width or $bl_height
l!l&&r!l&&!r
330
MC/DC0%0/2
$bl_width or $bl_height
$bl_width $bl_height
Truth table66%2/3
A or B
A= $bl_widthB= $bl_height
ABresult
1X1
011
000
28 if $bl_width || $bl_height;
29 }
30 else {
31 10 $size = 9;
32 10 $bl_width = $bl_height = 3;
33 }
34
35 1150 $this->{size} = $size;
36 1150 $this->{block_width} = $bl_width;
37 1150 $this->{block_height} = $bl_height;
38
39 1150 $this->_initialize(%options);
40
41 1145 $this;
42 }
43
44 0 ▶ sub _initialize {
Subroutine _initialize: not called CC=1 SCAR=6.9
45 0 my ($this, %options) = @_;
46 }
47
48 275893 ▶ sub _check {
Subroutine _check: called CC=4 SCAR=13.9
49 275893 my ($this, $value) = @_;
50
51 275893 ▶ croak "Invalid value: undef" unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 1 275892 275893
52 275892 ▶ croak "Invalid value: $value" if $value > $this->{size} || $value < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $value > $this->{"size"} or $value < 1 10 275882 275892
Condition100%3/3
$value > $this->{"size"} or $value < 1
l!l&&r!l&&!r
55275882
MC/DC100%2/2
$value > $this->{"size"} or $value < 1
$value > $this->{"size"} $value < 1
Truth table100%3/3
A or B
A= $value > $this->{"size"}B= $value < 1
ABresult
1X1
011
000
53
54 275882 $value;
55 }
56
57 568 ▶ sub _check0 {
Subroutine _check0: called CC=4 SCAR=15.6
58 568 my ($this, $value) = @_;
59
60 568 ▶ croak "Invalid value: undef" unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 568 568
61 568 ▶ croak "Invalid value: $value" if $value > $this->{size} || $value < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $value > $this->{"size"} or $value < 0 0 568 568
Condition33%1/3
$value > $this->{"size"} or $value < 0
l!l&&r!l&&!r
00568
MC/DC0%0/2
$value > $this->{"size"} or $value < 0
$value > $this->{"size"} $value < 0
Truth table33%1/3
A or B
A= $value > $this->{"size"}B= $value < 0
ABresult
1X1
011
000
62
63 568 $value;
64 }
65
66 58055 ▶ sub _block_id {
Subroutine _block_id: called CC=3 SCAR=11.2
67 58055 my ($this, $row, $col) = @_;
68
69 58055 ▶ croak "Invalid row: $row" unless $this->_check($row);
Branch: 1 branch
BranchTrueFalseTotal
unless $this->_check($row) 0 58054 58054
70 58054 ▶ croak "Invalid col: $col" unless $this->_check($col);
Branch: 1 branch
BranchTrueFalseTotal
unless $this->_check($col) 0 58054 58054
71
72 58054 my $blockrow = int(($row - 1) / $this->{block_height});
73 58054 my $blockcol = int(($col - 1) / $this->{block_width});
74
75 58054 $blockrow * $this->{block_height} + $blockcol + 1;
76 }
77
78 21 ▶ sub size { $_[0]->{size} }
Subroutine size: called CC=1 SCAR=0.0
Pod documented
79 9 ▶ sub block_width { $_[0]->{block_width} }
Subroutine block_width: called CC=1 SCAR=0.0
Pod documented
80 9 ▶ sub block_height { $_[0]->{block_height} }
Subroutine block_height: called CC=1 SCAR=0.0
Pod documented
81 }
82
83 7 1;
84 __END__
« Component/Controller.pm ↑ Summary Component/Result.pm »