File Coverage

blib/lib/Games/ABC_Path/Solver/App.pm
Criterion Covered Total %
statement 44 47 93.6
branch 8 12 66.6
condition n/a
subroutine 9 9 100.0
pod 1 1 100.0
total 62 69 89.8


line stmt bran cond sub pod time code
1             package Games::ABC_Path::Solver::App;
2             $Games::ABC_Path::Solver::App::VERSION = '0.8.1';
3 4     4   384413 use warnings;
  4         8  
  4         251  
4 4     4   25 use strict;
  4         10  
  4         167  
5              
6              
7 4     4   2643 use parent 'Games::ABC_Path::Solver::Base';
  4         1093  
  4         22  
8              
9 4     4   3138 use Getopt::Long qw/ GetOptionsFromArray /;
  4         62113  
  4         29  
10 4     4   3280 use Pod::Usage qw/ pod2usage /;
  4         303601  
  4         360  
11              
12 4     4   2430 use Games::ABC_Path::Solver::Board ();
  4         21  
  4         1629  
13              
14             sub _argv
15             {
16 8     8   16 my $self = shift;
17              
18 8 100       29 if (@_)
19             {
20 3         21 $self->{_argv} = shift;
21             }
22              
23 8         57 return $self->{_argv};
24             }
25              
26             sub _init
27             {
28 3     3   10 my ( $self, $args ) = @_;
29              
30 3         9 $self->_argv( [ @{ $args->{argv} } ] );
  3         25  
31              
32 3         9 return;
33             }
34              
35             sub run
36             {
37 3     3 1 7 my $self = shift;
38              
39 3         6 my $man = 0;
40 3         8 my $help = 0;
41 3         7 my $gen_template = 0;
42 3 50       12 GetOptionsFromArray(
43             $self->_argv,
44             'help|h' => \$help,
45             man => \$man,
46             'gen-v1-template' => \$gen_template,
47             ) or pod2usage(2);
48              
49 3 50       2574 if ($help)
    50          
    100          
50             {
51 0         0 pod2usage(1);
52             }
53             elsif ($man)
54             {
55 0         0 pod2usage( -verbose => 2 );
56             }
57             elsif ($gen_template)
58             {
59 1         8 print <<'EOF';
60             ABC Path Solver Layout Version 1:
61             ???????
62             ? ?
63             ? ?
64             ? ?
65             ? A ?
66             ? ?
67             ???????
68             EOF
69             }
70             else
71             {
72 2         5 my $board_fn = shift( @{ $self->_argv } );
  2         8  
73              
74 2 50       8 if ( !defined($board_fn) )
75             {
76 0         0 die
77             "Filename not specified - usage: abc-path-solver.pl [filename]!";
78             }
79              
80 2         23 my $solver = Games::ABC_Path::Solver::Board->input_from_file($board_fn);
81              
82             # Now let's do a neighbourhood inferring of the board.
83              
84 2         14 $solver->solve;
85              
86 2         5 foreach my $move ( @{ $solver->get_moves } )
  2         12  
87             {
88 181         581 print +( ' => ' x $move->get_depth() ), $move->get_text(), "\n";
89             }
90              
91 2         16 print @{ $solver->get_successes_text_tables };
  2         38  
92             }
93              
94 3           exit(0);
95             }
96              
97              
98             1; # End of Games::ABC_Path::Solver::App
99              
100             __END__