Nonogram/CommandLine.pm

filter: Statementstmt 33.3% 16 / 48 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 62.5% 5 / 8 Podpod n/a totaltotal 21.0% 21 / 100 CC 17 SCAR 46.2
CC
17
Cov
20%
_solve
182.0
bootstrap
12.0
_files_from_dir
7.1
CRAP 101.2
« Nonogram/BruteForce.pm ↑ Summary Nonogram/Grid.pm »
1 package Games::Nonogram::CommandLine;
2
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Games::Nonogram::Grid;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 0 ▶sub bootstrap {
Subroutine bootstrap: not called CC=3 SCAR=24.8
9 0 my $class = shift;
10
11 0 my %options;
12 GetOptions(
13 'dir=s' => \$options{dir},
14 'check_only' => \$options{check_only},
15 'debug' => \$options{debug},
16 'verbose' => \$options{verbose},
17 0 );
18
19 0 my @files = @ARGV;
20 0 ▶ push @files, $class->_files_from_dir( $options{dir} ) if $options{dir};
Branch: 1 branch
BranchTrueFalseTotal
if $options{"dir"} 0 0 0
21
22 0 foreach my $file ( @files ) {
23 0 $class->_solve( $file, \%options );
24 }
25 }
26
27 0 ▶sub _files_from_dir {
Subroutine _files_from_dir: not called CC=3 SCAR=19.6
28 0 my ($class, $dir) = @_;
29
30 0 ▶ $dir .= '/' unless $dir =~ m{[/\\]$};
Branch: 1 branch
BranchTrueFalseTotal
unless $dir =~ m([/\\]$) 0 0 0
31 0 $dir .= '*';
32
33 0 ▶ my @dirs = grep { /^[^\.]/ && -f } glob( $dir );
Subroutine BEGIN: called CC=1 SCAR=2.2
Condition0%0/3
/^[^\.]/ && -f $_
!ll&&!rl&&r
000
MC/DC0%0/2
/^[^\.]/ && -f $_
/^[^\.]/ -f $_
Truth table0%0/3
A && B
A= /^[^\.]/B= -f $_
ABresult
0X0
100
111
34 }
35
36 0 ▶sub _solve {
Subroutine _solve: not called CC=13 SCAR=52.0
37 0 my ($class, $file, $options) = @_;
38
39 0 ▶ return unless $file && -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file and -f $file 0 0 0
Condition0%0/3
$file and -f $file
!ll&&!rl&&r
000
MC/DC0%0/2
$file and -f $file
$file -f $file
Truth table0%0/3
A and B
A= $fileB= -f $file
ABresult
0X0
100
111
40
41 0 my $grid = Games::Nonogram::Grid->new_from( file => $file );
42
43 0 ▶ my $debug = $options->{debug} || 0;
Condition0%0/2
$options->{'debug'} || 0
l!l
00
MC/DC0%0/1
$options->{'debug'} || 0
$options->{'debug'}
Truth table0%0/2
A
A= $options->{'debug'}
Aresult
11
00
44 0 ▶ my $verbose = $options->{verbose} || $debug;
Condition0%0/3
$options->{'verbose'} || $debug
l!l&&r!l&&!r
000
MC/DC0%0/2
$options->{'verbose'} || $debug
$options->{'verbose'} $debug
Truth table0%0/3
A || B
A= $options->{'verbose'}B= $debug
ABresult
1X1
011
000
45 0 ▶ my $check_only = $options->{check_only} || 0;
Condition0%0/2
$options->{'check_only'} || 0
l!l
00
MC/DC0%0/1
$options->{'check_only'} || 0
$options->{'check_only'}
Truth table0%0/2
A
A= $options->{'check_only'}
Aresult
11
00
46
47 0 $grid->debug( $debug );
48
49 0 ▶ while ( $grid->is_dirty ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($grid->is_dirty) 0 0 0
50 0 $grid->update;
51 0 ▶ print $grid->as_string,"\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
52 }
53
54 0 ▶ if ( $grid->is_done or $grid->has_answers ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($grid->is_done or $grid->has_answers) { } 0 0 0
Condition0%0/3
$grid->is_done or $grid->has_answers
l!l&&r!l&&!r
000
MC/DC0%0/2
$grid->is_done or $grid->has_answers
$grid->is_done $grid->has_answers
Truth table0%0/3
A or B
A= $grid->is_doneB= $grid->has_answers
ABresult
1X1
011
000
55 0 my @answers = $grid->answers;
56 0 ▶ unless ( $check_only ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($check_only) { } 0 0 0
if (do { @answers > 1 }) { } 0 0 0
57 0 print "\n$file: Answers\n", join "\n", @answers;
58 }
59 elsif ( @answers > 1 ) {
60 0 print "$file is ambiguous.\n";
61 }
62 else {
63 0 print "$file is ok.\n";
64 }
65 }
66 else {
67 0 ▶ unless ( $check_only ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($check_only) { } 0 0 0
68 0 print "\n$file: Failed\n";
69 0 print $grid->as_string,"\n";
70 }
71 else {
72 0 print "$file seems broken.\n";
73 }
74 }
75 }
76
77 2 1;
78
79 __END__
« Nonogram/BruteForce.pm ↑ Summary Nonogram/Grid.pm »