lib/BalanceOfPower/Executive.pm

filter: Statementstmt 45.3% 73 / 161 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 76.6% 23 / 30 Podpod 0.0% 0 / 5 totaltotal 45.7% 96 / 210 CC 11 SCAR 18.8
CC
11
Cov
42%
recognize_command
20.0
decide
20.0
allowed_orders
12.0
CRAP 6.5
« blib/lib/BalanceOfPower/Commands/RecallRebelMilitarySupport.pm ↑ Summary lib/BalanceOfPower/Commands/Role/TreatiesUnderLimit.pm »
1 package BalanceOfPower::Executive;
2 11 $BalanceOfPower::Executive::VERSION = '0.300010';
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 with 'BalanceOfPower::Role::Logger';
9  
10 11 ▶use BalanceOfPower::Constants ":all";
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use BalanceOfPower::Utils qw(as_active as_title);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use BalanceOfPower::Commands::BuildTroops;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶use BalanceOfPower::Commands::InMilitaryRange;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 11 ▶use BalanceOfPower::Commands::DeleteRoute;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 11 ▶use BalanceOfPower::Commands::MilitarySupport;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 11 ▶use BalanceOfPower::Commands::RebelMilitarySupport;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 11 ▶use BalanceOfPower::Commands::RecallRebelMilitarySupport;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 11 ▶use BalanceOfPower::Commands::RecallMilitarySupport;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 11 ▶use BalanceOfPower::Commands::ComTreaty;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 11 ▶use BalanceOfPower::Commands::NagTreaty;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 11 ▶use BalanceOfPower::Commands::LowerDisorder;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 11 ▶use BalanceOfPower::Commands::BoostProduction;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 11 ▶use BalanceOfPower::Commands::AddRoute;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 11 ▶use BalanceOfPower::Commands::EconomicAid;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 11 ▶use BalanceOfPower::Commands::DeclareWar;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 11 ▶use BalanceOfPower::Commands::AidInsurgents;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 11 ▶use BalanceOfPower::Commands::DiplomaticPressure;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 11 ▶use BalanceOfPower::Commands::MilitaryAid;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 11 ▶use BalanceOfPower::Commands::Progress;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 has actor => (
32 is => 'rw',
33 0 ▶ default => sub { undef }
Subroutine __ANON__: not called CC=1 SCAR=6.9
34 11 );
35  
36 has commands => (
37 is => 'ro',
38 0 ▶ default => sub { {} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 11 );
40  
41 sub init
42 {
43 0 ▶ my $self = shift;
Subroutine init: not called CC=1 SCAR=6.9
Pod undocumented
44 0 $self->log_name("bop-IA.log");
45 0 $self->delete_log();
46 0 $self->log_active(1);
47 0 my $world = shift;
48 0 my $command =
49 BalanceOfPower::Commands::BuildTroops->new( name => "BUILD TROOPS",
50 domestic_cost => ARMY_COST,
51 world => $world,
52 allowed_at_war => 1, );
53 0 $self->commands->{"BUILD TROOPS"} = $command;
54 0 $command =
55 BalanceOfPower::Commands::LowerDisorder->new( name => "LOWER DISORDER",
56 world => $world,
57 domestic_cost => RESOURCES_FOR_DISORDER );
58 0 $self->commands->{"LOWER DISORDER"} = $command;
59 0 $command =
60 BalanceOfPower::Commands::AddRoute->new( name => "ADD ROUTE",
61 world => $world,
62 export_cost => ADDING_TRADEROUTE_COST );
63 0 $self->commands->{"ADD ROUTE"} = $command;
64 0 $command =
65 BalanceOfPower::Commands::DeclareWar->new( name => "DECLARE WAR TO",
66 synonyms => ["DECLARE WAR"],
67 world => $world,
68 crisis_needed => 1 );
69 0 $self->commands->{"DECLARE WAR TO"} = $command;
70 0 $command =
71 BalanceOfPower::Commands::DeleteRoute->new( name => "DELETE TRADEROUTE",
72 synonyms => ["DELETE ROUTE"],
73 world => $world );
74 0 $self->commands->{"DELETE TRADEROUTE"} = $command;
75 0 $command =
76 BalanceOfPower::Commands::BoostProduction->new( name => "BOOST PRODUCTION",
77 world => $world,
78 );
79 0 $self->commands->{"BOOST PRODUCTION"} = $command;
80 0 $command =
81 BalanceOfPower::Commands::MilitarySupport->new( name => "MILITARY SUPPORT",
82 world => $world,
83 army_limit => { '>' => ARMY_FOR_SUPPORT }
84 );
85 0 $self->commands->{"MILITARY SUPPORT"} = $command;
86 0 $command =
87 BalanceOfPower::Commands::RecallMilitarySupport->new( name => "RECALL MILITARY SUPPORT",
88 synonyms => ["RECALL SUPPORT"],
89 world => $world,
90 allowed_at_war => 1,
91 );
92 0 $self->commands->{"RECALL MILITARY SUPPORT"} = $command;
93 0 $command =
94 BalanceOfPower::Commands::AidInsurgents->new( name => "AID INSURGENTS IN",
95 synonyms => ["AID INSURGENTS", "AID INSURGENCE"],
96 world => $world,
97 export_cost => AID_INSURGENTS_COST );
98 0 $self->commands->{"AID INSURGENTS IN"} = $command;
99 0 $command =
100 BalanceOfPower::Commands::ComTreaty->new( name => "TREATY COM WITH",
101 synonyms => ["COM TREATY",
102 "COM TREATY WITH",
103 "TREATY COM",
104 ],
105 world => $world,
106 prestige_cost => TREATY_PRESTIGE_COST,
107 treaty_limit => 1,
108 );
109 0 $self->commands->{"TREATY COM WITH"} = $command;
110 0 $command =
111 BalanceOfPower::Commands::NagTreaty->new( name => "TREATY NAG WITH",
112 synonyms => ["NAG TREATY",
113 "NAG TREATY WITH",
114 "TREATY NAG"
115 ],
116 world => $world,
117 prestige_cost => TREATY_PRESTIGE_COST,
118 treaty_limit => 1,
119 );
120 0 $self->commands->{"TREATY NAG WITH"} = $command;
121 0 $command =
122 BalanceOfPower::Commands::EconomicAid->new( name => "ECONOMIC AID FOR",
123 synonyms => ["ECONOMIC AID"],
124 world => $world,
125 export_cost => ECONOMIC_AID_COST,
126 );
127 0 $self->commands->{"ECONOMIC AID FOR"} = $command;
128 0 $command =
129 BalanceOfPower::Commands::RebelMilitarySupport->new( name => "REBEL MILITARY SUPPORT",
130 world => $world,
131 army_limit => { '>' => ARMY_FOR_SUPPORT }
132 );
133 0 $self->commands->{"REBEL MILITARY SUPPORT"} = $command;
134 0 $command =
135 BalanceOfPower::Commands::DiplomaticPressure->new( name => "DIPLOMATIC PRESSURE ON",
136 world => $world,
137 prestige_cost => DIPLOMATIC_PRESSURE_PRESTIGE_COST
138 );
139 0 $self->commands->{"DIPLOMATIC PRESSURE ON"} = $command;
140 0 $command =
141 BalanceOfPower::Commands::RecallRebelMilitarySupport->new( name => "RECALL REBEL MILITARY SUPPORT",
142 world => $world,
143 );
144 0 $self->commands->{"RECALL REBEL MILITARY SUPPORT"} = $command;
145 0 $command =
146 BalanceOfPower::Commands::MilitaryAid->new( name => "MILITARY AID FOR",
147 synonyms => ["MILITARY AID"],
148 world => $world,
149 export_cost => MILITARY_AID_COST,
150 );
151 0 $self->commands->{"MILITARY AID FOR"} = $command;
152 0 $command =
153 BalanceOfPower::Commands::Progress->new( name => "PROGRESS",
154 world => $world,
155 domestic_cost => PROGRESS_COST,
156 );
157 0 $self->commands->{"PROGRESS"} = $command;
158 }
159  
160  
161 sub recognize_command
162 {
163 0 ▶ my $self = shift;
Subroutine recognize_command: not called CC=4 SCAR=30.0
Pod undocumented
164 0 my $nation = shift;
165 0 my $query = shift;
166 0 my $actor = $self->actor;
167 0 for(keys %{$self->commands})
168 {
169 0 my $c = $self->commands->{$_};
170 0 $c->actor($actor);
171 0 ▶ if($c->recognize($query))
Branch: 1 branch
BranchTrueFalseTotal
if ($c->recognize($query)) 0 0 0
172 {
173 0 ▶ if($c->allowed())
Branch: 1 branch
BranchTrueFalseTotal
if ($c->allowed) { } 0 0 0
174 {
175 0 return $c->execute($query, $nation);
176 }
177 else
178 {
179 0 return { status => -1 };
180 }
181
182 }
183 }
184 0 return { status => 0 };
185 }
186  
187 sub decide
188 {
189 0 ▶ my $self = shift;
Subroutine decide: not called CC=4 SCAR=30.0
Pod undocumented
190 0 my $order = shift;
191 0 ▶ if(! exists $self->commands->{$order})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->commands->{$order}) 0 0 0
192 {
193 0 $self->log($self->actor . ": $order doesn't exists!");
194 0 return undef;
195 }
196 0 my $c = $self->commands->{$order};
197 0 $c->actor($self->actor);
198 0 ▶ if($c->allowed())
Branch: 1 branch
BranchTrueFalseTotal
if ($c->allowed) { } 0 0 0
199 {
200 0 my $command = $c->IA();
201 0 ▶ my $exit_log = $command ? $command : "KO";
Branch: 1 branch
BranchTrueFalseTotal
$command ? : 0 0 0
202 0 $self->log($self->actor . ": executing $order: $exit_log");
203 0 return $command;
204 }
205 else
206 {
207 0 $self->log($self->actor . ": $order not allowed");
208 0 return undef;
209 }
210 }
211  
212 sub allowed_orders
213 {
214 0 ▶ my $self = shift;
Subroutine allowed_orders: not called CC=3 SCAR=24.8
Pod undocumented
215 0 my @out;
216 0 for(keys %{$self->commands})
217 {
218 0 my $c = $self->commands->{$_};
219 0 $c->actor($self->actor);
220 0 ▶ if( $c->allowed() )
Branch: 1 branch
BranchTrueFalseTotal
if ($c->allowed) 0 0 0
221 {
222 0 push @out, $c->print;
223 }
224 }
225 0 return @out;
226 }
227  
228 sub print_orders
229 {
230 0 ▶ my $self = shift;
Subroutine print_orders: not called CC=3 SCAR=24.8
Pod undocumented
231 0 my $out = as_title("ORDERS FOR " . $self->actor);
232 0 $out .= "\n\n";
233 0 for(keys %{$self->commands})
234 {
235 0 my $c = $self->commands->{$_};
236 0 $c->actor($self->actor);
237 0 ▶ if( $c->allowed() )
Branch: 1 branch
BranchTrueFalseTotal
if ($c->allowed) { } 0 0 0
238 {
239 0 $out .= as_active($c->print) . "\n";
240 }
241 else
242 {
243 0 $out .= $c->print . "\n";
244 }
245 }
246 0 return $out;
247 }
248  
249 11 1;
« blib/lib/BalanceOfPower/Commands/RecallRebelMilitarySupport.pm ↑ Summary lib/BalanceOfPower/Commands/Role/TreatiesUnderLimit.pm »