lib/BalanceOfPower/Relations/War.pm

filter: Statementstmt 70.5% 48 / 68 Branchbran 58.3% 7 / 12 Conditioncond 20.0% 1 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 70.0% 7 / 10 Podpod 0.0% 0 / 5 totaltotal 61.1% 63 / 103 CC 10 SCAR 15.4
CC
10
Cov
66%
dump
12.0
print_history
5.6
print
4.0
CRAP 4.7
« blib/lib/BalanceOfPower/Commands/EconomicAid.pm ↑ Summary lib/BalanceOfPower/Commands/RebelMilitarySupport.pm »
1 package BalanceOfPower::Relations::War;
2 11 $BalanceOfPower::Relations::War::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  
6 11 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use BalanceOfPower::Utils qw( from_to_turns );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use Term::ANSIColor;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 11 with 'BalanceOfPower::Relations::Role::Relation';
11 11 with 'BalanceOfPower::Role::Reporter';
12  
13 11 has attack_leader => (
14 is => 'rw',
15 default => ""
16 );
17 11 has war_id => (
18 is => 'rw',
19 default => ""
20 );
21 11 has name => (
22 is => 'rw',
23 default => "WAR"
24 );
25 11 has node1_faction => (
26 is => 'rw',
27 default => ""
28 );
29 11 has node2_faction => (
30 is => 'rw',
31 default => ""
32 );
33 11 has start_date => (
34 is => 'ro',
35 default => ""
36 );
37 11 has end_date => (
38 is => 'rw',
39 default => ""
40 );
41 11 has current_year => (
42 is => 'rw',
43 default => ""
44 );
45  
46  
47 sub bidirectional
48 {
49 0 ▶ return 0;
Subroutine bidirectional: not called CC=1 SCAR=6.9
Pod undocumented
50 }
51 sub print
52 {
53 2 ▶ my $self = shift;
Subroutine print: called CC=4 SCAR=13.9
Pod undocumented
54 2 my $army_node1 = shift;
55 2 my $army_node2 = shift;
56 2 ▶ my $army_node1_label = $army_node1 ? "[".$army_node1."] " : "";
Branch: 1 branch
BranchTrueFalseTotal
$army_node1 ? : 1 1 2
57 2 ▶ my $army_node2_label = $army_node2 ? " [".$army_node2."]" : "";
Branch: 1 branch
BranchTrueFalseTotal
$army_node2 ? : 1 1 2
58 2 my $node1 = $army_node1_label . $self->node1;
59 2 my $node2 = $self->node2 . $army_node2_label;
60 2 ▶ if($self->node1_faction == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->node1_faction == 0) { } 2 0 2
61 {
62 2 $node1 = color("bold") . $node1 . color("reset");
63 }
64 else
65 {
66 0 $node2 = color("bold") . $node2 . color("reset");
67 }
68 2 return $node1 . " -> " . $node2;
69 }
70 sub print_history
71 {
72 1 ▶ my $self = shift;
Subroutine print_history: called CC=5 SCAR=17.2
Pod undocumented
73 1 my $out = "";
74 #$out .= "### WAR " . $self->war_id . "\n";
75 1 $out .= $self->node1;
76 1 ▶ if($self->attack_leader && $self->attack_leader ne $self->node1)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->attack_leader and $self->attack_leader ne $self->node1) 0 1 1
Condition33%1/3
$self->attack_leader and $self->attack_leader ne $self->node1
!ll&&!rl&&r
010
MC/DC0%0/2
$self->attack_leader and $self->attack_leader ne $self->node1
$self->attack_leader $self->attack_leader ne $self->node1
Truth table33%1/3
A and B
A= $self->attack_leaderB= $self->attack_leader ne $self->node1
ABresult
0X0
100
111
77 {
78 0 $out .= " (" . $self->attack_leader . ")";
79 }
80 1 $out .= " => " . $self->node2 . "\n";
81 1 $out .= "*** War started in " . $self->start_date . " ***\n";
82 1 $out .= $self->print_turn_events_notitle("START");
83 1 for(from_to_turns($self->start_date, $self->end_date))
84 {
85 14 my $events = $self->print_turn_events_inline_year($_);
86 14 ▶ if($events)
Branch: 1 branch
BranchTrueFalseTotal
if ($events) 0 14 14
87 {
88 0 $out .= $events;
89 }
90 }
91 1 $out .= "*** War ended in " . $self->end_date . " ***\n";
92 1 return $out;
93 }
94 sub dump
95 {
96 0 ▶ my $self = shift;
Subroutine dump: not called CC=3 SCAR=24.8
Pod undocumented
97 0 my $io = shift;
98 0 ▶ my $indent = shift || "";
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
99 0 print {$io} $indent . join(";", $self->node1, $self->node2, $self->attack_leader,
100 $self->war_id, $self->name, $self->node1_faction, $self->node2_faction,
101 $self->start_date, $self->end_date, $self->current_year ). "\n";
102 0 ▶ if($self->events)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->events) 0 0 0
103 {
104 0 $self->dump_events($io, $indent . " ");
105 }
106 }
107 sub load
108 {
109 0 ▶ my $self = shift;
Subroutine load: not called CC=1 SCAR=6.9
Pod undocumented
110 0 my $data = shift;
111 0 my $war_line = ( split /\n/, $data )[0];
112 0 $war_line =~ s/^\s+//;
113 0 chomp $war_line;
114 0 my ($node1, $node2, $attack_leader, $war_id, $name, $node1_faction, $node2_faction, $start_date, $end_date, $current_year) = split ";", $war_line;
115 0 $data =~ s/^.*?\n//;
116 0 my $events = $self->load_events($data);
117 0 return $self->new(node1 => $node1, node2 => $node2,
118 attack_leader => $attack_leader,
119 war_id => $war_id, name => $name,
120 node1_faction => $node1_faction, node2_faction => $node2_faction,
121 start_date => $start_date, end_date => $end_date, current_year => $current_year,
122 events => $events);
123 }
124  
125  
126  
127 11 1;
« blib/lib/BalanceOfPower/Commands/EconomicAid.pm ↑ Summary lib/BalanceOfPower/Commands/RebelMilitarySupport.pm »