File Coverage

lib/BalanceOfPower/Commands/DeleteRoute.pm
Criterion Covered Total %
statement 12 38 31.5
branch 2 12 16.6
condition n/a
subroutine 3 5 60.0
pod 0 3 0.0
total 17 58 29.3


line stmt bran cond sub pod time code
1             package BalanceOfPower::Commands::DeleteRoute;
2             $BalanceOfPower::Commands::DeleteRoute::VERSION = '0.400110';
3 13     13   44 use Moo;
  13         14  
  13         52  
4              
5 13     13   2430 use BalanceOfPower::Utils qw( prev_turn );
  13         17  
  13         4369  
6              
7             extends 'BalanceOfPower::Commands::TargetRoute';
8              
9             sub get_available_targets
10             {
11 0     0 0 0 my $self = shift;
12 0         0 my @targets = $self->SUPER::get_available_targets();
13 0         0 my $nation = $self->actor;
14 0         0 @targets = grep {! $self->world->exists_treaty_by_type($nation, $_, 'commercial') } @targets;
  0         0  
15 0         0 return @targets;
16             }
17              
18             sub execute
19             {
20 0     0 0 0 my $self = shift;
21 0         0 my $query = shift;
22 0         0 my $nation = shift;
23 0         0 my $result = $self->SUPER::execute($query, $nation);
24 0 0       0 if($result->{status} == 1)
25             {
26 0         0 my $command = $result->{command};
27 0         0 $command .= "->" . $self->actor;
28 0         0 return { status => 1, command => $command };
29             }
30             else
31             {
32 0         0 return $result;
33             }
34             }
35              
36             sub IA
37             {
38 8     8 0 6 my $self = shift;
39 8         19 my $actor = $self->get_nation();
40              
41 8         30 my $prev_year = prev_turn($actor->current_year);
42 8         22 my @trade_ko = $actor->get_events("TRADE KO", $prev_year);
43 8 50       25 if(@trade_ko > 1)
    50          
44             {
45 0         0 for(@trade_ko)
46             {
47 0         0 my $to_delete = $_;
48 0         0 $to_delete =~ s/TRADE KO //;
49 0 0       0 if(! $self->world->exists_treaty_by_type($actor->name, $to_delete, 'commercial'))
50             {
51 0         0 return "DELETE TRADEROUTE " . $actor->name . "->" . $to_delete;
52             }
53             }
54             }
55             elsif(@trade_ko == 1)
56             {
57 0         0 my @older_trade_ko = $actor->get_events("TRADE KO", prev_turn($prev_year));
58 0 0       0 if(@older_trade_ko > 0)
59             {
60 0         0 my $to_delete = $trade_ko[$#trade_ko];
61 0         0 $to_delete =~ s/TRADE KO //;
62 0 0       0 if(! $self->world->exists_treaty_by_type($actor->name, $to_delete, 'commercial'))
63             {
64 0         0 return "DELETE TRADEROUTE " . $actor->name . "->" . $to_delete;
65             }
66             }
67             }
68 8         13 return undef;
69             }
70            
71            
72             1;