line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer2::Plugin::Map::Tube; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$Dancer2::Plugin::Map::Tube::VERSION = '0.02'; |
4
|
|
|
|
|
|
|
$Dancer2::Plugin::Map::Tube::AUTHORITY = 'cpan:MANWAR'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Dancer2::Plugin::Map::Tube - Dancer2 add-on for Map::Tube. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.02 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
53487
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
17
|
1
|
|
|
1
|
|
4
|
use strict; use warnings; |
|
1
|
|
|
1
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
18
|
1
|
|
|
1
|
|
484
|
use Data::Dumper; |
|
1
|
|
|
|
|
5347
|
|
|
1
|
|
|
|
|
48
|
|
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
367
|
use Class::Load qw(try_load_class); |
|
1
|
|
|
|
|
15682
|
|
|
1
|
|
|
|
|
46
|
|
21
|
1
|
|
|
1
|
|
393
|
use Dancer2::Plugin::Map::Tube::API; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
30
|
|
22
|
1
|
|
|
1
|
|
453
|
use Dancer2::Plugin; |
|
1
|
|
|
|
|
164398
|
|
|
1
|
|
|
|
|
7
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 DESCRIPTION |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
It provides the REST API features for L.It holds the supported |
27
|
|
|
|
|
|
|
map informations. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Currently users are allowed to make 6 api calls per minute. Other than that there |
30
|
|
|
|
|
|
|
are no restrictions for now. In future, we would allow access by API KEY. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Please be gentle as it's running on tiny RaspberryPI box sitting in the corner of |
33
|
|
|
|
|
|
|
my bedroom. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 SYNOPSIS |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
get '/map-tube/v1/shortest-route/:map/:start/:end' => sub { |
38
|
|
|
|
|
|
|
my $client = request->address; |
39
|
|
|
|
|
|
|
my $name = route_parameters->get('map'); |
40
|
|
|
|
|
|
|
my $start = route_parameters->get('start'); |
41
|
|
|
|
|
|
|
my $end = route_parameters->get('end'); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $response = api($name)->shortest_route($client, $start, $end); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
... |
46
|
|
|
|
|
|
|
... |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
return $response->{content}; |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
get '/map-tube/v1/stations/:map/:line' => sub { |
52
|
|
|
|
|
|
|
my $client = request->address; |
53
|
|
|
|
|
|
|
my $name = route_parameters->get('map'); |
54
|
|
|
|
|
|
|
my $line = route_parameters->get('line'); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $response = api($name)->line_stations($client, $line); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
... |
59
|
|
|
|
|
|
|
... |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
return $response->{content}; |
62
|
|
|
|
|
|
|
}; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
get '/map-tube/v1/stations/:map' => sub { |
65
|
|
|
|
|
|
|
my $client = request->address; |
66
|
|
|
|
|
|
|
my $name = route_parameters->get('map'); |
67
|
|
|
|
|
|
|
my $response = api($name)->map_stations($client); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
... |
70
|
|
|
|
|
|
|
... |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
return $response->{content}; |
73
|
|
|
|
|
|
|
}; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
get '/map-tube/v1/maps' => sub { |
76
|
|
|
|
|
|
|
my $client = request->address; |
77
|
|
|
|
|
|
|
my $response = api->available_maps($client); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
... |
80
|
|
|
|
|
|
|
... |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
return $response->{content}; |
83
|
|
|
|
|
|
|
}; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 METHODS |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 api($map_name) |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Returns an object of type L.The C<$map_name> can |
90
|
|
|
|
|
|
|
be one of the following supported maps. Please make sure map is installed first. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=over 2 |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=item Barcelona |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item Beijing |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item Berlin |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item Bucharest |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item Budapest |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item Delhi |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item Dnipropetrovsk |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item Glasgow |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item Kazan |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item Kharkiv |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item Kiev |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item KoelnBonn |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item Kolkatta |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item KualaLumpur |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item London |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item Lyon |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item Malaga |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item Minsk |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item Moscow |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item Nanjing |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item NizhnyNovgorod |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item Novosibirsk |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item Prague |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item SaintPetersburg |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item Samara |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item Singapore |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item Sofia |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item Tbilisi |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item Vienna |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item Warsaw |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item Yekaterinburg |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=back |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=cut |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
our $INSTALLED_MAPS; |
161
|
|
|
|
|
|
|
our $SUPPORTED_MAPS = [qw/ |
162
|
|
|
|
|
|
|
Barcelona Beijing Berlin Bucharest Budapest |
163
|
|
|
|
|
|
|
Delhi Dnipropetrovsk Glasgow Kazan Kharkiv |
164
|
|
|
|
|
|
|
Kiev KoelnBonn Kolkatta KualaLumpur London |
165
|
|
|
|
|
|
|
Lyon Malaga Minsk Moscow Nanjing |
166
|
|
|
|
|
|
|
NizhnyNovgorod Novosibirsk Prague SaintPetersburg Samara |
167
|
|
|
|
|
|
|
Singapore Sofia Tbilisi Vienna Warsaw |
168
|
|
|
|
|
|
|
Yekaterinburg/]; |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
register api => sub { |
171
|
0
|
|
|
0
|
|
|
my ($dsl, $map_name) = @_; |
172
|
|
|
|
|
|
|
|
173
|
0
|
|
|
|
|
|
my $params = { map_name => $map_name }; |
174
|
0
|
|
|
|
|
|
my $conf = plugin_setting(); |
175
|
0
|
0
|
|
|
|
|
if (exists $conf->{user_maps}) { |
176
|
0
|
|
|
|
|
|
my $maps = $conf->{user_maps}; |
177
|
0
|
0
|
|
|
|
|
$params->{user_maps} = $maps if (scalar(@$maps)); |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
$params->{supported_maps} = { map { $_ => 1 } @$SUPPORTED_MAPS }; |
|
0
|
|
|
|
|
|
|
181
|
0
|
|
|
|
|
|
$params->{map_names} = { map { lc($_) => $_ } @$SUPPORTED_MAPS }; |
|
0
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
# If user has provided list of maps then make only those available. |
184
|
0
|
|
|
|
|
|
my $user_maps = {}; |
185
|
0
|
0
|
|
|
|
|
if (defined $params->{user_maps}) { |
186
|
|
|
|
|
|
|
$user_maps = { |
187
|
|
|
|
|
|
|
map { |
188
|
0
|
|
|
|
|
|
'Map::Tube::'. $params->{map_names}->{lc($_)} => 1 |
189
|
|
|
|
|
|
|
} |
190
|
0
|
|
|
|
|
|
@{$params->{user_maps}} |
|
0
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
}; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
0
|
|
|
|
|
|
my $maps = { map { 'Map::Tube::'.$_ => $_ } @$SUPPORTED_MAPS }; |
|
0
|
|
|
|
|
|
|
195
|
0
|
|
|
|
|
|
foreach my $map (keys %$maps) { |
196
|
0
|
0
|
|
|
|
|
try_load_class($map) or next; |
197
|
0
|
0
|
0
|
|
|
|
next if (scalar(keys %$user_maps) && !exists $user_maps->{$map}); |
198
|
0
|
|
|
|
|
|
$INSTALLED_MAPS->{$maps->{$map}} = $map->new; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
0
|
|
|
|
|
|
$params->{installed_maps} = $INSTALLED_MAPS; |
202
|
|
|
|
|
|
|
|
203
|
0
|
|
|
|
|
|
return Dancer2::Plugin::Map::Tube::API->new($params); |
204
|
|
|
|
|
|
|
}; |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
register_plugin; |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 AUTHOR |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Mohammad S Anwar, C<< >> |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 REPOSITORY |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
L |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 BUGS |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, |
219
|
|
|
|
|
|
|
or through the web interface at L. |
220
|
|
|
|
|
|
|
I will be notified and then you'll automatically be notified of progress on your |
221
|
|
|
|
|
|
|
bug as I make changes. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head1 SUPPORT |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
perldoc Dancer2::Plugin::Map::Tube |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
You can also look for information at: |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=over 4 |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
L |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
L |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=item * CPAN Ratings |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
L |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=item * Search CPAN |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
L |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=back |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
Copyright (C) 2018 Mohammad S Anwar. |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
This program is free software; you can redistribute it and / or modify it under |
256
|
|
|
|
|
|
|
the terms of the the Artistic License (2.0). You may obtain a copy of the full |
257
|
|
|
|
|
|
|
license at: |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
L |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified Versions is |
262
|
|
|
|
|
|
|
governed by this Artistic License.By using, modifying or distributing the Package, |
263
|
|
|
|
|
|
|
you accept this license. Do not use, modify, or distribute the Package, if you do |
264
|
|
|
|
|
|
|
not accept this license. |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made by someone |
267
|
|
|
|
|
|
|
other than you,you are nevertheless required to ensure that your Modified Version |
268
|
|
|
|
|
|
|
complies with the requirements of this license. |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service mark, |
271
|
|
|
|
|
|
|
tradename, or logo of the Copyright Holder. |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge patent license |
274
|
|
|
|
|
|
|
to make, have made, use, offer to sell, sell, import and otherwise transfer the |
275
|
|
|
|
|
|
|
Package with respect to any patent claims licensable by the Copyright Holder that |
276
|
|
|
|
|
|
|
are necessarily infringed by the Package. If you institute patent litigation |
277
|
|
|
|
|
|
|
(including a cross-claim or counterclaim) against any party alleging that the |
278
|
|
|
|
|
|
|
Package constitutes direct or contributory patent infringement,then this Artistic |
279
|
|
|
|
|
|
|
License to you shall terminate on the date that such litigation is filed. |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND |
282
|
|
|
|
|
|
|
CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED |
283
|
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR |
284
|
|
|
|
|
|
|
NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS |
285
|
|
|
|
|
|
|
REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, |
286
|
|
|
|
|
|
|
INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE |
287
|
|
|
|
|
|
|
OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=cut |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
1; # End of Dancer2::Plugin::Map::Tube |