line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package BalanceOfPower::Role::Reporter; |
2
|
|
|
|
|
|
|
$BalanceOfPower::Role::Reporter::VERSION = '0.400115'; |
3
|
13
|
|
|
13
|
|
105431
|
use strict; |
|
13
|
|
|
|
|
28
|
|
|
13
|
|
|
|
|
421
|
|
4
|
13
|
|
|
13
|
|
7764
|
use utf8; |
|
13
|
|
|
|
|
121
|
|
|
13
|
|
|
|
|
61
|
|
5
|
13
|
|
|
13
|
|
415
|
use v5.10; |
|
13
|
|
|
|
|
38
|
|
6
|
13
|
|
|
13
|
|
48
|
use Moo::Role; |
|
13
|
|
|
|
|
18
|
|
|
13
|
|
|
|
|
123
|
|
7
|
13
|
|
|
13
|
|
3658
|
use Data::Dumper; |
|
13
|
|
|
|
|
18
|
|
|
13
|
|
|
|
|
745
|
|
8
|
13
|
|
|
13
|
|
56
|
use BalanceOfPower::Constants ':all'; |
|
13
|
|
|
|
|
15
|
|
|
13
|
|
|
|
|
7755
|
|
9
|
13
|
|
|
13
|
|
90
|
use BalanceOfPower::Utils qw( prev_turn get_year_turns as_title ); |
|
13
|
|
|
|
|
16
|
|
|
13
|
|
|
|
|
794
|
|
10
|
13
|
|
|
13
|
|
4179
|
use BalanceOfPower::Printer; |
|
13
|
|
|
|
|
25
|
|
|
13
|
|
|
|
|
20807
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
with "BalanceOfPower::Role::Logger"; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has events => ( |
17
|
|
|
|
|
|
|
is => 'rw', |
18
|
|
|
|
|
|
|
default => sub { {} } |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#Event structure: |
22
|
|
|
|
|
|
|
# - code |
23
|
|
|
|
|
|
|
# - text |
24
|
|
|
|
|
|
|
# - involved (ordered) |
25
|
|
|
|
|
|
|
# - values (ordered) |
26
|
|
|
|
|
|
|
# |
27
|
|
|
|
|
|
|
# involved e values have mean is based on code |
28
|
|
|
|
|
|
|
# |
29
|
|
|
|
|
|
|
# In the future, text will be replaced with something generated from code |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub register_event |
32
|
|
|
|
|
|
|
{ |
33
|
1897
|
|
|
1897
|
0
|
2118
|
my $self = shift; |
34
|
1897
|
|
|
|
|
1917
|
my $event = shift; |
35
|
|
|
|
|
|
|
#Fallback for old style events |
36
|
1897
|
100
|
|
|
|
4127
|
if(! (ref $event eq 'HASH')) |
37
|
|
|
|
|
|
|
{ |
38
|
969
|
|
|
|
|
3880
|
$event = { code => undef, |
39
|
|
|
|
|
|
|
text => $event, |
40
|
|
|
|
|
|
|
involved => [], |
41
|
|
|
|
|
|
|
values => [] }; |
42
|
|
|
|
|
|
|
} |
43
|
1897
|
100
|
|
|
|
4836
|
my $time = $self->current_year ? $self->current_year : "START"; |
44
|
|
|
|
|
|
|
|
45
|
1897
|
50
|
|
|
|
4514
|
$self->events({}) if(! $self->events ); |
46
|
1897
|
|
|
|
|
1809
|
push @{$self->events->{$time}}, $event; |
|
1897
|
|
|
|
|
4521
|
|
47
|
1897
|
|
|
|
|
8407
|
$self->log("$time - [" . $self->name . "] " . $event->{text}); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
sub make_plain |
50
|
|
|
|
|
|
|
{ |
51
|
440
|
|
|
440
|
0
|
491
|
my $self = shift; |
52
|
440
|
|
|
|
|
532
|
my @events = @_; |
53
|
440
|
|
|
|
|
458
|
my @out = (); |
54
|
440
|
|
|
|
|
819
|
for(@events) |
55
|
|
|
|
|
|
|
{ |
56
|
20
|
|
|
|
|
44
|
push @out, $_->{text}; |
57
|
|
|
|
|
|
|
} |
58
|
440
|
|
|
|
|
1219
|
return @out; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
sub by_tags |
61
|
|
|
|
|
|
|
{ |
62
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
63
|
0
|
|
|
|
|
0
|
my @events = @_; |
64
|
0
|
|
|
|
|
0
|
my %out = (); |
65
|
0
|
|
|
|
|
0
|
foreach my $e (@events) |
66
|
|
|
|
|
|
|
{ |
67
|
0
|
|
0
|
|
|
0
|
my $tag = $e->{code} || 'XXX'; |
68
|
0
|
0
|
|
|
|
0
|
if(exists $out{$tag}) |
69
|
|
|
|
|
|
|
{ |
70
|
0
|
|
|
|
|
0
|
push @{$out{$tag}}, $e; |
|
0
|
|
|
|
|
0
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
else |
73
|
|
|
|
|
|
|
{ |
74
|
0
|
|
|
|
|
0
|
$out{$tag} = []; |
75
|
0
|
|
|
|
|
0
|
push @{$out{$tag}}, $e; |
|
0
|
|
|
|
|
0
|
|
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
0
|
|
|
|
|
0
|
return %out; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
sub plain_events |
81
|
|
|
|
|
|
|
{ |
82
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
83
|
0
|
|
|
|
|
0
|
my %out = (); |
84
|
0
|
|
|
|
|
0
|
for(keys %{$self->events}) |
|
0
|
|
|
|
|
0
|
|
85
|
|
|
|
|
|
|
{ |
86
|
0
|
|
|
|
|
0
|
my $turn = $_; |
87
|
0
|
|
|
|
|
0
|
my @evs = $self->make_plain(@{$self->events->{$turn}}); |
|
0
|
|
|
|
|
0
|
|
88
|
0
|
|
|
|
|
0
|
$out{$turn} = \@evs; |
89
|
|
|
|
|
|
|
} |
90
|
0
|
|
|
|
|
0
|
return \%out; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
sub by_tags_events |
93
|
|
|
|
|
|
|
{ |
94
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
95
|
0
|
|
|
|
|
0
|
my %out = (); |
96
|
0
|
|
|
|
|
0
|
for(keys %{$self->events}) |
|
0
|
|
|
|
|
0
|
|
97
|
|
|
|
|
|
|
{ |
98
|
0
|
|
|
|
|
0
|
my $turn = $_; |
99
|
0
|
|
|
|
|
0
|
my %evs = $self->make_plain(@{$self->events->{$turn}}); |
|
0
|
|
|
|
|
0
|
|
100
|
0
|
|
|
|
|
0
|
$out{$turn} = \%evs; |
101
|
|
|
|
|
|
|
} |
102
|
0
|
|
|
|
|
0
|
return \%out; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
#Old get_events, based on grep on text. Returns events as array of strings. |
106
|
|
|
|
|
|
|
sub get_events |
107
|
|
|
|
|
|
|
{ |
108
|
608
|
|
|
608
|
0
|
673
|
my $self = shift; |
109
|
608
|
|
|
|
|
629
|
my $label = shift; |
110
|
608
|
|
|
|
|
615
|
my $year = shift; |
111
|
608
|
100
|
33
|
|
|
2558
|
if($self->events && exists $self->events->{$year}) |
112
|
|
|
|
|
|
|
{ |
113
|
440
|
|
|
|
|
459
|
my @events = grep { $_->{text} =~ /^$label/ } @{$self->events->{$year}}; |
|
3236
|
|
|
|
|
12412
|
|
|
440
|
|
|
|
|
1001
|
|
114
|
440
|
|
|
|
|
1034
|
return $self->make_plain(@events); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
else |
117
|
|
|
|
|
|
|
{ |
118
|
168
|
|
|
|
|
328
|
return (); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
sub get_events_by_tag |
122
|
|
|
|
|
|
|
{ |
123
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
124
|
0
|
|
|
|
|
|
my $tag = shift; |
125
|
0
|
|
|
|
|
|
my $year = shift; |
126
|
0
|
0
|
0
|
|
|
|
if($self->events && exists $self->events->{$year}) |
127
|
|
|
|
|
|
|
{ |
128
|
0
|
|
|
|
|
|
my %events = $self->by_tags(@{$self->events->{$year}}); |
|
0
|
|
|
|
|
|
|
129
|
0
|
0
|
|
|
|
|
if(exists $events{$tag}) |
130
|
|
|
|
|
|
|
{ |
131
|
0
|
|
|
|
|
|
return @{$events{$tag}}; |
|
0
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
else |
134
|
|
|
|
|
|
|
{ |
135
|
0
|
|
|
|
|
|
return (); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
else |
139
|
|
|
|
|
|
|
{ |
140
|
0
|
|
|
|
|
|
return (); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
sub turns_to_print |
144
|
|
|
|
|
|
|
{ |
145
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
146
|
0
|
|
|
|
|
|
my $y = shift; |
147
|
0
|
|
|
|
|
|
my $backlog = shift; |
148
|
0
|
|
|
|
|
|
my @to_print = (); |
149
|
0
|
0
|
|
|
|
|
if(! $y) |
150
|
|
|
|
|
|
|
{ |
151
|
0
|
0
|
|
|
|
|
$y = $self->current_year ? $self->current_year : "START"; |
152
|
|
|
|
|
|
|
} |
153
|
0
|
0
|
|
|
|
|
if($y =~ /^\d\d\d\d$/) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
154
|
|
|
|
|
|
|
{ |
155
|
0
|
|
|
|
|
|
@to_print = get_year_turns($y); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
elsif($y =~ /^\d\d\d\d\/\d+$/) |
158
|
|
|
|
|
|
|
{ |
159
|
0
|
|
|
|
|
|
@to_print = ($y); |
160
|
0
|
|
|
|
|
|
for(my $i = 0; $i < $backlog; $i++) |
161
|
|
|
|
|
|
|
{ |
162
|
0
|
|
|
|
|
|
push @to_print, prev_turn($y); |
163
|
0
|
|
|
|
|
|
$y = prev_turn($y); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
elsif($y eq 'START') |
167
|
|
|
|
|
|
|
{ |
168
|
0
|
|
|
|
|
|
@to_print = ('START'); |
169
|
|
|
|
|
|
|
} |
170
|
0
|
|
|
|
|
|
return @to_print; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub print_turn_events |
175
|
|
|
|
|
|
|
{ |
176
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
177
|
0
|
|
|
|
|
|
my $y = shift; |
178
|
0
|
|
|
|
|
|
my $title = shift; |
179
|
0
|
|
0
|
|
|
|
my $backlog = shift || 0; |
180
|
0
|
|
0
|
|
|
|
my $mode = shift || 'print'; |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
my @to_print = $self->turns_to_print($y, $backlog); |
183
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
|
return BalanceOfPower::Printer::print($mode, $self, 'print_turn_events', |
185
|
|
|
|
|
|
|
{ title => $title, |
186
|
|
|
|
|
|
|
turns => \@to_print, |
187
|
|
|
|
|
|
|
events => $self->plain_events() } ); |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub get_turn_tags |
191
|
|
|
|
|
|
|
{ |
192
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
193
|
0
|
|
0
|
|
|
|
my $range = shift || -1; |
194
|
|
|
|
|
|
|
sub sort_start |
195
|
|
|
|
|
|
|
{ |
196
|
0
|
0
|
|
0
|
0
|
|
return 0 if($a eq $b); |
197
|
0
|
0
|
|
|
|
|
return -1 if($a eq 'START'); |
198
|
0
|
0
|
|
|
|
|
return 1 if($b eq 'START'); |
199
|
0
|
0
|
|
|
|
|
return 1 if($a gt $b); |
200
|
0
|
0
|
|
|
|
|
return -1 if($b gt $a); |
201
|
|
|
|
|
|
|
} |
202
|
0
|
|
|
|
|
|
my @keys = keys %{$self->events}; |
|
0
|
|
|
|
|
|
|
203
|
0
|
|
|
|
|
|
my $start; |
204
|
0
|
|
|
|
|
|
my $stop = $#keys; |
205
|
0
|
0
|
|
|
|
|
if($range == -1) |
206
|
|
|
|
|
|
|
{ |
207
|
0
|
|
|
|
|
|
$start = 0; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
else |
210
|
|
|
|
|
|
|
{ |
211
|
0
|
|
|
|
|
|
$start = $stop - $range; |
212
|
0
|
0
|
|
|
|
|
$start = 0 if($start < 0); |
213
|
|
|
|
|
|
|
} |
214
|
0
|
|
|
|
|
|
@keys = sort sort_start keys %{$self->events}; |
|
0
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
|
return @keys[$start..$stop]; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub dump_events |
219
|
|
|
|
|
|
|
{ |
220
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
221
|
0
|
|
|
|
|
|
my $io = shift; |
222
|
0
|
|
0
|
|
|
|
my $indent = shift || ""; |
223
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
foreach my $y ($self->get_turn_tags(EVENT_TURNS_TO_DUMP)) |
225
|
|
|
|
|
|
|
{ |
226
|
0
|
|
|
|
|
|
print {$io} $indent . "### $y\n"; |
|
0
|
|
|
|
|
|
|
227
|
0
|
|
|
|
|
|
foreach my $e (@{$self->events->{$y}}) |
|
0
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
{ |
229
|
0
|
|
0
|
|
|
|
my $code = $e->{code} || ''; |
230
|
0
|
|
0
|
|
|
|
my $text = $e->{text} || ''; |
231
|
0
|
|
|
|
|
|
my $values = ""; |
232
|
0
|
0
|
0
|
|
|
|
if(defined $e->{values} && @{$e->{values}}) |
|
0
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
{ |
234
|
0
|
0
|
|
|
|
|
$values = join(',', map { defined $_ ? $_ : '' } @{$e->{values}}); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
} |
236
|
0
|
|
|
|
|
|
my $involved = ""; |
237
|
0
|
0
|
0
|
|
|
|
if(defined $e->{involved} && @{$e->{involved}}) |
|
0
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
{ |
239
|
0
|
0
|
|
|
|
|
$involved = join(',', map { defined $_ ? $_ : '' } @{$e->{involved}}); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
} |
241
|
0
|
|
|
|
|
|
my $line = join '|', $code, $text, $involved, $values; |
242
|
0
|
|
|
|
|
|
print {$io} $indent . $line . "\n"; |
|
0
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
sub load_events |
247
|
|
|
|
|
|
|
{ |
248
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
249
|
0
|
|
|
|
|
|
my $data = shift; |
250
|
0
|
|
|
|
|
|
my @lines = split "\n", $data; |
251
|
0
|
|
|
|
|
|
my $year = ""; |
252
|
0
|
|
|
|
|
|
my %events; |
253
|
0
|
|
|
|
|
|
foreach my $l (@lines) |
254
|
|
|
|
|
|
|
{ |
255
|
0
|
|
|
|
|
|
$l =~ s/^\s//; |
256
|
0
|
|
|
|
|
|
chomp $l; |
257
|
0
|
0
|
|
|
|
|
if($l =~ /### (.*)$/) |
258
|
|
|
|
|
|
|
{ |
259
|
0
|
|
|
|
|
|
$year = $1; |
260
|
0
|
|
|
|
|
|
$events{$year} = []; |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
else |
263
|
|
|
|
|
|
|
{ |
264
|
0
|
|
|
|
|
|
my @elements = split /\|/, $l; |
265
|
0
|
|
|
|
|
|
my $e; |
266
|
0
|
0
|
|
|
|
|
if(@elements == 1) |
267
|
|
|
|
|
|
|
{ |
268
|
0
|
|
|
|
|
|
$e = { code => undef, |
269
|
|
|
|
|
|
|
text => $elements[0], |
270
|
|
|
|
|
|
|
involved => [], |
271
|
|
|
|
|
|
|
values => [] }; |
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
else |
274
|
|
|
|
|
|
|
{ |
275
|
0
|
|
|
|
|
|
my @involved = (); |
276
|
0
|
0
|
|
|
|
|
@involved = split ',', $elements[2] if $elements[2]; |
277
|
0
|
|
|
|
|
|
my @values = (); |
278
|
0
|
0
|
|
|
|
|
@values = split ',', $elements[3] if $elements[3]; |
279
|
0
|
|
0
|
|
|
|
$e = { code => $elements[0] || '', |
|
|
|
0
|
|
|
|
|
280
|
|
|
|
|
|
|
text => $elements[1] || '', |
281
|
|
|
|
|
|
|
involved => \@involved, |
282
|
|
|
|
|
|
|
values => \@values |
283
|
|
|
|
|
|
|
}; |
284
|
|
|
|
|
|
|
} |
285
|
0
|
|
|
|
|
|
push @{$events{$year}}, $e; |
|
0
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
} |
287
|
|
|
|
|
|
|
} |
288
|
0
|
|
|
|
|
|
return \%events; |
289
|
|
|
|
|
|
|
} |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
1; |