File Coverage

lib/BalanceOfPower/Targets/Fall.pm
Criterion Covered Total %
statement 22 42 52.3
branch 3 4 75.0
condition 2 5 40.0
subroutine 5 10 50.0
pod 0 8 0.0
total 32 69 46.3


line stmt bran cond sub pod time code
1             package BalanceOfPower::Targets::Fall;
2             $BalanceOfPower::Targets::Fall::VERSION = '0.400110';
3 13     13   48 use Moo;
  13         16  
  13         54  
4              
5             with "BalanceOfPower::Targets::Role::Target";
6              
7             has government_id => (
8             is => 'ro'
9             );
10              
11 13     13   2709 use constant INTERNAL_DISORDER_LIMIT_FOR_CHOOSE => 40;
  13         19  
  13         5595  
12              
13              
14              
15             sub type
16             {
17 0     0 0 0 return "FALL";
18             }
19             sub name
20             {
21 1     1 0 1 my $self = shift;
22 1         6 return "Fall of " . $self->target_obj->name
23             }
24             sub description
25             {
26 0     0 0 0 return "Make government fall";
27             }
28             sub achieved
29             {
30 8     8 0 8 my $self = shift;
31 8         5 my $world = shift;
32 8         41 return $self->target_obj->government_id > $self->government_id;
33             }
34             sub select_random_target
35             {
36 2     2 0 21 my $self = shift;
37 2         4 my $world = shift;
38 2         3 my @possible_targets = ();
39 2         2 for(@{$world->nations})
  2         10  
40             {
41 11         7 my $n = $_;
42 11 100 66     28 if((! $world->war_busy($n->name)) &&
43             $n->internal_disorder < INTERNAL_DISORDER_LIMIT_FOR_CHOOSE )
44             {
45 9         18 push @possible_targets, $n;
46             }
47             }
48 2 50       8 if(@possible_targets > 0)
49             {
50 2         34 @possible_targets = $world->shuffle("Choosing FALL target", @possible_targets);
51 2         8 return $possible_targets[0];
52             }
53             else
54             {
55 0           return undef;
56             }
57             }
58             sub dump
59             {
60 0     0 0   my $self = shift;
61 0           my $io = shift;
62 0   0       my $indent = shift || "";
63 0           print {$io} $indent .
  0            
64             join(";", "FALL", $self->target_obj->name, $self->government_id, $self->countdown) . "\n";
65             }
66             sub load_target
67             {
68 0     0 0   my $self = shift;
69 0           my $world = shift;
70 0           my $nation_obj = $world->get_nation($self->target_to_load);
71 0           $self->target_obj($nation_obj);
72             }
73             sub load
74             {
75 0     0 0   my $self = shift;
76 0           my $data = shift;
77 0           my $f_line = ( split /\n/, $data )[0];
78 0           $f_line =~ s/^\s+//;
79 0           chomp $f_line;
80 0           my ($type, $nation, $government, $countdown) = split ";", $f_line;
81 0           $data =~ s/^.*?\n//;
82 0           return $self->new( target_to_load => $nation, government_id => $government, countdown => $countdown);
83             }
84             1;