-
Notifications
You must be signed in to change notification settings - Fork 1
/
Warsaw.pm
341 lines (215 loc) · 6.07 KB
/
Warsaw.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
package Map::Tube::Warsaw;
use strict;
use warnings;
use 5.006;
use File::Share ':all';
use Moo;
use namespace::clean;
our $VERSION = 0.09;
# Get XML.
has xml => (
'is' => 'ro',
'default' => sub {
return dist_file('Map-Tube-Warsaw', 'warsaw-map.xml');
},
);
with 'Map::Tube';
1;
__END__
=encoding utf8
=head1 NAME
Map::Tube::Warsaw - Interface to the Warsaw Tube Map.
=head1 SYNOPSIS
use Map::Tube::Warsaw;
my $obj = Map::Tube::Warsaw->new;
my $routes_ar = $obj->get_all_routes($from, $to);
my $line = $obj->get_line_by_id($line_id);
my $line = $obj->get_line_by_name($line_name);
my $lines_ar = $obj->get_lines;
my $station = $obj->get_node_by_id($station_id);
my $station = $obj->get_node_by_name($station_name);
my $route = $obj->get_shortest_route($from, $to);
my $stations_ar = $obj->get_stations($line);
my $metro_name = $obj->name;
my $xml = $obj->xml;
=head1 DESCRIPTION
It currently provides functionality to find the shortest route between the two
given nodes.
For more information about Warsaw Map, click L<here|https://en.wikipedia.org/wiki/Warsaw_Metro>.
=head1 METHODS
=head2 C<new>
my $obj = Map::Tube::Warsaw->new;
Constructor.
Returns instance of object.
=head2 C<get_all_routes>
my $routes_ar = $obj->get_all_routes($from, $to);
Get all routes from station to station.
Returns reference to array with Map::Tube::Route objects.
=head2 C<get_line_by_id>
my $line = $obj->get_line_by_id($line_id);
Get line object defined by id.
Returns Map::Tube::Line object.
=head2 C<get_line_by_name>
my $line = $obj->get_line_by_name($line_name);
Get line object defined by name.
Returns Map::Tube::Line object.
=head2 C<get_lines>
my $lines_ar = $obj->get_lines;
Get lines in metro map.
Returns reference to unsorted array with Map::Tube::Line objects.
=head2 C<get_node_by_id>
my $station = $obj->get_node_by_id($station_id);
Get station node by id.
Returns Map::Tube::Node object.
=head2 C<get_node_by_name>
my $station = $obj->get_node_by_name($station_name);
Get station node by name.
Returns Map::Tube::Node object.
=head2 C<get_shortest_route>
my $route = $obj->get_shortest_route($from, $to);
Get shortest route between $from and $to node names. Node names in $from and $to are case insensitive.
Returns Map::Tube::Route object.
=head2 C<get_stations>
my $stations_ar = $obj->get_stations($line);
Get list of stations for concrete metro line.
Returns reference to array with Map::Tube::Node objects.
=head2 C<name>
my $metro_name = $obj->name;
Get metro name.
Returns string with metro name.
=head2 C<xml>
my $xml = $obj->xml;
Get XML specification of Warsaw metro.
Returns string with XML.
=head1 EXAMPLE1
use strict;
use warnings;
use Encode qw(decode_utf8 encode_utf8);
use Map::Tube::Warsaw;
# Object.
my $obj = Map::Tube::Warsaw->new;
# Get route.
my $route = $obj->get_shortest_route(decode_utf8('Imielin'), decode_utf8('Świętokrzyska'));
# Print out type.
print "Route: ".encode_utf8($route)."\n";
# Output:
# Route: Imielin (Linia M1), Stokłosy (Linia M1), Ursynów (Linia M1), Służew (Linia M1), Wilanowska (Linia M1), Wierzbno (Linia M1), Racławicka (Linia M1), Pole Mokotowskie (Linia M1), Politechnika (Linia M1), Centrum (Linia M1), Świętokrzyska (Linia M1)
=head1 EXAMPLE2
use strict;
use warnings;
use Map::Tube::Warsaw;
# Object.
my $obj = Map::Tube::Warsaw->new;
# Get XML file.
my $xml_file = $obj->xml;
# Print out XML file.
print "XML file: $xml_file\n";
# Output like:
# XML file: .*/warsaw-map.xml
=head1 EXAMPLE3
use strict;
use warnings;
use Map::Tube::GraphViz;
use Map::Tube::GraphViz::Utils qw(node_color_without_label);
use Map::Tube::Warsaw;
# Object.
my $obj = Map::Tube::Warsaw->new;
# GraphViz object.
my $g = Map::Tube::GraphViz->new(
'callback_node' => \&node_color_without_label,
'tube' => $obj,
);
# Get graph to file.
$g->graph('Warsaw.png');
# Print file.
system "ls -l Warsaw.png";
# Output like:
# -rw-r--r-- 1 skim skim 90061 lis 3 23:18 Warsaw.png
=begin html
<a href="https://raw.githubusercontent.com/michal-josef-spacek/Map-Tube-Warsaw/master/images/ex3.png">
<img src="https://raw.githubusercontent.com/michal-josef-spacek/Map-Tube-Warsaw/master/images/ex3.png" alt="Metro w Warszawie" width="300px" height="300px" />
</a>
=end html
=head1 EXAMPLE4
use strict;
use warnings;
use Encode qw(encode_utf8);
use Map::Tube::Warsaw;
# Object.
my $obj = Map::Tube::Warsaw->new;
# Get lines.
my $lines_ar = $obj->get_lines;
# Print out.
map { print encode_utf8($_->name)."\n"; } sort @{$lines_ar};
# Output:
# Linia M1
# Linia M2
=head1 EXAMPLE5
use strict;
use warnings;
use Encode qw(encode_utf8);
use Map::Tube::Warsaw;
# Arguments.
if (@ARGV < 1) {
print STDERR "Usage: $0 line\n";
exit 1;
}
my $line = $ARGV[0];
# Object.
my $obj = Map::Tube::Warsaw->new;
# Get stations for line.
my $stations_ar = $obj->get_stations($line);
# Print out.
map { print encode_utf8($_->name)."\n"; } @{$stations_ar};
# Output:
# Usage: __PROG__ line
# Output with 'foo' argument.
# Map::Tube::get_stations(): ERROR: Invalid Line Name [foo]. (status: 105) file __PROG__ on line __LINE__
# Output with 'Linia M1' argument.
# Kabaty
# Natolin
# Imielin
# Stokłosy
# Ursynów
# Służew
# Wilanowska
# Wierzbno
# Racławicka
# Pole Mokotowskie
# Politechnika
# Centrum
# Świętokrzyska
# Ratusz Arsenał
# Dworzec Gdański
# Plac Wilsona
# Marymont
# Słodowiec
# Stare Bielany
# Wawrzyszew
# Młociny
=head1 DEPENDENCIES
L<File::Share>,
L<Map::Tube>,
L<Moo>,
L<namespace::clean>.
=head1 SEE ALSO
=over
=item L<Map::Tube>
Core library as Role (Moo) to process map data.
=item L<Task::Map::Tube>
Install the Map::Tube modules.
=item L<Task::Map::Tube::Metro>
Install the Map::Tube concrete metro modules.
=back
=head1 REPOSITORY
L<https://github.com/michal-josef-spacek/Map-Tube-Warsaw>
=head1 AUTHOR
Michal Josef Špaček L<mailto:skim@cpan.org>
L<http://skim.cz>
=head1 LICENSE AND COPYRIGHT
© 2014-2021 Michal Josef Špaček
Artistic License
BSD 2-Clause License
=head1 VERSION
0.09
=cut