lib/BalanceOfPower/Role/Ruler.pm

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