Component/Controller/Loader.pm

filter: Statementstmt 68.8% 31 / 45 Branchbran 12.5% 2 / 16 Conditioncond 18.1% 2 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 83.3% 5 / 6 Podpod 100% 1 / 1 totaltotal 47.6% 41 / 86 CC 15 SCAR 36.9
CC
15
Cov
49%
load
56.3
_load_from_file
6.0
BEGIN
1.0
CRAP 40.2
↑ Summary Component/Controller.pm »
1 package Games::Sudoku::Component::Controller::Loader;
2 {
3 3 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶ use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 3 our $VERSION = '0.02';
8
9 3 ▶ use Games::Sudoku::Component::Table::Item;
Subroutine BEGIN: called CC=1 SCAR=0.0
10
11 2 ▶ sub load {
Subroutine load: called CC=14 SCAR=40.3
Pod documented
12 2 my $pkg = shift;
13
14 2 my $str;
15
16 2 ▶ if (@_ == 1 and !ref $_[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 and not ref $_[0]) { } 2 0 2
elsif (@_ == 1 and ref $_[0] eq 'SCALAR') { } 0 0 0
Condition33%1/3
@_ == 1 and not ref $_[0]
!ll&&!rl&&r
002
MC/DC0%0/2
@_ == 1 and not ref $_[0]
@_ == 1 not ref $_[0]
Truth table33%1/3
A and not(B)
A= @_ == 1B= not ref $_[0]
ABresult
0X0
100
111
17 2 $str = shift;
18 }
19 ▶ elsif (@_ == 1 and ref $_[0] eq 'SCALAR') {
Condition0%0/3
@_ == 1 and ref $_[0] eq "SCALAR"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "SCALAR"
@_ == 1 ref $_[0] eq "SCALAR"
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0] eq "SCALAR"
ABresult
0X0
100
111
20 0 $str = ${ $_[0] };
21 }
22 else {
23 0 ▶ my %options = ref $_[0] ? %{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
24
25 0 ▶ if (my $file = $options{filename} || $options{file}) {
Branch: 3 branches
BranchTrueFalseTotal
if (my $file = $options{'filename'} || $options{'file'}) { } 0 0 0
elsif ($options{'scalar'}) { } 0 0 0
elsif ($options{'scalarref'}) { } 0 0 0
Condition0%0/3
$options{'filename'} || $options{'file'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{'filename'} || $options{'file'}
$options{'filename'} $options{'file'}
Truth table0%0/3
A || B
A= $options{'filename'}B= $options{'file'}
ABresult
1X1
011
000
26 0 $str = $pkg->_load_from_file($file);
27 }
28 elsif ($options{scalar}) {
29 0 $str = $options{scalar};
30 }
31 elsif ($options{scalarref}) {
32 0 $str = ${ $options{scalarref} };
33 }
34 }
35
36 2 ▶ $str ||= '';
Condition50%1/2
$str ||= ""
l!l
20
MC/DC0%0/1
$str ||= ""
$str
Truth table50%1/2
A
A= $str
Aresult
11
00
37
38 2 my @cells = ();
39 2 my ($row, $col) = (0,0);
40 2 foreach my $line (split(/\n+/, $str)) {
41 9 $line =~ s/\r//g;
42 9 $row++;
43 9 $col = 0;
44 9 foreach my $value (split(/\s+/, $line)) {
45 45 $col++;
46 45 ▶ $value = 0 unless $value =~ /^[0-9]+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /^[0-9]+$/ 0 45 45
47 45 push @cells, Games::Sudoku::Component::Table::Item->new(
48 row => $row,
49 col => $col,
50 allowed => [],
51 value => $value,
52 );
53 }
54 }
55 2 @cells;
56 }
57
58 0 ▶ sub _load_from_file {
Subroutine _load_from_file: not called CC=2 SCAR=17.9
59 0 my ($pkg, $file) = @_;
60
61 0 ▶ open my $fh, '<', $file or croak "failed to open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or croak("failed to open ${file}: $!") 0 0 0
62 0 read $fh, my $str, (-s $file);
63 0 close $fh;
64
65 0 $str;
66 }
67 }
68
69 3 1;
70 __END__
↑ Summary Component/Controller.pm »