| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 31 | 0 | $dir .= '*'; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | my @dirs = grep { /^[^\.]/ && -f } glob( $dir ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.2
Condition0%0/3
/^[^\.]/ && -f $_
MC/DC0%0/2
/^[^\.]/ && -f $_
/^[^\.]/
-f $_
Truth table0%0/3
A && B
A= /^[^\.]/B= -f $_
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$file and -f $file
MC/DC0%0/2
$file and -f $file
$file
-f $file
Truth table0%0/3
A and B
A= $fileB= -f $file
| |||||||||||||||||||||||||||||
| 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
MC/DC0%0/1
$options->{'debug'} || 0
$options->{'debug'}
Truth table0%0/2
A
A= $options->{'debug'}
| |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | my $verbose = $options->{verbose} || $debug; | ||||||||||||||||||||||||||
|
Condition0%0/3
$options->{'verbose'} || $debug
MC/DC0%0/2
$options->{'verbose'} || $debug
$options->{'verbose'}
$debug
Truth table0%0/3
A || B
A= $options->{'verbose'}B= $debug
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | my $check_only = $options->{check_only} || 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$options->{'check_only'} || 0
MC/DC0%0/1
$options->{'check_only'} || 0
$options->{'check_only'}
Truth table0%0/2
A
A= $options->{'check_only'}
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | $grid->debug( $debug ); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | while ( $grid->is_dirty ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | $grid->update; | |||||||||||||||||||||||||||
| 51 | 0 | ▶ | print $grid->as_string,"\n" if $verbose; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ( $grid->is_done or $grid->has_answers ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$grid->is_done or $grid->has_answers
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
| |||||||||||||||||||||||||||||
| 55 | 0 | my @answers = $grid->answers; | |||||||||||||||||||||||||||
| 56 | 0 | ▶ | unless ( $check_only ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||