| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package BalanceOfPower::Relations::War; | 
| 2 |  |  |  |  |  |  | $BalanceOfPower::Relations::War::VERSION = '0.400115'; | 
| 3 | 13 |  |  | 13 |  | 71 | use strict; | 
|  | 13 |  |  |  |  | 29 |  | 
|  | 13 |  |  |  |  | 360 |  | 
| 4 | 13 |  |  | 13 |  | 137 | use v5.10; | 
|  | 13 |  |  |  |  | 38 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 13 |  |  | 13 |  | 63 | use Moo; | 
|  | 13 |  |  |  |  | 34 |  | 
|  | 13 |  |  |  |  | 81 |  | 
| 7 | 13 |  |  | 13 |  | 3336 | use BalanceOfPower::Utils qw( from_to_turns as_html_evidenced ); | 
|  | 13 |  |  |  |  | 31 |  | 
|  | 13 |  |  |  |  | 763 |  | 
| 8 | 13 |  |  | 13 |  | 60 | use Term::ANSIColor; | 
|  | 13 |  |  |  |  | 20 |  | 
|  | 13 |  |  |  |  | 614 |  | 
| 9 | 13 |  |  | 13 |  | 59 | use HTML::Entities; | 
|  | 13 |  |  |  |  | 35 |  | 
|  | 13 |  |  |  |  | 8973 |  | 
| 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 | 0 |  |  | 0 | 0 |  | return 0; | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | sub print | 
| 54 |  |  |  |  |  |  | { | 
| 55 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 56 | 0 |  |  |  |  |  | my $army_node1 = shift; | 
| 57 | 0 |  |  |  |  |  | my $army_node2 = shift; | 
| 58 | 0 |  |  |  |  |  | return $self->output($army_node1, $army_node2, 'print'); | 
| 59 |  |  |  |  |  |  | } | 
| 60 |  |  |  |  |  |  | sub html | 
| 61 |  |  |  |  |  |  | { | 
| 62 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 63 | 0 |  |  |  |  |  | my $army_node1 = shift; | 
| 64 | 0 |  |  |  |  |  | my $army_node2 = shift; | 
| 65 | 0 |  |  |  |  |  | return $self->output($army_node1, $army_node2, 'html'); | 
| 66 |  |  |  |  |  |  | } | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | sub output | 
| 71 |  |  |  |  |  |  | { | 
| 72 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 73 | 0 |  |  |  |  |  | my $army_node1 = shift; | 
| 74 | 0 |  |  |  |  |  | my $army_node2 = shift; | 
| 75 | 0 |  |  |  |  |  | my $mode = shift; | 
| 76 | 0 | 0 |  |  |  |  | my $army_node1_label = $army_node1 ? "[".$army_node1."] " : ""; | 
| 77 | 0 | 0 |  |  |  |  | my $army_node2_label = $army_node2 ? " [".$army_node2."]" : ""; | 
| 78 | 0 |  |  |  |  |  | my $node1 = $army_node1_label . $self->node1; | 
| 79 | 0 |  |  |  |  |  | my $node2 = $self->node2 . $army_node2_label; | 
| 80 | 0 | 0 |  |  |  |  | if($mode eq 'print') | 
|  |  | 0 |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | { | 
| 82 | 0 | 0 |  |  |  |  | if($self->node1_faction == 0) | 
| 83 |  |  |  |  |  |  | { | 
| 84 | 0 |  |  |  |  |  | $node1 = color("bold") . $node1 . color("reset"); | 
| 85 |  |  |  |  |  |  | } | 
| 86 |  |  |  |  |  |  | else | 
| 87 |  |  |  |  |  |  | { | 
| 88 | 0 |  |  |  |  |  | $node2 = color("bold") . $node2 . color("reset"); | 
| 89 |  |  |  |  |  |  | } | 
| 90 | 0 |  |  |  |  |  | return  $node1 . " -> " . $node2; | 
| 91 |  |  |  |  |  |  | } | 
| 92 |  |  |  |  |  |  | elsif($mode eq 'html') | 
| 93 |  |  |  |  |  |  | { | 
| 94 | 0 | 0 |  |  |  |  | if($self->node1_faction == 0) | 
| 95 |  |  |  |  |  |  | { | 
| 96 | 0 |  |  |  |  |  | $node1 = as_html_evidenced($node1); | 
| 97 |  |  |  |  |  |  | } | 
| 98 |  |  |  |  |  |  | else | 
| 99 |  |  |  |  |  |  | { | 
| 100 | 0 |  |  |  |  |  | $node2 = as_html_evidenced($node2); | 
| 101 |  |  |  |  |  |  | } | 
| 102 | 0 |  |  |  |  |  | return  $node1 . " -> " . $node2; | 
| 103 |  |  |  |  |  |  | } | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | } | 
| 108 |  |  |  |  |  |  | sub dump | 
| 109 |  |  |  |  |  |  | { | 
| 110 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 111 | 0 |  |  |  |  |  | my $io = shift; | 
| 112 | 0 |  | 0 |  |  |  | my $indent = shift || ""; | 
| 113 | 0 |  |  |  |  |  | print {$io} $indent . join(";", $self->node1, $self->node2, $self->attack_leader, | 
|  | 0 |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | $self->war_id, $self->name, $self->node1_faction, $self->node2_faction, | 
| 115 |  |  |  |  |  |  | $self->start_date, $self->end_date, $self->current_year ). "\n"; | 
| 116 | 0 | 0 |  |  |  |  | if($self->events) | 
| 117 |  |  |  |  |  |  | { | 
| 118 | 0 |  |  |  |  |  | $self->dump_events($io, $indent . " "); | 
| 119 |  |  |  |  |  |  | } | 
| 120 |  |  |  |  |  |  | } | 
| 121 |  |  |  |  |  |  | sub load | 
| 122 |  |  |  |  |  |  | { | 
| 123 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 124 | 0 |  |  |  |  |  | my $data = shift; | 
| 125 | 0 |  |  |  |  |  | my $war_line = ( split /\n/, $data )[0]; | 
| 126 | 0 |  |  |  |  |  | $war_line =~ s/^\s+//; | 
| 127 | 0 |  |  |  |  |  | chomp $war_line; | 
| 128 | 0 |  |  |  |  |  | my ($node1, $node2, $attack_leader, $war_id, $name, $node1_faction, $node2_faction, $start_date, $end_date, $current_year) = split ";", $war_line; | 
| 129 | 0 |  |  |  |  |  | $data =~ s/^.*?\n//; | 
| 130 | 0 |  |  |  |  |  | my $events = $self->load_events($data); | 
| 131 | 0 |  |  |  |  |  | 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; |