| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Games::Lacuna::Task::Utils; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
2865
|
use strict; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
82
|
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
103
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = $Games::Lacuna::Task::VERSION; |
|
7
|
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
4916
|
use Unicode::Normalize qw(decompose); |
|
|
2
|
|
|
|
|
21205
|
|
|
|
2
|
|
|
|
|
292
|
|
|
9
|
2
|
|
|
2
|
|
23
|
use Scalar::Util qw(blessed); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
175
|
|
|
10
|
2
|
|
|
2
|
|
2826
|
use Time::Local qw(timegm); |
|
|
2
|
|
|
|
|
4769
|
|
|
|
2
|
|
|
|
|
189
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
18
|
use base qw(Exporter); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
839
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
|
14
|
|
|
|
|
|
|
class_to_name |
|
15
|
|
|
|
|
|
|
name_to_class |
|
16
|
|
|
|
|
|
|
normalize_name |
|
17
|
|
|
|
|
|
|
clean_name |
|
18
|
|
|
|
|
|
|
distance |
|
19
|
|
|
|
|
|
|
pretty_dump |
|
20
|
|
|
|
|
|
|
parse_ship_type |
|
21
|
|
|
|
|
|
|
parse_date |
|
22
|
|
|
|
|
|
|
format_date |
|
23
|
|
|
|
|
|
|
); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub class_to_name { |
|
26
|
1
|
|
|
1
|
1
|
4
|
my ($class) = @_; |
|
27
|
|
|
|
|
|
|
|
|
28
|
1
|
50
|
|
|
|
8
|
$class = ref($class) |
|
29
|
|
|
|
|
|
|
if ref($class); |
|
30
|
1
|
|
|
|
|
8
|
$class =~ s/^.+::([^:]+)$/$1/; |
|
31
|
2
|
|
|
2
|
|
14
|
$class =~ s/(\p{Lower})(\p{Upper}\p{Lower})/$1_$2/g; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
40
|
|
|
|
1
|
|
|
|
|
10
|
|
|
32
|
1
|
|
|
|
|
3
|
$class = lc($class); |
|
33
|
1
|
|
|
|
|
5
|
return $class; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub name_to_class { |
|
37
|
3
|
|
|
3
|
1
|
411
|
my ($name) = @_; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
return |
|
40
|
3
|
50
|
|
|
|
12
|
unless defined $name; |
|
41
|
|
|
|
|
|
|
|
|
42
|
3
|
|
|
|
|
21
|
my @parts = map { ucfirst(lc($_)) } |
|
|
5
|
|
|
|
|
18
|
|
|
43
|
|
|
|
|
|
|
split (/[_ ]/,$name); |
|
44
|
|
|
|
|
|
|
|
|
45
|
3
|
|
|
|
|
11
|
my $class = 'Games::Lacuna::Task::Action::'.join ('',@parts); |
|
46
|
|
|
|
|
|
|
|
|
47
|
3
|
|
|
|
|
15
|
return $class; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub normalize_name { |
|
51
|
1
|
|
|
1
|
1
|
358
|
my ($name) = @_; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
return |
|
54
|
1
|
50
|
|
|
|
7
|
unless defined $name; |
|
55
|
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
5
|
return uc(clean_name($name)); |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub clean_name { |
|
60
|
1
|
|
|
1
|
0
|
1
|
my ($name) = @_; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
return |
|
63
|
1
|
50
|
|
|
|
5
|
unless defined $name; |
|
64
|
|
|
|
|
|
|
|
|
65
|
1
|
|
|
|
|
27
|
my $name_simple = decompose($name); |
|
66
|
1
|
|
|
|
|
37
|
$name_simple =~ s/\p{NonSpacingMark}//g; |
|
67
|
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
5
|
$name_simple =~ s/^\s+//g; |
|
69
|
1
|
|
|
|
|
6
|
$name_simple =~ s/\s+$//g; |
|
70
|
|
|
|
|
|
|
|
|
71
|
1
|
|
|
|
|
8
|
return $name_simple; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub distance { |
|
75
|
1
|
|
|
1
|
1
|
360
|
my ($x1,$y1,$x2,$y2) = @_; |
|
76
|
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
16
|
return int(sqrt( ($x1 - $x2)**2 + ($y1 - $y2)**2 )); |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub pretty_dump { |
|
81
|
0
|
|
|
0
|
1
|
0
|
my ($value) = @_; |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
0
|
return $value |
|
84
|
|
|
|
|
|
|
unless ref $value; |
|
85
|
0
|
0
|
0
|
|
|
0
|
return $value->stringify |
|
86
|
|
|
|
|
|
|
if blessed($value) && $value->can('stringify'); |
|
87
|
0
|
0
|
0
|
|
|
0
|
return $value->message |
|
88
|
|
|
|
|
|
|
if blessed($value) && $value->can('message'); |
|
89
|
0
|
|
|
|
|
0
|
my $dump = Data::Dumper::Dumper($value); |
|
90
|
0
|
|
|
|
|
0
|
chomp($dump); |
|
91
|
0
|
|
|
|
|
0
|
$dump =~ s/^\$VAR1\s=\s(.+);$/$1/s; |
|
92
|
0
|
|
|
|
|
0
|
return $dump; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub parse_ship_type { |
|
96
|
9
|
|
|
9
|
1
|
3792
|
my ($name) = @_; |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
return |
|
99
|
9
|
50
|
|
|
|
30
|
unless defined $name; |
|
100
|
|
|
|
|
|
|
|
|
101
|
9
|
|
|
|
|
18
|
$name = lc($name); |
|
102
|
9
|
|
|
|
|
33
|
$name =~ s/\s+/_/g; |
|
103
|
9
|
|
|
|
|
23
|
$name =~ s/(vi)$/6/i; |
|
104
|
9
|
|
|
|
|
17
|
$name =~ s/(iv)$/4/i; |
|
105
|
9
|
|
|
|
|
18
|
$name =~ s/(v)$/5/i; |
|
106
|
9
|
|
|
|
|
22
|
$name =~ s/(i{1,3})$/length($1)/ei; |
|
|
1
|
|
|
|
|
8
|
|
|
107
|
9
|
|
|
|
|
29
|
$name =~ s/_([1-6])$/$1/; |
|
108
|
|
|
|
|
|
|
|
|
109
|
9
|
|
|
|
|
38
|
return $name; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub parse_date { |
|
113
|
1
|
|
|
1
|
1
|
355
|
my ($date) = @_; |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
return |
|
116
|
1
|
50
|
|
|
|
5
|
unless defined $date; |
|
117
|
|
|
|
|
|
|
|
|
118
|
1
|
50
|
|
|
|
9
|
if ($date =~ m/^ |
|
119
|
|
|
|
|
|
|
(?<day>\d{2}) \s |
|
120
|
|
|
|
|
|
|
(?<month>\d{2}) \s |
|
121
|
|
|
|
|
|
|
(?<year>20\d{2}) \s |
|
122
|
|
|
|
|
|
|
(?<hour>\d{2}) : |
|
123
|
|
|
|
|
|
|
(?<minute>\d{2}) : |
|
124
|
|
|
|
|
|
|
(?<second>\d{2}) \s |
|
125
|
|
|
|
|
|
|
\+(?<timezoneoffset>\d{4}) |
|
126
|
|
|
|
|
|
|
$/x) { |
|
127
|
|
|
|
|
|
|
|
|
128
|
2
|
50
|
|
2
|
|
71030
|
warn('Unexpected timezone offset '.$+{timezoneoffset}) |
|
|
2
|
|
|
|
|
1353
|
|
|
|
2
|
|
|
|
|
688
|
|
|
|
1
|
|
|
|
|
18
|
|
|
129
|
|
|
|
|
|
|
if $+{timezoneoffset} != 0; |
|
130
|
|
|
|
|
|
|
|
|
131
|
1
|
|
|
|
|
3
|
my @params = map { $+{$_} } qw(second minute hour day month year); |
|
|
6
|
|
|
|
|
36
|
|
|
132
|
1
|
|
|
|
|
4
|
$params[4]--; #month index |
|
133
|
|
|
|
|
|
|
|
|
134
|
1
|
|
|
|
|
38
|
return timegm(@params); |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
0
|
return; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub format_date { |
|
141
|
1
|
|
|
1
|
1
|
398
|
my ($date) = @_; |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
return |
|
144
|
1
|
50
|
33
|
|
|
14
|
unless defined $date && $date =~ m/^\d+$/; |
|
145
|
|
|
|
|
|
|
|
|
146
|
1
|
|
|
|
|
8
|
my ($sec,$min,$hour,$mday,$mon,$year) = gmtime($date); |
|
147
|
1
|
|
|
|
|
3
|
$year += 1900; |
|
148
|
1
|
|
|
|
|
2
|
$mon++; |
|
149
|
|
|
|
|
|
|
|
|
150
|
1
|
|
|
|
|
10
|
return sprintf('%04i.%02i.%02i %02i:%02i',$year,$mon,$mday,$hour,$min); |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
1; |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=encoding utf8 |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 NAME |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Games::Lacuna::Task::Utils -Â Helper functions for Games::Lacuna::Task |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
use Games::Lacuna::Task::Utils qw(class_to_name); |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
No functions are exported by default. |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head3 class_to_name |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Class name to moniker (lowercase, uderscore separated) |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head3 name_to_class |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Moniker to class name (camel case, prefixed with Games::Lacuna::Task::Action::) |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head3 distance |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
my $dist = distance($x1,$y1,$x2,$y2); |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Calculates map distance |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head3 pretty_dump |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
say pretty_dump($value); |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Stringifies any value |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head3 normalize_name |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Removes diacritic marks and uppercases a string for better compareability |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head3 parse_ship_type |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
my $ship_type = parse_ship_type($human_type); |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Converts a human ship name into the ship type |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head2 parse_date |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Returns a epoch timestamp for the given timestamp from the api response |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head2 format_date |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Formats an epoch timestamp |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=cut |