blib/lib/BalanceOfPower/Relations/War.pm untested

filter: Statementstmt 0.0% 0 / 68 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 5 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 100 CC 7 SCAR 21.8
CC
7
Cov
0%
print
20.0
print_history
12.0
dump
6.0
CRAP 8.9
1 package BalanceOfPower::Relations::War;
2 $BalanceOfPower::Relations::War::VERSION = '0.200000';
3 use strict;
4 use v5.10;
5  
6 use Moo;
7 use BalanceOfPower::Utils qw( from_to_turns );
8 use Term::ANSIColor;
9  
10 with 'BalanceOfPower::Relations::Role::Relation';
11 with 'BalanceOfPower::Role::Reporter';
12  
13 has attack_leader => (
14 is => 'rw',
15 default => ""
16 );
17 has war_id => (
18 is => 'rw',
19 default => ""
20 );
21 has name => (
22 is => 'rw',
23 default => "WAR"
24 );
25 has node1_faction => (
26 is => 'rw',
27 default => ""
28 );
29 has node2_faction => (
30 is => 'rw',
31 default => ""
32 );
33 has start_date => (
34 is => 'ro',
35 default => ""
36 );
37 has end_date => (
38 is => 'rw',
39 default => ""
40 );
41 has current_year => (
42 is => 'rw',
43 default => ""
44 );
45  
46  
47 sub bidirectional
48 {
49 return 0;
50 }
51 sub print
52 {
53 my $self = shift;
54 my $army_node1 = shift;
55 my $army_node2 = shift;
56 my $army_node1_label = $army_node1 ? "[".$army_node1."] " : "";
57 my $army_node2_label = $army_node2 ? " [".$army_node2."]" : "";
58 my $node1 = $army_node1_label . $self->node1;
59 my $node2 = $self->node2 . $army_node2_label;
60 if($self->node1_faction == 0)
61 {
62 $node1 = color("bold") . $node1 . color("reset");
63 }
64 else
65 {
66 $node2 = color("bold") . $node2 . color("reset");
67 }
68 return $node1 . " -> " . $node2;
69 }
70 sub print_history
71 {
72 my $self = shift;
73 my $out = "";
74 #$out .= "### WAR " . $self->war_id . "\n";
75 $out .= $self->node1;
76 if($self->attack_leader && $self->attack_leader ne $self->node1)
77 {
78 $out .= " (" . $self->attack_leader . ")";
79 }
80 $out .= " => " . $self->node2 . "\n";
81 $out .= "*** War started in " . $self->start_date . " ***\n";
82 $out .= $self->print_turn_events_notitle("START");
83 for(from_to_turns($self->start_date, $self->end_date))
84 {
85 my $events = $self->print_turn_events_inline_year($_);
86 if($events)
87 {
88 $out .= $events;
89 }
90 }
91 $out .= "*** War ended in " . $self->end_date . " ***\n";
92 return $out;
93 }
94 sub dump
95 {
96 my $self = shift;
97 my $io = shift;
98 my $indent = shift || "";
99 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 if($self->events)
103 {
104 $self->dump_events($io, $indent . " ");
105 }
106 }
107 sub load
108 {
109 my $self = shift;
110 my $data = shift;
111 my $war_line = ( split /\n/, $data )[0];
112 $war_line =~ s/^\s+//;
113 chomp $war_line;
114 my ($node1, $node2, $attack_leader, $war_id, $name, $node1_faction, $node2_faction, $start_date, $end_date, $current_year) = split ";", $war_line;
115 $data =~ s/^.*?\n//;
116 my $events = $self->load_events($data);
117 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 1;