File Coverage

blib/lib/Games/ABC_Path/Solver/Move.pm
Criterion Covered Total %
statement 35 36 97.2
branch 5 6 83.3
condition 3 4 75.0
subroutine 10 10 100.0
pod 4 4 100.0
total 57 60 95.0


line stmt bran cond sub pod time code
1             package Games::ABC_Path::Solver::Move;
2             $Games::ABC_Path::Solver::Move::VERSION = '0.8.1';
3 14     14   299860 use warnings;
  14         32  
  14         848  
4 14     14   75 use strict;
  14         25  
  14         362  
5              
6              
7 14     14   77 use parent 'Games::ABC_Path::Solver::Base';
  14         24  
  14         88  
8              
9              
10             sub get_text
11             {
12 188     188 1 344 my $self = shift;
13              
14 188         604 my $text = $self->_format;
15              
16 188         1055 $text =~ s/%\((\w+)\)\{(\w+)\}/
17 506         1208 $self->_expand_format($1,$2)
18             /ge;
19              
20 188         975 return $text;
21             }
22              
23             sub _depth
24             {
25 460     460   755 my $self = shift;
26              
27 460 100       1018 if (@_)
28             {
29 272         500 $self->{_depth} = shift;
30             }
31              
32 460         1123 return $self->{_depth};
33             }
34              
35              
36             sub get_depth
37             {
38 188     188 1 378 my ($self) = @_;
39              
40 188         445 return $self->_depth();
41             }
42              
43             sub _init
44             {
45 272     272   454 my ( $self, $args ) = @_;
46              
47 272         812 $self->{_text} = $args->{text};
48 272   100     1176 $self->_depth( $args->{depth} || 0 );
49 272   50     669 $self->{_vars} = ( $args->{vars} || {} );
50              
51 272         423 return;
52             }
53              
54              
55             sub bump
56             {
57 7     7 1 16 my ($self) = @_;
58              
59             return ref($self)->new(
60             {
61             text => $self->get_text(),
62             depth => ( $self->get_depth + 1 ),
63 7         33 vars => { %{ $self->{_vars} }, },
  7         78  
64             }
65             );
66             }
67              
68              
69             sub get_var
70             {
71 506     506 1 923 my ( $self, $name ) = @_;
72              
73 506         1234 return $self->{_vars}->{$name};
74             }
75              
76             # TODO : duplicate code with ::Board
77             my @letters = (qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y));
78              
79             sub _expand_format
80             {
81 506     506   1606 my ( $self, $name, $type ) = @_;
82              
83 506         1191 my $value = $self->get_var($name);
84              
85 506 100       1161 if ( $type eq "letter" )
    50          
86             {
87 318         1197 return $letters[$value];
88             }
89             elsif ( $type eq "coords" )
90             {
91 188         531 return sprintf( "(%d,%d)", $value->x() + 1, $value->y() + 1 );
92             }
93             else
94             {
95 0           die "Unknown format type '$type'!";
96             }
97             }
98              
99              
100             1; # End of Games::ABC_Path::Solver::Move
101              
102             __END__