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

filter: Statementstmt 0.0% 0 / 71 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 105 CC 8 SCAR 31.1
CC
8
Cov
0%
output
56.0
dump
6.0
bidirectional
2.0
CRAP 22.3
1 package BalanceOfPower::Relations::War;
2 $BalanceOfPower::Relations::War::VERSION = '0.300010';
3 use strict;
4 use v5.10;
5  
6 use Moo;
7 use BalanceOfPower::Utils qw( from_to_turns as_html_evidenced );
8 use Term::ANSIColor;
9 use HTML::Entities;
10  
11 with 'BalanceOfPower::Relations::Role::Relation';
12 with 'BalanceOfPower::Role::Reporter';
13  
14 has attack_leader => (
15 is => 'rw',
16 default => ""
17 );
18 has war_id => (
19 is => 'rw',
20 default => ""
21 );
22 has name => (
23 is => 'rw',
24 default => "WAR"
25 );
26 has node1_faction => (
27 is => 'rw',
28 default => ""
29 );
30 has node2_faction => (
31 is => 'rw',
32 default => ""
33 );
34 has start_date => (
35 is => 'ro',
36 default => ""
37 );
38 has end_date => (
39 is => 'rw',
40 default => ""
41 );
42 has current_year => (
43 is => 'rw',
44 default => ""
45 );
46  
47  
48 sub bidirectional
49 {
50 return 0;
51 }
52  
53 sub print
54 {
55 my $self = shift;
56 my $army_node1 = shift;
57 my $army_node2 = shift;
58 return $self->output($army_node1, $army_node2, 'print');
59 }
60 sub html
61 {
62 my $self = shift;
63 my $army_node1 = shift;
64 my $army_node2 = shift;
65 return $self->output($army_node1, $army_node2, 'html');
66 }
67  
68  
69  
70 sub output
71 {
72 my $self = shift;
73 my $army_node1 = shift;
74 my $army_node2 = shift;
75 my $mode = shift;
76 my $army_node1_label = $army_node1 ? "[".$army_node1."] " : "";
77 my $army_node2_label = $army_node2 ? " [".$army_node2."]" : "";
78 my $node1 = $army_node1_label . $self->node1;
79 my $node2 = $self->node2 . $army_node2_label;
80 if($mode eq 'print')
81 {
82 if($self->node1_faction == 0)
83 {
84 $node1 = color("bold") . $node1 . color("reset");
85 }
86 else
87 {
88 $node2 = color("bold") . $node2 . color("reset");
89 }
90 return $node1 . " -> " . $node2;
91 }
92 elsif($mode eq 'html')
93 {
94 if($self->node1_faction == 0)
95 {
96 $node1 = as_html_evidenced($node1);
97 }
98 else
99 {
100 $node2 = as_html_evidenced($node2);
101 }
102 return $node1 . " -> " . $node2;
103 }
104
105
106
107 }
108 sub dump
109 {
110 my $self = shift;
111 my $io = shift;
112 my $indent = shift || "";
113 print {$io} $indent . join(";", $self->node1, $self->node2, $self->attack_leader,
114 $self->war_id, $self->name, $self->node1_faction, $self->node2_faction,
115 $self->start_date, $self->end_date, $self->current_year ). "\n";
116 if($self->events)
117 {
118 $self->dump_events($io, $indent . " ");
119 }
120 }
121 sub load
122 {
123 my $self = shift;
124 my $data = shift;
125 my $war_line = ( split /\n/, $data )[0];
126 $war_line =~ s/^\s+//;
127 chomp $war_line;
128 my ($node1, $node2, $attack_leader, $war_id, $name, $node1_faction, $node2_faction, $start_date, $end_date, $current_year) = split ";", $war_line;
129 $data =~ s/^.*?\n//;
130 my $events = $self->load_events($data);
131 return $self->new(node1 => $node1, node2 => $node2,
132 attack_leader => $attack_leader,
133 war_id => $war_id, name => $name,
134 node1_faction => $node1_faction, node2_faction => $node2_faction,
135 start_date => $start_date, end_date => $end_date, current_year => $current_year,
136 events => $events);
137 }
138  
139  
140  
141 1;