Component/Table/Permission.pm

filter: Statementstmt 90.2% 65 / 72 Branchbran 69.2% 18 / 26 Conditioncond 25.0% 1 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 93.3% 14 / 15 Podpod 100% 7 / 7 totaltotal 83.3% 105 / 126 CC 18 SCAR 13.4
CC
18
Cov
82%
result
9.4
is_allowed
4.0
_flag
3.1
CRAP 3.8
« Component/Table/Item.pm ↑ Summary Component/Controller/Status.pm »
1 package Games::Sudoku::Component::Table::Permission;
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 7 ▶ use base qw/Games::Sudoku::Component::Base/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10
11 7 my $Verbose = 0;
12
13 14 ▶ sub _initialize {
Subroutine _initialize: called CC=1 SCAR=0.0
14 14 my ($this, %options) = @_;
15
16 14 $this->clear;
17 }
18
19 0 ▶ sub verbose { shift; $Verbose = shift; }
Subroutine verbose: not called CC=1 SCAR=6.9
Pod documented
20
21 15 ▶ sub clear {
Subroutine clear: called CC=2 SCAR=6.9
Pod documented
22 15 my $this = shift;
23
24 15 my $size = $this->{size};
25 15 my $flag = (2 ** $size) - 1;
26
27 15 foreach my $ct (1..$size) {
28 151 $this->{row}[$ct] = $flag;
29 151 $this->{col}[$ct] = $flag;
30 151 $this->{blk}[$ct] = $flag;
31 }
32 }
33
34 121 ▶ sub allow {
Subroutine allow: called CC=1 SCAR=0.0
Pod documented
35 121 my ($this, $row, $col, $value) = @_;
36
37 121 my $blk = $this->_block_id($row,$col);
38
39 121 $this->{row}[$row] = $this->_on($this->{row}[$row], $value);
40 121 $this->{col}[$col] = $this->_on($this->{col}[$col], $value);
41 121 $this->{blk}[$blk] = $this->_on($this->{blk}[$blk], $value);
42 }
43
44 327 ▶ sub deny {
Subroutine deny: called CC=1 SCAR=0.0
Pod documented
45 327 my ($this, $row, $col, $value) = @_;
46
47 327 my $blk = $this->_block_id($row,$col);
48
49 327 $this->{row}[$row] = $this->_off($this->{row}[$row], $value);
50 327 $this->{col}[$col] = $this->_off($this->{col}[$col], $value);
51 327 $this->{blk}[$blk] = $this->_off($this->{blk}[$blk], $value);
52 }
53
54 6907 ▶ sub allowed {
Subroutine allowed: called CC=3 SCAR=11.0
Pod documented
55 6907 my ($this, $row, $col) = @_;
56
57 6907 my @allowed = ();
58 6907 foreach my $ct (1..$this->{size}) {
59 57169 ▶ push @allowed, $ct if $this->is_allowed($row, $col, $ct);
Branch: 1 branch
BranchTrueFalseTotal
if $this->is_allowed($row, $col, $ct) 38650 18518 57168
60 }
61 6906 @allowed;
62 }
63
64 57607 ▶ sub is_allowed {
Subroutine is_allowed: called CC=4 SCAR=13.9
Pod documented
65 57607 my ($this, $row, $col, $value) = @_;
66
67 57607 my $blk = $this->_block_id($row, $col);
68
69 return $this->result(
70 result => 0,
71 reason => "row $row has $value"
72 57606 ▶ ) unless $this->_flag($this->{row}[$row], $value);
Branch: 1 branch
BranchTrueFalseTotal
unless $this->_flag($this->{"row"}[$row], $value) 3667 53939 57606
73
74 return $this->result(
75 result => 0,
76 reason => "col $col has $value"
77 53939 ▶ ) unless $this->_flag($this->{col}[$col], $value);
Branch: 1 branch
BranchTrueFalseTotal
unless $this->_flag($this->{"col"}[$col], $value) 13640 40299 53939
78
79 return $this->result(
80 result => 0,
81 reason => "blk $blk has $value"
82 40299 ▶ ) unless $this->_flag($this->{blk}[$blk], $value);
Branch: 1 branch
BranchTrueFalseTotal
unless $this->_flag($this->{"blk"}[$blk], $value) 1255 39044 40299
83
84 39044 return $this->result(1);
85 }
86
87 57616 ▶ sub result {
Subroutine result: called CC=6 SCAR=22.4
Pod documented
88 57616 my $this = shift;
89
90 57616 ▶ if ($Verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Verbose) { } 0 57616 57616
91 0 require Games::Sudoku::Component::Result;
92 0 my $result = Games::Sudoku::Component::Result->new(@_);
93 }
94 else {
95 57616 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 39044 18572 57616
96 39044 ▶ if (ref $_[0] eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 39044 39044
97 0 my %options = %{ $_[0] };
98 0 ▶ return $options{result} || 0;
Condition0%0/2
$options{'result'} || 0
l!l
00
MC/DC0%0/1
$options{'result'} || 0
$options{'result'}
Truth table0%0/2
A
A= $options{'result'}
Aresult
11
00
99 }
100 else {
101 39044 return $_[0];
102 }
103 }
104 else {
105 18572 my %options = @_;
106 18572 ▶ return $options{result} || 0;
Condition50%1/2
$options{'result'} || 0
l!l
018572
MC/DC0%0/1
$options{'result'} || 0
$options{'result'}
Truth table50%1/2
A
A= $options{'result'}
Aresult
11
00
107 }
108 }
109 }
110
111 151873 ▶ sub _flag {
Subroutine _flag: called CC=3 SCAR=11.4
112 151873 my ($this, $flag, $value) = @_;
113
114 151873 ▶ croak "Invalid value: $value" unless $this->_check($value);
Branch: 1 branch
BranchTrueFalseTotal
unless $this->_check($value) 0 151871 151871
115 151871 ▶ croak "Invalid flag: undef" unless defined $flag;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flag 0 151871 151871
116
117 151871 return (0 + $flag) & (2 ** ($value - 1));
118 }
119
120 366 ▶ sub _on {
Subroutine _on: called CC=3 SCAR=11.4
121 366 my ($this, $flag, $value) = @_;
122
123 366 ▶ croak "Invalid value: $value" unless $this->_check($value);
Branch: 1 branch
BranchTrueFalseTotal
unless $this->_check($value) 0 364 364
124 364 ▶ croak "Invalid flag: undef" unless defined $flag;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flag 0 364 364
125
126 364 return (0 + $flag) | (2 ** ($value - 1));
127 }
128
129 984 ▶ sub _off {
Subroutine _off: called CC=3 SCAR=11.4
130 984 my ($this, $flag, $value) = @_;
131
132 984 ▶ croak "Invalid value: $value" unless $this->_check($value);
Branch: 1 branch
BranchTrueFalseTotal
unless $this->_check($value) 0 982 982
133 982 ▶ croak "Invalid flag: undef" unless defined $flag;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flag 0 982 982
134
135 982 return (0 + $flag) & ~(2 ** ($value - 1));
136 }
137 }
138
139 7 1;
140 __END__
« Component/Table/Item.pm ↑ Summary Component/Controller/Status.pm »