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/App.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.1';
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 460 ▶ my $self = shift;
Subroutine _depth: called CC=2 SCAR=6.9
25  
26 460 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 272 188 460
27 272 $self->{_depth} = shift;
28 }
29  
30 460 return $self->{_depth};
31 }
32  
33  
34 sub get_depth
35 {
36 188 ▶ my ($self) = @_;
Subroutine get_depth: called CC=1 SCAR=0.0
Pod documented
37  
38 188 return $self->_depth();
39 }
40  
41 sub _init
42 {
43 272 ▶ my ($self, $args) = @_;
Subroutine _init: called CC=3 SCAR=11.0
44  
45 272 $self->{_text} = $args->{text};
46 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
47 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
48  
49 272 return;
50 }
51  
52  
53 sub bump
54 {
55 7 ▶ my ($self) = @_;
Subroutine bump: called CC=1 SCAR=0.0
Pod documented
56  
57 return ref($self)->new(
58 {
59 text => $self->get_text(),
60 depth => ($self->get_depth+1),
61 7 vars => { %{$self->{_vars}}, },
62 }
63 );
64 }
65  
66  
67 sub get_var
68 {
69 506 ▶ my ($self, $name) = @_;
Subroutine get_var: called CC=1 SCAR=0.0
Pod documented
70  
71 506 return $self->{_vars}->{$name};
72 }
73  
74 # TODO : duplicate code with ::Board
75 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));
76  
77 sub _expand_format
78 {
79 506 ▶ my ($self, $name, $type) = @_;
Subroutine _expand_format: called CC=3 SCAR=11.2
80  
81 506 my $value = $self->get_var($name);
82  
83 506 ▶ if ($type eq "letter")
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'letter') { } 318 188 506
elsif ($type eq 'coords') { } 188 0 188
84 {
85 318 return $letters[$value];
86 }
87 elsif ($type eq "coords")
88 {
89 188 return sprintf("(%d,%d)", $value->x()+1, $value->y()+1);
90 }
91 else
92 {
93 0 die "Unknown format type '$type'!";
94 }
95 }
96  
97  
98 14 1; # End of Games::ABC_Path::Solver::Move
99  
100 __END__
« blib/lib/Games/ABC_Path/Solver/App.pm ↑ Summary blib/lib/Games/ABC_Path/Solver/Coord.pm »