lib/BalanceOfPower/Commands/Role/Command.pm

filter: Statementstmt 26.9% 21 / 78 Branchbran 0.0% 0 / 36 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 21.4% 3 / 14 Podpod 0.0% 0 / 8 totaltotal 17.6% 24 / 136 CC 20 SCAR 44.4
CC
20
Cov
18%
allowed
182.0
extract_argument
56.0
recognize
6.0
CRAP 84.5
« blib/lib/BalanceOfPower/Commands/Role/Command.pm ↑ Summary lib/BalanceOfPower/Role/Broker.pm »
1 package BalanceOfPower::Commands::Role::Command;
2 11 $BalanceOfPower::Commands::Role::Command::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 11 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 has name => (
8 is => 'ro',
9 default => 'DO NOTHING'
10 );
11 11 has actor => (
12 is => 'rw',
13 );
14  
15 11 has world => (
16 is => 'ro'
17 );
18 has synonyms => (
19 is => 'rw',
20 0 ▶ default => sub { [] }
Subroutine __ANON__: not called CC=1 SCAR=6.9
21 11 );
22 11 has export_cost => (
23 is => 'ro',
24 default => 0
25 );
26 11 has domestic_cost => (
27 is => 'ro',
28 default => 0
29 );
30 11 has prestige_cost => (
31 is => 'ro',
32 default => 0
33 );
34  
35 11 has allowed_at_war => (
36 is => 'ro',
37 default => 0
38 );
39 has production_limit => (
40 is => 'ro',
41 0 ▶ default => sub { {} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
42 11 );
43 has army_limit => (
44 is => 'ro',
45 0 ▶ default => sub { {} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
46 11 );
47 11 has treaty_limit => (
48 is => 'ro',
49 default => 0
50 );
51  
52 sub has_argument
53 {
54 0 ▶ return 1;
Subroutine has_argument: not called CC=1 SCAR=6.9
Pod undocumented
55 }
56  
57 sub get_nation
58 {
59 0 ▶ my $self = shift;
Subroutine get_nation: not called CC=1 SCAR=6.9
Pod undocumented
60 0 return $self->world->get_nation($self->actor);
61 }
62  
63 sub allowed
64 {
65 0 ▶ my $self = shift;
Subroutine allowed: not called CC=13 SCAR=52.0
Pod undocumented
66 0 my $nation = $self->get_nation();
67 0 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
if $nation->internal_disorder_status eq "Civil war" 0 0 0
68 if($nation->internal_disorder_status() eq 'Civil war');
69 0 ▶ if(! $self->allowed_at_war)
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->allowed_at_war) 0 0 0
70 {
71 0 ▶ if($self->world->at_war($self->actor))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->world->at_war($self->actor)) 0 0 0
72 {
73 0 return 0;
74 }
75 }
76 0 ▶ if(exists $self->production_limit->{'<'})
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->production_limit->{'<'}) { } 0 0 0
elsif (exists $self->production_limit->{'>'}) { } 0 0 0
77 {
78 0 return $nation->production() <= $self->production_limit->{'<'};
79 }
80 elsif(exists $self->production_limit->{'>'})
81 {
82 0 return $nation->production() >= $self->production_limit->{'>'};
83 }
84 0 ▶ if(exists $self->army_limit->{'<'})
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->army_limit->{'<'}) { } 0 0 0
elsif (exists $self->army_limit->{'>'}) { } 0 0 0
85 {
86 0 return $nation->army() <= $self->army_limit->{'<'};
87 }
88 elsif(exists $self->army_limit->{'>'})
89 {
90 0 return $nation->army() >= $self->army_limit->{'>'};
91 }
92 0 ▶ if($nation->production_for_domestic < $self->domestic_cost)
Branch: 1 branch
BranchTrueFalseTotal
if ($nation->production_for_domestic < $self->domestic_cost) 0 0 0
93 {
94 0 return 0;
95 }
96 0 ▶ if($nation->production_for_export < $self->export_cost)
Branch: 1 branch
BranchTrueFalseTotal
if ($nation->production_for_export < $self->export_cost) 0 0 0
97 {
98 0 return 0;
99 }
100 0 ▶ if($nation->prestige < $self->prestige_cost)
Branch: 1 branch
BranchTrueFalseTotal
if ($nation->prestige < $self->prestige_cost) 0 0 0
101 {
102 0 return 0;
103 }
104 0 ▶ if($self->treaty_limit == 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->treaty_limit == 1) 0 0 0
105 {
106 0 ▶ if($self->world->get_treaties_for_nation($nation->name) >= $nation->treaty_limit)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->world->get_treaties_for_nation($nation->name) >= $nation->treaty_limit) 0 0 0
107 {
108 0 return 0;
109 }
110 }
111 0 return 1;
112 }
113  
114 sub extract_argument
115 {
116 0 ▶ my $self = shift;
Subroutine extract_argument: not called CC=7 SCAR=40.3
Pod undocumented
117 0 my $query = shift;
118 0 my $extract = shift;
119 0 $query = uc $query; #Commands are always all caps
120 0 ▶ $extract = 1 if(! defined $extract);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $extract 0 0 0
121 0 my $name = $self->name;
122 0 ▶ if($query =~ /^$name( (.*))?$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($query =~ /^$name( (.*))?$/) 0 0 0
123 {
124 0 ▶ if($extract)
Branch: 1 branch
BranchTrueFalseTotal
if ($extract) { } 0 0 0
125 {
126 0 return $2;
127 }
128 else
129 {
130 0 return 1;
131 }
132 }
133 0 foreach my $syn (@{$self->synonyms})
134 {
135 0 ▶ if($query =~ /^$syn( (.*))?/)
Branch: 1 branch
BranchTrueFalseTotal
if ($query =~ /^$syn( (.*))?/) 0 0 0
136 {
137 0 ▶ if($extract)
Branch: 1 branch
BranchTrueFalseTotal
if ($extract) { } 0 0 0
138 {
139 0 return $2;
140 }
141 else
142 {
143 0 return 1;
144 }
145 }
146 }
147 0 return undef;
148 }
149  
150 sub recognize
151 {
152 0 ▶ my $self = shift;
Subroutine recognize: not called CC=2 SCAR=17.9
Pod undocumented
153 0 my $query = shift;
154 0 ▶ if($self->extract_argument($query, 0))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->extract_argument($query, 0)) { } 0 0 0
155 {
156 0 return 1;
157 }
158 else
159 {
160 0 return 0;
161 }
162 }
163  
164 sub execute
165 {
166 0 ▶ my $self = shift;
Subroutine execute: not called CC=1 SCAR=6.9
Pod undocumented
167 0 my $query = shift;
168 0 return { status => 1, command => uc $query };
169 }
170  
171 sub print
172 {
173 0 ▶ my $self = shift;
Subroutine print: not called CC=1 SCAR=6.9
Pod undocumented
174 0 return $self->name;
175 }
176  
177 sub IA
178 {
179 0 ▶ my $self = shift;
Subroutine IA: not called CC=1 SCAR=6.9
Pod undocumented
180 0 return $self->name;
181 }
182  
183  
184 11 1;
« blib/lib/BalanceOfPower/Commands/Role/Command.pm ↑ Summary lib/BalanceOfPower/Role/Broker.pm »