| 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
Condition33%1/3
@_ == 1 and not ref $_[0]
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]
| |||||||||||||||||||||||||||||||||||||
| 17 | 2 | $str = shift; | |||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||
| 19 | ▶ | elsif (@_ == 1 and ref $_[0] eq 'SCALAR') { | |||||||||||||||||||||||||||||||||||
|
Condition0%0/3
@_ == 1 and ref $_[0] eq "SCALAR"
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"
| |||||||||||||||||||||||||||||||||||||
| 20 | 0 | $str = ${ $_[0] }; | |||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||
| 22 | else { | ||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | my %options = ref $_[0] ? %{ $_[0] } : @_; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | if (my $file = $options{filename} || $options{file}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
$options{'filename'} || $options{'file'}
MC/DC0%0/2
$options{'filename'} || $options{'file'}
$options{'filename'}
$options{'file'}
Truth table0%0/3
A || B
A= $options{'filename'}B= $options{'file'}
| |||||||||||||||||||||||||||||||||||||
| 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 ||= ""
MC/DC0%0/1
$str ||= ""
$str
Truth table50%1/2
A
A= $str
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 62 | 0 | read $fh, my $str, (-s $file); | |||||||||||||||||||||||||||||||||||
| 63 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||
| 65 | 0 | $str; | |||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||
| 69 | 3 | 1; | |||||||||||||||||||||||||||||||||||
| 70 | __END__ | ||||||||||||||||||||||||||||||||||||