blib/lib/Games/ABC_Path/Solver/Move.pm

filter: Statementstmt 97.4% 38 / 39 Branchbran 83.3% 5 / 6 Conditioncond 75.0% 3 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 10 / 10 Podpod 100% 4 / 4 totaltotal 93.8% 61 / 65 CC 6 SCAR 6.7
CC
6
Cov
94%
_expand_format
3.1
_init
3.0
_depth
2.0
CRAP 2.0
« blib/lib/Games/ABC_Path/Solver/Board.pm ↑ Summary blib/lib/Games/ABC_Path/Solver/Coord.pm »
1 package Games::ABC_Path::Solver::Move;
2 14 $Games::ABC_Path::Solver::Move::VERSION = '0.6.2';
3 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6  
7 14 ▶use parent 'Games::ABC_Path::Solver::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 sub get_text
11 {
12 188 ▶ my $self = shift;
Subroutine get_text: called CC=1 SCAR=0.0
Pod documented
13  
14 188 my $text = $self->_format;
15  
16 188 $text =~ s/%\((\w+)\)\{(\w+)\}/
17 506 $self->_expand_format($1,$2)
18 /ge;
19  
20 188 return $text;
21 }
22  
23 sub _depth
24 {
25 460 ▶ my $self = shift;
Subroutine _depth: called CC=2 SCAR=6.9
26  
27 460 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 272 188 460
28 {
29 272 $self->{_depth} = shift;
30 }
31  
32 460 return $self->{_depth};
33 }
34  
35  
36 sub get_depth
37 {
38 188 ▶ my ($self) = @_;
Subroutine get_depth: called CC=1 SCAR=0.0
Pod documented
39  
40 188 return $self->_depth();
41 }
42  
43 sub _init
44 {
45 272 ▶ my ( $self, $args ) = @_;
Subroutine _init: called CC=3 SCAR=11.0
46  
47 272 $self->{_text} = $args->{text};
48 272 ▶ $self->_depth( $args->{depth} || 0 );
Condition100%2/2
$args->{'depth'} || 0
l!l
7265
MC/DC100%1/1
$args->{'depth'} || 0
$args->{'depth'}
Truth table100%2/2
A
A= $args->{'depth'}
Aresult
11
00
49 272 ▶ $self->{_vars} = ( $args->{vars} || {} );
Condition50%1/2
$args->{'vars'} || {}
l!l
2720
MC/DC0%0/1
$args->{'vars'} || {}
$args->{'vars'}
Truth table50%1/2
A
A= $args->{'vars'}
Aresult
11
00
50  
51 272 return;
52 }
53  
54  
55 sub bump
56 {
57 7 ▶ my ($self) = @_;
Subroutine bump: called CC=1 SCAR=0.0
Pod documented
58  
59 return ref($self)->new(
60 {
61 text => $self->get_text(),
62 depth => ( $self->get_depth + 1 ),
63 7 vars => { %{ $self->{_vars} }, },
64 }
65 );
66 }
67  
68  
69 sub get_var
70 {
71 506 ▶ my ( $self, $name ) = @_;
Subroutine get_var: called CC=1 SCAR=0.0
Pod documented
72  
73 506 return $self->{_vars}->{$name};
74 }
75  
76 # TODO : duplicate code with ::Board
77 14 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 ▶ my ( $self, $name, $type ) = @_;
Subroutine _expand_format: called CC=3 SCAR=11.2
82  
83 506 my $value = $self->get_var($name);
84  
85 506 ▶ if ( $type eq "letter" )
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'letter') { } 318 188 506
elsif ($type eq 'coords') { } 188 0 188
86 {
87 318 return $letters[$value];
88 }
89 elsif ( $type eq "coords" )
90 {
91 188 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 14 1; # End of Games::ABC_Path::Solver::Move
101  
102 __END__
« blib/lib/Games/ABC_Path/Solver/Board.pm ↑ Summary blib/lib/Games/ABC_Path/Solver/Coord.pm »