lib/BalanceOfPower/Commands/Role/Command.pm

filter: Statementstmt 81.8% 63 / 77 Branchbran 66.6% 24 / 36 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 84.6% 11 / 13 Podpod 0.0% 0 / 7 totaltotal 73.6% 98 / 133 CC 20 SCAR 22.0
CC
20
Cov
77%
allowed
14.3
extract_argument
12.5
recognize
2.0
CRAP 9.0
« blib/lib/BalanceOfPower/Role/Historian.pm ↑ Summary blib/lib/BalanceOfPower/Relations/War.pm »
1 package BalanceOfPower::Commands::Role::Command;
2 11 $BalanceOfPower::Commands::Role::Command::VERSION = '0.200000';
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 594 ▶ default => sub { [] }
Subroutine __ANON__: called CC=1 SCAR=0.0
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 1122 ▶ default => sub { {} }
Subroutine __ANON__: called CC=1 SCAR=0.0
42 11 );
43 has army_limit => (
44 is => 'ro',
45 990 ▶ default => sub { {} }
Subroutine __ANON__: called CC=1 SCAR=0.0
46 11 );
47 11 has treaty_limit => (
48 is => 'ro',
49 default => 0
50 );
51  
52 sub get_nation
53 {
54 381 ▶ my $self = shift;
Subroutine get_nation: called CC=1 SCAR=0.0
Pod undocumented
55 381 return $self->world->get_nation($self->actor);
56 }
57  
58 sub allowed
59 {
60 218 ▶ my $self = shift;
Subroutine allowed: called CC=13 SCAR=26.6
Pod undocumented
61 218 my $nation = $self->get_nation();
62 218 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
if $nation->internal_disorder_status eq "Civil war" 0 218 218
63 if($nation->internal_disorder_status() eq 'Civil war');
64 218 ▶ if(! $self->allowed_at_war)
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->allowed_at_war) 189 29 218
65 {
66 189 ▶ if($self->world->at_war($self->actor))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->world->at_war($self->actor)) 8 181 189
67 {
68 8 return 0;
69 }
70 }
71 210 ▶ if(exists $self->production_limit->{'<'})
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->production_limit->{'<'}) { } 0 210 210
elsif (exists $self->production_limit->{'>'}) { } 0 210 210
72 {
73 0 return $nation->production() <= $self->production_limit->{'<'};
74 }
75 elsif(exists $self->production_limit->{'>'})
76 {
77 0 return $nation->production() >= $self->production_limit->{'>'};
78 }
79 210 ▶ if(exists $self->army_limit->{'<'})
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->army_limit->{'<'}) { } 0 210 210
elsif (exists $self->army_limit->{'>'}) { } 27 183 210
80 {
81 0 return $nation->army() <= $self->army_limit->{'<'};
82 }
83 elsif(exists $self->army_limit->{'>'})
84 {
85 27 return $nation->army() >= $self->army_limit->{'>'};
86 }
87 183 ▶ if($nation->production_for_domestic < $self->domestic_cost)
Branch: 1 branch
BranchTrueFalseTotal
if ($nation->production_for_domestic < $self->domestic_cost) 7 176 183
88 {
89 7 return 0;
90 }
91 176 ▶ if($nation->production_for_export < $self->export_cost)
Branch: 1 branch
BranchTrueFalseTotal
if ($nation->production_for_export < $self->export_cost) 5 171 176
92 {
93 5 return 0;
94 }
95 171 ▶ if($nation->prestige < $self->prestige_cost)
Branch: 1 branch
BranchTrueFalseTotal
if ($nation->prestige < $self->prestige_cost) 7 164 171
96 {
97 7 return 0;
98 }
99 164 ▶ if($self->treaty_limit == 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->treaty_limit == 1) 24 140 164
100 {
101 24 ▶ 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 24 24
102 {
103 0 return 0;
104 }
105 }
106 164 return 1;
107 }
108  
109 sub extract_argument
110 {
111 5 ▶ my $self = shift;
Subroutine extract_argument: called CC=7 SCAR=25.2
Pod undocumented
112 5 my $query = shift;
113 5 my $extract = shift;
114 5 $query = uc $query; #Commands are always all caps
115 5 ▶ $extract = 1 if(! defined $extract);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $extract 0 5 5
116 5 my $name = $self->name;
117 5 ▶ if($query =~ /^$name( (.*))?$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($query =~ /^$name( (.*))?$/) 0 5 5
118 {
119 0 ▶ if($extract)
Branch: 1 branch
BranchTrueFalseTotal
if ($extract) { } 0 0 0
120 {
121 0 return $2;
122 }
123 else
124 {
125 0 return 1;
126 }
127 }
128 5 foreach my $syn (@{$self->synonyms})
129 {
130 5 ▶ if($query =~ /^$syn( (.*))?/)
Branch: 1 branch
BranchTrueFalseTotal
if ($query =~ /^$syn( (.*))?/) 0 5 5
131 {
132 0 ▶ if($extract)
Branch: 1 branch
BranchTrueFalseTotal
if ($extract) { } 0 0 0
133 {
134 0 return $2;
135 }
136 else
137 {
138 0 return 1;
139 }
140 }
141 }
142 5 return undef;
143 }
144  
145 sub recognize
146 {
147 6 ▶ my $self = shift;
Subroutine recognize: called CC=2 SCAR=6.9
Pod undocumented
148 6 my $query = shift;
149 6 ▶ if($self->extract_argument($query, 0))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->extract_argument($query, 0)) { } 1 5 6
150 {
151 1 return 1;
152 }
153 else
154 {
155 5 return 0;
156 }
157 }
158  
159 sub execute
160 {
161 1 ▶ my $self = shift;
Subroutine execute: called CC=1 SCAR=0.0
Pod undocumented
162 1 my $query = shift;
163 1 return { status => 1, command => uc $query };
164 }
165  
166 sub print
167 {
168 0 ▶ my $self = shift;
Subroutine print: not called CC=1 SCAR=6.9
Pod undocumented
169 0 return $self->name;
170 }
171  
172 sub IA
173 {
174 0 ▶ my $self = shift;
Subroutine IA: not called CC=1 SCAR=6.9
Pod undocumented
175 0 return $self->name;
176 }
177  
178  
179 11 1;
« blib/lib/BalanceOfPower/Role/Historian.pm ↑ Summary blib/lib/BalanceOfPower/Relations/War.pm »