line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package BalanceOfPower::Utils; |
2
|
|
|
|
|
|
|
$BalanceOfPower::Utils::VERSION = '0.400110'; |
3
|
13
|
|
|
13
|
|
40
|
use BalanceOfPower::Constants ':all'; |
|
13
|
|
|
|
|
14
|
|
|
13
|
|
|
|
|
4914
|
|
4
|
13
|
|
|
13
|
|
6593
|
use Term::ANSIColor; |
|
13
|
|
|
|
|
60285
|
|
|
13
|
|
|
|
|
664
|
|
5
|
|
|
|
|
|
|
|
6
|
13
|
|
|
13
|
|
59
|
use strict; |
|
13
|
|
|
|
|
10
|
|
|
13
|
|
|
|
|
183
|
|
7
|
13
|
|
|
13
|
|
35
|
use warnings; |
|
13
|
|
|
|
|
13
|
|
|
13
|
|
|
|
|
246
|
|
8
|
|
|
|
|
|
|
|
9
|
13
|
|
|
13
|
|
33
|
use base 'Exporter'; |
|
13
|
|
|
|
|
13
|
|
|
13
|
|
|
|
|
9589
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub prev_turn |
12
|
|
|
|
|
|
|
{ |
13
|
1868
|
|
|
1868
|
0
|
1506
|
my $year = shift; |
14
|
1868
|
|
|
|
|
2973
|
my ($y, $i) = split '/', $year; |
15
|
1868
|
|
50
|
|
|
2507
|
$i ||= 1; |
16
|
1868
|
100
|
|
|
|
2502
|
if($i == 1) |
17
|
|
|
|
|
|
|
{ |
18
|
614
|
|
|
|
|
1864
|
return ($y -1) . '/' . TURNS_FOR_YEAR; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
else |
21
|
|
|
|
|
|
|
{ |
22
|
1254
|
|
|
|
|
3514
|
return $y . '/' . ($i - 1); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
sub next_turn |
26
|
|
|
|
|
|
|
{ |
27
|
4
|
|
|
4
|
0
|
4
|
my $year = shift; |
28
|
4
|
|
|
|
|
12
|
my ($y, $i) = split '/', $year; |
29
|
4
|
100
|
|
|
|
13
|
if($i == TURNS_FOR_YEAR) |
30
|
|
|
|
|
|
|
{ |
31
|
1
|
|
|
|
|
4
|
return ($y +1) . '/' . '1'; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
else |
34
|
|
|
|
|
|
|
{ |
35
|
3
|
|
|
|
|
11
|
return $y . '/' . ($i + 1); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
sub get_year_turns |
39
|
|
|
|
|
|
|
{ |
40
|
1
|
|
|
1
|
0
|
1
|
my $year = shift; |
41
|
1
|
50
|
|
|
|
3
|
return ($year) if($year =~ /\d+\/\d+/); |
42
|
1
|
|
|
|
|
2
|
my @turns = (); |
43
|
1
|
|
|
|
|
4
|
for(my $i = 1; $i<= TURNS_FOR_YEAR; $i++) |
44
|
|
|
|
|
|
|
{ |
45
|
4
|
|
|
|
|
9
|
push @turns, $year . '/' . $i; |
46
|
|
|
|
|
|
|
} |
47
|
1
|
|
|
|
|
3
|
return @turns; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
sub split_turn |
50
|
|
|
|
|
|
|
{ |
51
|
0
|
|
|
0
|
0
|
|
my $turn = shift; |
52
|
0
|
0
|
|
|
|
|
if($turn =~ /(\d+)(\/(\d+))?/) |
53
|
|
|
|
|
|
|
{ |
54
|
0
|
|
|
|
|
|
my $turn_y = $1; |
55
|
0
|
0
|
|
|
|
|
my $turn_t = $3 ? $3 : 1; |
56
|
0
|
|
|
|
|
|
return ($turn_y, $turn_t); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
else |
59
|
|
|
|
|
|
|
{ |
60
|
0
|
|
|
|
|
|
(undef, undef); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
sub from_to_turns |
64
|
|
|
|
|
|
|
{ |
65
|
0
|
|
|
0
|
0
|
|
my $from = shift; |
66
|
0
|
|
|
|
|
|
my $to = shift; |
67
|
0
|
|
|
|
|
|
my ($from_y, $from_t) = split_turn($from); |
68
|
0
|
0
|
|
|
|
|
return () if(! $from_y); |
69
|
0
|
|
|
|
|
|
my ($to_y, $to_t) = split_turn($to); |
70
|
0
|
0
|
|
|
|
|
return () if(! $from_y); |
71
|
|
|
|
|
|
|
return () |
72
|
0
|
0
|
0
|
|
|
|
if($to_y < $from_y || ($to_y == $from_y && $to_t < $from_t)); |
|
|
|
0
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my $goon = 1; |
74
|
0
|
|
|
|
|
|
my $to_add_y = $from_y; |
75
|
0
|
|
|
|
|
|
my $to_add_t = $from_t; |
76
|
0
|
|
|
|
|
|
my @turns = (); |
77
|
0
|
|
|
|
|
|
while(1) |
78
|
|
|
|
|
|
|
{ |
79
|
0
|
|
|
|
|
|
my $to_add = $to_add_y . '/' . $to_add_t; |
80
|
0
|
|
|
|
|
|
push @turns, $to_add; |
81
|
0
|
0
|
|
|
|
|
last if($to_add eq $to); |
82
|
0
|
0
|
|
|
|
|
if($to_add_t < TURNS_FOR_YEAR) |
83
|
|
|
|
|
|
|
{ |
84
|
0
|
|
|
|
|
|
$to_add_t++; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
else |
87
|
|
|
|
|
|
|
{ |
88
|
0
|
|
|
|
|
|
$to_add_y++; |
89
|
0
|
|
|
|
|
|
$to_add_t = 1; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
0
|
|
|
|
|
|
return @turns; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# first < second -> -1 |
99
|
|
|
|
|
|
|
# first = second -> 0 |
100
|
|
|
|
|
|
|
# first > second -> 1 |
101
|
|
|
|
|
|
|
# |
102
|
|
|
|
|
|
|
sub compare_turns |
103
|
|
|
|
|
|
|
{ |
104
|
0
|
|
|
0
|
0
|
|
my $first = shift; |
105
|
0
|
|
|
|
|
|
my $second = shift; |
106
|
0
|
0
|
|
|
|
|
return 0 if ($first eq $second); |
107
|
0
|
|
|
|
|
|
my ($first_y, $first_t) = split_turn($first); |
108
|
0
|
0
|
|
|
|
|
return undef if(! $first_y); |
109
|
0
|
|
|
|
|
|
my ($second_y, $second_t) = split_turn($second); |
110
|
0
|
0
|
|
|
|
|
return undef if(! $second_y); |
111
|
0
|
0
|
0
|
|
|
|
return 0 if($first_y == $second_y && $first_t == $second_t); |
112
|
|
|
|
|
|
|
return undef |
113
|
0
|
0
|
0
|
|
|
|
if($first_t < 0 || |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
114
|
|
|
|
|
|
|
$second_t < 0 || |
115
|
|
|
|
|
|
|
$first_t > TURNS_FOR_YEAR || |
116
|
|
|
|
|
|
|
$second_t > TURNS_FOR_YEAR); |
117
|
0
|
0
|
0
|
|
|
|
if($first_y > $second_y || |
|
|
|
0
|
|
|
|
|
118
|
|
|
|
|
|
|
(($first_y == $second_y && $first_t > $second_t))) |
119
|
|
|
|
|
|
|
{ |
120
|
0
|
|
|
|
|
|
return 1; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
else |
123
|
|
|
|
|
|
|
{ |
124
|
0
|
|
|
|
|
|
return -1; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
sub evidence_text |
128
|
|
|
|
|
|
|
{ |
129
|
0
|
|
|
0
|
0
|
|
my $text = shift; |
130
|
0
|
|
|
|
|
|
my $key = shift; |
131
|
0
|
|
|
|
|
|
$text =~ s/($key)/as_evidenced($1)/eg; |
|
0
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
return $text; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub as_main_title |
136
|
|
|
|
|
|
|
{ |
137
|
0
|
|
|
0
|
0
|
|
my $text = shift; |
138
|
0
|
|
|
|
|
|
my $mode = shift; |
139
|
0
|
0
|
|
|
|
|
if($mode eq 'print') |
|
|
0
|
|
|
|
|
|
140
|
|
|
|
|
|
|
{ |
141
|
0
|
|
|
|
|
|
return as_title("$text\n===\n"); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
elsif($mode eq 'html') |
144
|
|
|
|
|
|
|
{ |
145
|
0
|
|
|
|
|
|
return as_html_title($text); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
sub as_main_subtitle |
149
|
|
|
|
|
|
|
{ |
150
|
0
|
|
|
0
|
0
|
|
my $text = shift; |
151
|
0
|
|
|
|
|
|
my $mode = shift; |
152
|
0
|
0
|
|
|
|
|
if($mode eq 'print') |
|
|
0
|
|
|
|
|
|
153
|
|
|
|
|
|
|
{ |
154
|
0
|
|
|
|
|
|
return "### $text\n"; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
elsif($mode eq 'html') |
157
|
|
|
|
|
|
|
{ |
158
|
0
|
|
|
|
|
|
return "<h4>$text</h4>"; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub as_title |
163
|
|
|
|
|
|
|
{ |
164
|
0
|
|
|
0
|
0
|
|
my $text = shift; |
165
|
0
|
|
|
|
|
|
return color("yellow bold") . $text . color("reset"); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
sub as_html_title |
168
|
|
|
|
|
|
|
{ |
169
|
0
|
|
|
0
|
0
|
|
my $text = shift; |
170
|
0
|
|
|
|
|
|
return "<h3>$text</h3>"; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
sub as_html_dangerous |
173
|
|
|
|
|
|
|
{ |
174
|
0
|
|
|
0
|
0
|
|
my $text = shift; |
175
|
0
|
|
|
|
|
|
return '<span class="dangerous">' . $text . '</span>'; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
sub as_html_evidenced |
178
|
|
|
|
|
|
|
{ |
179
|
0
|
|
|
0
|
0
|
|
my $text = shift; |
180
|
0
|
|
|
|
|
|
return '<span class="evidenced">' . $text . '</span>'; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
sub as_html_box |
183
|
|
|
|
|
|
|
{ |
184
|
0
|
|
|
0
|
0
|
|
my $text = shift; |
185
|
0
|
|
|
|
|
|
return "<p>$text</p>"; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
sub as_subtitle |
188
|
|
|
|
|
|
|
{ |
189
|
0
|
|
|
0
|
0
|
|
my $text = shift; |
190
|
0
|
|
|
|
|
|
return color("yellow") . $text . color("reset"); |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
sub as_evidenced |
193
|
|
|
|
|
|
|
{ |
194
|
0
|
|
|
0
|
0
|
|
my $text = shift; |
195
|
0
|
|
|
|
|
|
return color("bold green") . $text . color("reset"); |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
sub as_active |
198
|
|
|
|
|
|
|
{ |
199
|
0
|
|
|
0
|
0
|
|
my $text = shift; |
200
|
0
|
|
|
|
|
|
return color("bold white") . $text . color("reset"); |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
sub br |
203
|
|
|
|
|
|
|
{ |
204
|
0
|
|
|
0
|
0
|
|
my $mode = shift; |
205
|
0
|
0
|
|
|
|
|
if($mode eq 'print') |
|
|
0
|
|
|
|
|
|
206
|
|
|
|
|
|
|
{ |
207
|
0
|
|
|
|
|
|
return "\n"; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
elsif($mode eq 'html') |
210
|
|
|
|
|
|
|
{ |
211
|
0
|
|
|
|
|
|
return "<br />"; |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
our @EXPORT_OK = ('prev_turn', 'next_turn', 'random', 'random10', 'get_year_turns', 'as_title', 'from_to_turns', 'compare_turns', 'as_subtitle', 'evidence_text', 'as_evidenced', 'as_active', 'as_html_title', 'as_html_box', 'as_html_dangerous', 'as_html_evidenced', 'as_main_title', 'as_main_subtitle', 'br'); |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
1; |