Verify/App/CmdLine.pm

filter: Statementstmt 30.0% 27 / 90 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 42.1% 8 / 19 Podpod 100% 1 / 1 totaltotal 26.6% 36 / 135 CC 12 SCAR 19.7
CC
12
Cov
24%
run
20.0
_init
12.0
__ANON__
12.0
CRAP 7.2
« Verify/App/CmdLine/Expand.pm ↑ Summary Verify/App/CmdLine/From_Patsolve.pm »
1 package Games::Solitaire::Verify::App::CmdLine;
2 1 $Games::Solitaire::Verify::App::CmdLine::VERSION = '0.2601';
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use parent 'Games::Solitaire::Verify::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Data::Dumper qw(Dumper);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Getopt::Long qw(GetOptionsFromArray);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Pod::Usage qw/ pod2usage /;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use Games::Solitaire::Verify::VariantsMap ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Games::Solitaire::Verify::Solution ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 __PACKAGE__->mk_acc_ref(
17 [
18 qw(
19 _filename
20 _max_rank
21 _variant_params
22 )
23 ]
24 );
25  
26 sub _init
27 0 ▶{
Subroutine _init: not called CC=3 SCAR=24.8
28 0 my ( $self, $args ) = @_;
29  
30 0 my $argv = $args->{'argv'};
31  
32 0 my $variant_map = Games::Solitaire::Verify::VariantsMap->new();
33  
34 0 my $variant_params = $variant_map->get_variant_by_id("freecell");
35 0 my $max_rank = 13;
36  
37 GetOptionsFromArray(
38 $argv,
39 0 ▶ 'help|h' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
40 0 pod2usage(1);
41 },
42 0 ▶ 'g|game|variant=s' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
43 0 my ( undef, $game ) = @_;
44  
45 0 $variant_params = $variant_map->get_variant_by_id($game);
46  
47 0 ▶ if ( !defined($variant_params) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $variant_params) 0 0 0
48 {
49 0 die "Unknown variant '$game'!\n";
50 }
51 },
52 0 ▶ 'freecells-num=i' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
53 0 my ( undef, $n ) = @_;
54 0 $variant_params->num_freecells($n);
55 },
56 0 ▶ 'stacks-num=i' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
57 0 my ( undef, $n ) = @_;
58 0 $variant_params->num_columns($n);
59 },
60 0 ▶ 'decks-num=i' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
61 0 my ( undef, $n ) = @_;
62  
63 0 ▶ if ( !( ( $n == 1 ) || ( $n == 2 ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($n == 1 or $n == 2) 0 0 0
Condition0%0/3
$n == 1 or $n == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$n == 1 or $n == 2
$n == 1 $n == 2
Truth table0%0/3
A or B
A= $n == 1B= $n == 2
ABresult
1X1
011
000
64 {
65 0 die "Decks should be 1 or 2.";
66 }
67  
68 0 $variant_params->num_decks($n);
69 },
70 0 ▶ 'max-rank=i' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
71 0 my ( undef, $n ) = @_;
72  
73 0 $max_rank = $n;
74  
75 0 return;
76 },
77 0 ▶ 'sequences-are-built-by=s' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
78 0 my ( undef, $val ) = @_;
79  
80 my %seqs_build_by = (
81 0 ( map { $_ => $_ } (qw(alt_color suit rank)) ),
82 "alternate_color" => "alt_color",
83 );
84  
85 0 my $proc_val = $seqs_build_by{$val};
86  
87 0 ▶ if ( !defined($proc_val) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $proc_val) 0 0 0
88 {
89 0 die "Unknown sequences-are-built-by '$val'!";
90 }
91  
92 0 $variant_params->seqs_build_by($proc_val);
93 },
94 0 ▶ 'empty-stacks-filled-by=s' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
95 0 my ( undef, $val ) = @_;
96  
97 my %empty_stacks_filled_by_map =
98 0 ( map { $_ => 1 } (qw(kings any none)) );
99  
100 0 ▶ if ( !exists( $empty_stacks_filled_by_map{$val} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $empty_stacks_filled_by_map{$val}) 0 0 0
101 {
102 0 die "Unknown empty stacks filled by '$val'!";
103 }
104  
105 0 $variant_params->empty_stacks_filled_by($val);
106 },
107 0 ▶ 'sequence-move=s' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
108 0 my ( undef, $val ) = @_;
109  
110 0 my %seq_moves = ( map { $_ => 1 } (qw(limited unlimited)) );
111  
112 0 ▶ if ( !exists( $seq_moves{$val} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $seq_moves{$val}) 0 0 0
113 {
114 0 die "Unknown sequence move '$val'!";
115 }
116  
117 0 $variant_params->sequence_move($val);
118 },
119 0 ▶ ) or die "Cannot process command line arguments";
Branch: 1 branch
BranchTrueFalseTotal
&GetOptionsFromArray($argv, "help|h", sub { pod2usage(1); } , "g|game|variant=s", sub { my(undef, $game) = @_; $variant_params = $variant_map->get_variant_by_id($game); if (not defined $variant_params) { die "Unknown variant '${game}'!\n"; } ; } , "freecells-num=i", sub { my(undef, $n) = @_; $variant_params->num_freecells($n); } , "stacks-num=i", sub { my(undef, $n) = @_; $variant_params->num_columns($n); } , "decks-num=i", sub { my(undef, $n) = @_; unless ($n == 1 or $n == 2) { die "Decks should be 1 or 2."; } ; $variant_params->num_decks($n); } , "max-rank=i", sub { my(undef, $n) = @_; $max_rank = $n; return; } , "sequences-are-built-by=s", sub { my(undef, $val) = @_; my(%seqs_build_by) = (map({$_, $_;} "alt_color", "suit", "rank"), "alternate_color", "alt_color"); my $proc_val = $seqs_build_by{$val}; unless (defined $proc_val) { die "Unknown sequences-are-built-by '${val}'!"; } ; $variant_params->seqs_build_by($proc_val); } , "empty-stacks-filled-by=s", sub { my(undef, $val) = @_; my(%empty_stacks_filled_by_map) = map({$_, 1;} "kings", "any", "none"); unless (exists $empty_stacks_filled_by_map{$val}) { die "Unknown empty stacks filled by '${val}'!"; } ; $variant_params->empty_stacks_filled_by($val); } , "sequence-move=s", sub { my(undef, $val) = @_; my(%seq_moves) = map({$_, 1;} "limited", "unlimited"); unless (exists $seq_moves{$val}) { die "Unknown sequence move '${val}'!"; } ; $variant_params->sequence_move($val); } ) or die "Cannot process command line arguments" 0 0 0
120  
121 0 my $filename = shift(@$argv);
122  
123 0 ▶ if ( !defined($filename) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $filename) 0 0 0
124 {
125 0 $filename = "-";
126 }
127  
128 0 $self->_variant_params($variant_params);
129 0 $self->_filename($filename);
130 0 $self->_max_rank($max_rank);
131  
132 0 return;
133 }
134  
135 sub run
136 0 ▶{
Subroutine run: not called CC=4 SCAR=30.0
Pod documented
137 0 my $self = shift;
138  
139 0 my $filename = $self->_filename();
140 0 my $variant_params = $self->_variant_params();
141  
142 0 my $fh;
143  
144 0 ▶ if ( $filename eq "-" )
Branch: 1 branch
BranchTrueFalseTotal
if ($filename eq '-') { } 0 0 0
145 {
146 0 $fh = *STDIN;
147 }
148 else
149 {
150 0 ▶ open $fh, "<", $filename
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $filename or die "Cannot open '${filename}' - $!" 0 0 0
151 or die "Cannot open '$filename' - $!";
152 }
153  
154 0 my $solution = Games::Solitaire::Verify::Solution->new(
155 {
156 max_rank => scalar( $self->_max_rank ),
157 input_fh => $fh,
158 variant => "custom",
159 variant_params => $variant_params,
160 },
161 );
162  
163 0 my $verdict = $solution->verify();
164 0 ▶ if ( !$verdict )
Branch: 1 branch
BranchTrueFalseTotal
if (not $verdict) { } 0 0 0
165 {
166 0 print "Solution is OK.\n";
167 0 exit(0);
168 }
169 else
170 {
171 0 print STDERR Dumper($verdict);
172 0 print "Solution is Wrong.\n";
173 0 exit(-1);
174 }
175 }
176  
177 1 1;
178  
179 __END__
« Verify/App/CmdLine/Expand.pm ↑ Summary Verify/App/CmdLine/From_Patsolve.pm »