lib/BalanceOfPower/Role/Mapmaker.pm

filter: Statementstmt 85.0% 57 / 67 Branchbran 50.0% 6 / 12 Conditioncond 38.4% 5 / 13 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 6 totaltotal 67.5% 79 / 117 CC 16 SCAR 18.8
CC
16
Cov
74%
load_borders
13.0
near_nations
6.0
print_near_nations
6.0
CRAP 6.6
« blib/lib/BalanceOfPower/Commands/RecallRebelMilitarySupport.pm ↑ Summary lib/BalanceOfPower/Nation.pm »
1 package BalanceOfPower::Role::Mapmaker;
2 11 $BalanceOfPower::Role::Mapmaker::VERSION = '0.200000';
3 11 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 ▶use BalanceOfPower::Relations::Border;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use BalanceOfPower::Relations::RelPack;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 has borders => (
11 is => 'ro',
12 14 ▶ default => sub { BalanceOfPower::Relations::RelPack->new() },
Subroutine __ANON__: called CC=1 SCAR=0.0
13 11 handles => { add_border => 'add_link',
14 border_exists => 'exists_link',
15 print_borders => 'print_links',
16 get_borders => 'links_for_node',
17 near_on_the_map => 'near',
18 distance_on_the_map => 'distance'
19 }
20 );
21  
22  
23 sub load_borders
24 {
25 14 ▶ my $self = shift;
Subroutine load_borders: called CC=9 SCAR=25.6
Pod undocumented
26 14 my $bordersfile = shift;
27 14 ▶ my $file = shift || $self->data_directory . "/" . $bordersfile;
Condition50%1/2
shift() || $self->data_directory . '/' . $bordersfile
l!l
014
MC/DC0%0/1
shift() || $self->data_directory . '/' . $bordersfile
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
28 14 ▶ open(my $borders, "<", $file) || die $!;;
Branch: 1 branch
BranchTrueFalseTotal
open my $borders, "<", $file or die $! 0 14 14
29 14 for(<$borders>)
30 {
31 51 chomp;
32 51 my $border = $_;
33 51 my @nodes = split(/,/, $border);
34 51 ▶ if($self->check_nation_name($nodes[0]) && $self->check_nation_name($nodes[1]))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->check_nation_name($nodes[0]) and $self->check_nation_name($nodes[1])) { } 51 0 51
Condition33%1/3
$self->check_nation_name($nodes[0]) and $self->check_nation_name($nodes[1])
!ll&&!rl&&r
0051
MC/DC0%0/2
$self->check_nation_name($nodes[0]) and $self->check_nation_name($nodes[1])
$self->check_nation_name($nodes[0]) $self->check_nation_name($nodes[1])
Truth table33%1/3
A and B
A= $self->check_nation_name($nodes[0])B= $self->check_nation_name($nodes[1])
ABresult
0X0
100
111
35 {
36 51 ▶ if($nodes[0] && $nodes[1] && ! $self->border_exists($nodes[0], $nodes[1]))
Branch: 1 branch
BranchTrueFalseTotal
if ($nodes[0] and $nodes[1] and not $self->border_exists($nodes[0], $nodes[1])) 51 0 51
Condition33%2/6
$nodes[0] and $nodes[1] and not $self->border_exists($nodes[0], $nodes[1])
!ll&&!rl&&r
0051
$nodes[0] and $nodes[1]
!ll&&!rl&&r
0051
MC/DC0%0/3
$nodes[0] and $nodes[1] and not $self->border_exists($nodes[0], $nodes[1])
$nodes[0] $nodes[1] not $self->border_exists($nodes[0], $nodes[1])
Truth table25%1/4
A and B and not(C)
A= $nodes[0]B= $nodes[1]C= not $self->border_exists($nodes[0], $nodes[1])
ABCresult
0XX0
10X0
1100
1111
37 {
38 51 my $b = BalanceOfPower::Relations::Border->new(node1 => $nodes[0], node2 => $nodes[1]);
39 51 $self->add_border($b);
40 }
41 }
42 else
43 {
44 0 say "WRONG BORDER: $border";
45 }
46 }
47 }
48  
49 sub near_nations
50 {
51 13 ▶ my $self = shift;
Subroutine near_nations: called CC=4 SCAR=17.9
Pod undocumented
52 13 my $nation = shift;
53 13 ▶ my $geographical = shift || 0;
Condition50%1/2
shift() || 0
l!l
130
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
54 13 ▶ if($geographical)
Branch: 1 branch
BranchTrueFalseTotal
if ($geographical) { } 13 0 13
55 {
56 13 return $self->near_on_the_map($nation, $self->nation_names);
57 }
58 else
59 {
60 0 ▶ return grep { $self->in_military_range($nation, $_) && $nation ne $_ } @{$self->nation_names};
Branch: 1 branch
BranchTrueFalseTotal
$self->in_military_range($nation, $_) and $nation ne $_ 0 0 0
61 }
62 }
63 sub print_near_nations
64 {
65 0 ▶ my $self = shift;
Subroutine print_near_nations: not called CC=2 SCAR=17.9
Pod undocumented
66 0 my $nation = shift;
67 0 my $out = "";
68 0 for($self->near_nations($nation))
69 {
70 0 $out .= $_ . "\n";
71 }
72 0 return $out;
73 }
74 sub distance
75 {
76 136 ▶ my $self = shift;
Subroutine distance: called CC=1 SCAR=0.0
Pod undocumented
77 136 my $nation1 = shift;
78 136 my $nation2 = shift;
79 136 return $self->distance_on_the_map($nation1, $nation2, $self->nation_names);
80 }
81  
82  
83 sub get_group_borders
84 {
85 14 ▶ my $self = shift;
Subroutine get_group_borders: called CC=4 SCAR=13.9
Pod undocumented
86 14 my $group1 = shift;
87 14 my $group2 = shift;
88 14 my @from = @{ $group1 };
89 14 my @to = @{ $group2 };
90 14 my @out = ();
91 14 foreach my $to_n (@to)
92 {
93 18 foreach my $from_n (@from)
94 {
95 21 ▶ if($self->in_military_range($from_n, $to_n))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->in_military_range($from_n, $to_n)) 8 13 21
96 {
97 8 push @out, $to_n;
98 8 last;
99 }
100 }
101 }
102 14 return @out;
103 }
104  
105 #cache management
106  
107  
108 sub print_distance
109 {
110 1 ▶ my $self = shift;
Subroutine print_distance: called CC=1 SCAR=0.0
Pod undocumented
111 1 my $n1 = shift;
112 1 my $n2 = shift;
113 1 return "Distance between $n1 and $n2: " . $self->distance($n1, $n2);
114 }
115  
116  
117  
118 11 1;
« blib/lib/BalanceOfPower/Commands/RecallRebelMilitarySupport.pm ↑ Summary lib/BalanceOfPower/Nation.pm »