File Coverage

lib/BalanceOfPower/Commands/ComTreaty.pm
Criterion Covered Total %
statement 18 26 69.2
branch 1 2 50.0
condition 1 3 33.3
subroutine 3 4 75.0
pod 0 2 0.0
total 23 37 62.1


line stmt bran cond sub pod time code
1             package BalanceOfPower::Commands::ComTreaty;
2             $BalanceOfPower::Commands::ComTreaty::VERSION = '0.400110';
3 13     13   45 use Moo;
  13         13  
  13         52  
4              
5 13     13   2430 use BalanceOfPower::Utils qw( prev_turn );
  13         26  
  13         3070  
6              
7             extends 'BalanceOfPower::Commands::TargetRoute';
8             with 'BalanceOfPower::Commands::Role::TreatiesUnderLimit';
9              
10             sub get_available_targets
11             {
12 0     0 0 0 my $self = shift;
13 0         0 my @targets = $self->SUPER::get_available_targets();
14 0         0 my $nation = $self->actor;
15 0         0 @targets = grep {! $self->world->exists_treaty($nation, $_) } @targets;
  0         0  
16 0         0 @targets = grep {! $self->world->diplomacy_status($nation, $_) ne 'HATE' } @targets;
  0         0  
17 0         0 return $self->nations_under_treaty_limit(@targets);
18             }
19              
20             sub IA
21             {
22 4     4 0 6 my $self = shift;
23 4         8 my $actor = $self->get_nation();
24 4         14 my $prev_year = prev_turn($actor->current_year);
25 4         12 my @trade_ok = $actor->get_events("TRADE OK", $prev_year);
26 4         7 for(@trade_ok)
27             {
28 1         2 my $route = $_;
29 1         4 $route =~ s/^TRADE OK //;
30 1         4 $route =~ s/ \[.*$//;
31 1         6 my $status = $self->world->diplomacy_status($actor->name, $route);
32 1 50 33     6 if(! $self->world->exists_treaty($actor->name, $route) && $status ne 'HATE')
33             {
34 1         4 return "TREATY COM WITH " . $route;
35             }
36             }
37 3         6 return undef;
38             }
39              
40             1;