lib/BalanceOfPower/Role/Ruler.pm

filter: Statementstmt 88.7% 87 / 98 Branchbran 80.7% 21 / 26 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 15 / 15 Podpod 0.0% 0 / 7 totaltotal 82.4% 127 / 154 CC 20 SCAR 14.0
CC
20
Cov
86%
occupy
7.7
situation_clock
6.2
print_nation_situation
5.0
CRAP 4.1
« lib/BalanceOfPower/Commands/EconomicAid.pm ↑ Summary blib/lib/BalanceOfPower/Commands/BoostProduction.pm »
1 package BalanceOfPower::Role::Ruler;
2 11 $BalanceOfPower::Role::Ruler::VERSION = '0.200000';
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 ▶use BalanceOfPower::Constants ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 ▶use BalanceOfPower::Relations::Influence;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 11 requires 'broadcast_event';
11 11 requires 'get_nation';
12  
13 has influences => (
14 is => 'ro',
15 14 ▶ default => sub { BalanceOfPower::Relations::RelPack->new() },
Subroutine __ANON__: called CC=1 SCAR=0.0
16 11 handles => { reset_influences => 'delete_link_for_node',
17 print_influences => 'print_links',
18 add_influence => 'add_link' }
19 );
20 sub influences_garbage_collector
21 {
22 41 ▶ my $self = shift;
Subroutine influences_garbage_collector: called CC=1 SCAR=0.0
Pod undocumented
23 41 ▶ $self->influences->garbage_collector(sub { my $rel = shift; return $rel->status == -1 });
Subroutine __ANON__: called CC=1 SCAR=0.0
24 }
25 sub is_under_influence
26 {
27 360 ▶ my $self = shift;
Subroutine is_under_influence: called CC=2 SCAR=6.9
Pod undocumented
28 360 my $nation = shift;
29 my @rels = $self->influences->query(
30 sub {
31 47 ▶ my $rel = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
32 47 ▶ return 0 if($rel->node2 ne $nation);
Branch: 1 branch
BranchTrueFalseTotal
if $rel->node2 ne $nation 37 10 47
33 10 return $rel->actual_influence()
34 360 }, $nation);
35 360 ▶ if(@rels > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (@rels > 0) { } 10 350 360
36 {
37 10 return $rels[0]->start($nation);
38 }
39 else
40 {
41 350 return undef;
42 }
43 }
44 sub print_nation_situation
45 {
46 2 ▶ my $self = shift;
Subroutine print_nation_situation: called CC=4 SCAR=16.1
Pod undocumented
47 2 my $nation = shift;
48 2 my $domination = $self->is_under_influence($nation);
49 2 ▶ return "$nation is under control of $domination" if $domination;
Branch: 1 branch
BranchTrueFalseTotal
if $domination 0 2 2
50 2 my @influence = $self->has_influence($nation);
51 2 ▶ if(@influence > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (@influence > 0) { } 0 2 2
52 {
53 0 my $out = "";
54 0 for(@influence)
55 {
56 0 $out .= "$nation has influence on $_\n";
57 }
58 0 return $out;
59 }
60 else
61 {
62 2 return "$nation is free";
63 }
64  
65 }
66 sub has_influence
67 {
68 322 ▶ my $self = shift;
Subroutine has_influence: called CC=2 SCAR=6.9
Pod undocumented
69 322 my $nation = shift;
70 my @influences = $self->influences->query(
71 sub {
72 33 ▶ my $rel = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
73 33 ▶ return 0 if($rel->node1 ne $nation);
Branch: 1 branch
BranchTrueFalseTotal
if $rel->node1 ne $nation 22 11 33
74 11 return $rel->actual_influence()
75 322 }, $nation);
76 322 my @out = ();
77 322 for(@influences)
78 {
79 10 push @out, $_->destination($nation);
80 }
81 322 return @out;
82 }
83 sub empire
84 {
85 141 ▶ my $self = shift;
Subroutine empire: called CC=2 SCAR=6.9
Pod undocumented
86 141 my $n = shift;
87 141 ▶ if(my $domination = $self->is_under_influence($n))
Branch: 1 branch
BranchTrueFalseTotal
if (my $domination = $self->is_under_influence($n)) { } 3 138 141
88 {
89 3 my $dominator = $domination;
90 3 my @allies = $self->has_influence($dominator);
91 3 push @allies, $dominator;
92 3 return @allies;
93 }
94 else
95 {
96 138 my @allies = $self->has_influence($n);
97 138 push @allies, $n;
98 138 return @allies;
99 }
100 }
101 sub occupy
102 {
103 4 ▶ my $self = shift;
Subroutine occupy: called CC=7 SCAR=20.4
Pod undocumented
104 4 my $nation = shift;
105 4 my $occupiers = shift;
106 4 my $leader = shift;
107 4 ▶ my $internal_disorder = shift || 0;
Condition100%2/2
shift() || 0
l!l
22
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
108 4 $self->get_nation($nation)->occupation($self);
109 4 my $occupied_progress = $self->get_nation($nation)->progress;
110  
111 4 my @occupiers_array = @{$occupiers};
112 4 my $real_leader = $self->is_under_influence($leader);
113 4 ▶ if($real_leader)
Branch: 1 branch
BranchTrueFalseTotal
if ($real_leader) 0 4 4
114 {
115 0 @occupiers_array = grep { $_ ne $real_leader } @occupiers_array;
116 0 push @occupiers_array, $real_leader;
117 0 $leader = $real_leader;
118 }
119 4 foreach my $c (@occupiers_array)
120 {
121 4 ▶ if($c eq $leader)
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq $leader) { } 4 0 4
122 {
123 4 ▶ $self->add_influence(BalanceOfPower::Relations::Influence->new( node1 => $c,
Branch: 1 branch
BranchTrueFalseTotal
$internal_disorder ? : 2 2 4
124 node2 => $nation,
125 status => 0,
126 next => $internal_disorder ? 2 : 1,
127 clock => 0 ));
128 4 $self->set_diplomacy($nation, $c, DOMINION_DIPLOMACY);
129 4 $self->copy_diplomacy($c, $nation);
130 4 ▶ if($self->get_nation($c)->progress < $occupied_progress)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_nation($c)->progress < $occupied_progress) 1 3 4
131 {
132 1 $self->get_nation($c)->progress($occupied_progress);
133 1 $self->broadcast_event("$c ACQUIRES PROGRESS FROM $nation: $occupied_progress", $c, $nation);
134 }
135 }
136 else
137 {
138 0 $self->add_influence(BalanceOfPower::Relations::Influence->new( node1 => $c,
139 node2 => $nation,
140 status => 0,
141 clock => 0 ));
142 0 $self->set_diplomacy($nation, $c, DIPLOMACY_AFTER_OCCUPATION);
143 0 $self->get_nation($c)->grow();
144 }
145 4 $self->broadcast_event("$c OCCUPIES $nation", $c, $nation);
146 }
147 }
148 sub situation_clock
149 {
150 41 ▶ my $self = shift;
Subroutine situation_clock: called CC=6 SCAR=18.2
Pod undocumented
151 41 foreach my $i ($self->influences->all())
152 {
153 7 my $old_status = $i->status_label;
154 7 my $new_status = $i->click();
155 7 ▶ if($new_status && $old_status ne $new_status)
Branch: 1 branch
BranchTrueFalseTotal
if ($new_status and $old_status ne $new_status) 7 0 7
Condition33%1/3
$new_status and $old_status ne $new_status
!ll&&!rl&&r
007
MC/DC0%0/2
$new_status and $old_status ne $new_status
$new_status $old_status ne $new_status
Truth table33%1/3
A and B
A= $new_statusB= $old_status ne $new_status
ABresult
0X0
100
111
156 {
157 7 ▶ if($new_status eq 'dominate')
Branch: 2 branches
BranchTrueFalseTotal
if ($new_status eq 'dominate') { } 1 6 7
elsif ($new_status eq 'control') { } 2 4 6
158 {
159 1 $self->broadcast_event($i->node1 . " DOMINATES " . $i->node2, $i->node1, $i->node2);
160 }
161 elsif($new_status eq 'control')
162 {
163 2 $self->broadcast_event($i->node1 . " CONTROLS " . $i->node2, $i->node1, $i->node2);
164 }
165 }
166 }
167 41 $self->influences_garbage_collector();
168 }
169  
170 11 1;
« lib/BalanceOfPower/Commands/EconomicAid.pm ↑ Summary blib/lib/BalanceOfPower/Commands/BoostProduction.pm »