API.pm

filter: Statementstmt 41.0% 23 / 56 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 46.1% 6 / 13 Podpod 100% 4 / 4 totaltotal 27.7% 33 / 119 CC 15 SCAR 31.1
CC
15
Cov
26%
shortest_route
56.0
line_stations
30.0
map_stations
12.0
CRAP 22.5
↑ Summary API/UserAgent.pm »
1 package Map::Tube::API;
2  
3 1 $Map::Tube::API::VERSION = '0.09';
4 1 $Map::Tube::API::AUTHORITY = 'cpan:MANWAR';
5  
6 =head1 NAME
7  
8 Map::Tube::API - Interface to Map::Tube REST API.
9  
10 =head1 VERSION
11  
12 Version 0.09
13  
14 =cut
15  
16 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶use Map::Tube::API::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 extends 'Map::Tube::API::UserAgent';
25  
26 0 ▶has 'base_url' => (is => 'ro', default => sub { $ENV{'MAP_BASE_URL'} });
Subroutine __ANON__: not called CC=1 SCAR=1.2
27 0 ▶has 'version' => (is => 'ro', default => sub { $ENV{'MAP_VERSION'} || 'v1' });
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
$ENV{"MAP_VERSION"} or "v1" 0 0 0
28  
29 =head1 DESCRIPTION
30  
31 Map::Tube REST API is still in beta. No API key is required at the moment.
32  
33 =head1 MAP NAMES
34  
35 =over 2
36  
37 =item Barcelona
38  
39 =item Beijing
40  
41 =item Berlin
42  
43 =item Bielefeld
44  
45 =item Bucharest
46  
47 =item Budapest
48  
49 =item Delhi
50  
51 =item Dnipropetrovsk
52  
53 =item Glasgow
54  
55 =item Kazan
56  
57 =item Kharkiv
58  
59 =item Kiev
60  
61 =item KoelnBonn
62  
63 =item Kolkatta
64  
65 =item KualaLumpur
66  
67 =item London
68  
69 =item Lyon
70  
71 =item Malaga
72  
73 =item Minsk
74  
75 =item Moscow
76  
77 =item Nanjing
78  
79 =item NizhnyNovgorod
80  
81 =item Novosibirsk
82  
83 =item Prague
84  
85 =item Rome
86  
87 =item Rhein/Ruhr
88  
89 =item SaintPetersburg
90  
91 =item Samara
92  
93 =item Singapore
94  
95 =item Sofia
96  
97 =item Tbilisi
98  
99 =item Toulouse
100  
101 =item Vienna
102  
103 =item Warsaw
104  
105 =item Yekaterinburg
106  
107 =back
108  
109 =head1 CONSTRUCTOR
110  
111 Optionally you can provide C<base_url> of REST API and also the C<version>. Default
112 version is C<v1>.
113  
114 You can even set the environment variable C<MAP_BASE_URL> and C<MAP_VERSION>.
115  
116 use strict; use warnings;
117 use Map::Tube::API;
118  
119 my $api = Map::Tube::API->new;
120  
121 =head1 METHODS
122  
123 =head2 shortest_route(\%params)
124  
125 Returns list of stations for the shortest route.The parameters should be as below
126  
127 +-------+-------------------------------------------------------------------+
128 | Key | Description |
129 +-------+-------------------------------------------------------------------+
130 | map | A valid map name. |
131 | start | A valid start station name in the given map. |
132 | end | A valid end station name in the give map. |
133 +-------+-------------------------------------------------------------------+
134  
135 use strict; use warnings;
136 use Map::Tube::API;
137  
138 my $api = Map::Tube::API->new;
139 my $route = $api->shortest_route({ map => 'london', start => 'Baker Street', end => 'Wembley Park' });
140  
141 =cut
142  
143 sub shortest_route {
144 0 ▶ my ($self, $params) = @_;
Subroutine shortest_route: not called CC=7 SCAR=40.3
Pod documented
145  
146 0 my $map = $params->{map};
147 0 ▶ die "ERROR: Missing map name."
Branch: 1 branch
BranchTrueFalseTotal
unless defined $map and not $map =~ /^$/ 0 0 0
Condition0%0/3
defined $map and not $map =~ /^$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $map and not $map =~ /^$/
defined $map not $map =~ /^$/
Truth table0%0/3
A and not(B)
A= defined $mapB= not $map =~ /^$/
ABresult
0X0
100
111
148 unless (defined $map && ($map !~ /^$/));
149  
150 0 my $start = $params->{start};
151 0 ▶ die "ERROR: Missing start station name."
Branch: 1 branch
BranchTrueFalseTotal
unless defined $start and not $start =~ /^$/ 0 0 0
Condition0%0/3
defined $start and not $start =~ /^$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $start and not $start =~ /^$/
defined $start not $start =~ /^$/
Truth table0%0/3
A and not(B)
A= defined $startB= not $start =~ /^$/
ABresult
0X0
100
111
152 unless (defined $start && ($start !~ /^$/));
153  
154 0 my $end = $params->{end};
155 0 ▶ die "ERROR: Missing end station name."
Branch: 1 branch
BranchTrueFalseTotal
unless defined $end and not $end =~ /^$/ 0 0 0
Condition0%0/3
defined $end and not $end =~ /^$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $end and not $end =~ /^$/
defined $end not $end =~ /^$/
Truth table0%0/3
A and not(B)
A= defined $endB= not $end =~ /^$/
ABresult
0X0
100
111
156 unless (defined $end && ($end !~ /^$/));
157  
158 0 my $url = sprintf("%s/shortest-route/%s/%s/%s", $self->_base_url, $map, $start, $end);
159 0 my $response = $self->get($url);
160  
161 0 return JSON->new->allow_nonref->utf8(1)->decode($response->decoded_content);
162 }
163  
164 =head2 line_stations(\%params)
165  
166 Returns list of stations. The parameters should be as below:
167  
168 +-------+-------------------------------------------------------------------+
169 | Key | Description |
170 +-------+-------------------------------------------------------------------+
171 | map | A valid map name. |
172 | line | A valid line name in the given map. |
173 +-------+-------------------------------------------------------------------+
174  
175 use strict; use warnings;
176 use Map::Tube::API;
177  
178 my $api = Map::Tube::API->new;
179 my $stations = $api->line_stations({ map => 'london', line => 'Metropolitan' });
180  
181 =cut
182  
183 sub line_stations {
184 0 ▶ my ($self, $params) = @_;
Subroutine line_stations: not called CC=5 SCAR=34.0
Pod documented
185  
186 0 my $map = $params->{map};
187 0 ▶ die "ERROR: Missing map name."
Branch: 1 branch
BranchTrueFalseTotal
unless defined $map and not $map =~ /^$/ 0 0 0
Condition0%0/3
defined $map and not $map =~ /^$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $map and not $map =~ /^$/
defined $map not $map =~ /^$/
Truth table0%0/3
A and not(B)
A= defined $mapB= not $map =~ /^$/
ABresult
0X0
100
111
188 unless (defined $map && ($map !~ /^$/));
189  
190 0 my $line = $params->{line};
191 0 ▶ die "ERROR: Missing line name."
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line and not $line =~ /^$/ 0 0 0
Condition0%0/3
defined $line and not $line =~ /^$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $line and not $line =~ /^$/
defined $line not $line =~ /^$/
Truth table0%0/3
A and not(B)
A= defined $lineB= not $line =~ /^$/
ABresult
0X0
100
111
192 unless (defined $line && ($line !~ /^$/));
193  
194 0 my $url = sprintf("%s/stations/%s/%s", $self->_base_url, $map, $line);
195 0 my $response = $self->get($url);
196  
197 0 return JSON->new->allow_nonref->utf8(1)->decode($response->decoded_content);
198 }
199  
200 =head2 map_stations(\%params)
201  
202 Returns list of stations for the given map.
203  
204 +-------+-------------------------------------------------------------------+
205 | Key | Description |
206 +-------+-------------------------------------------------------------------+
207 | map | A valid map name. |
208 +-------+-------------------------------------------------------------------+
209  
210 use strict; use warnings;
211 use Map::Tube::API;
212  
213 my $api = Map::Tube::API->new;
214 my $stations = $api->map_stations({ map => 'london' });
215  
216 =cut
217  
218 sub map_stations {
219 0 ▶ my ($self, $params) = @_;
Subroutine map_stations: not called CC=3 SCAR=24.8
Pod documented
220  
221 0 my $map = $params->{map};
222 0 ▶ die "ERROR: Missing map name."
Branch: 1 branch
BranchTrueFalseTotal
unless defined $map and not $map =~ /^$/ 0 0 0
Condition0%0/3
defined $map and not $map =~ /^$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $map and not $map =~ /^$/
defined $map not $map =~ /^$/
Truth table0%0/3
A and not(B)
A= defined $mapB= not $map =~ /^$/
ABresult
0X0
100
111
223 unless (defined $map && ($map !~ /^$/));
224  
225 0 my $url = sprintf("%s/stations/%s", $self->_base_url, $map);
226 0 my $response = $self->get($url);
227  
228 0 return JSON->new->allow_nonref->utf8(1)->decode($response->decoded_content);
229 }
230  
231 =head2 available_maps()
232  
233 Returns list of available maps.
234  
235 use strict; use warnings;
236 use Map::Tube::API;
237  
238 my $api = Map::Tube::API->new;
239 my $maps = $api->available_maps({ map => 'london' });
240  
241 =cut
242  
243 sub available_maps {
244 0 ▶ my ($self) = @_;
Subroutine available_maps: not called CC=1 SCAR=6.9
Pod documented
245  
246 0 my $url = sprintf("%s/maps", $self->_base_url);
247 0 my $response = $self->get($url);
248  
249 0 return JSON->new->allow_nonref->utf8(1)->decode($response->decoded_content);
250 }
251  
252 #
253 #
254 # PRIVATE METHODS
255  
256 sub _base_url {
257 0 ▶ my ($self) = @_;
Subroutine _base_url: not called CC=2 SCAR=17.9
258  
259 0 ▶ die "ERROR: Missing map base url, please set env MAP_BASE_URL."
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->base_url 0 0 0
260 unless defined $self->base_url;
261  
262 0 return sprintf("%s/map-tube/%s", $self->base_url, $self->version);
263 }
264  
265 =head1 AUTHOR
266  
267 Mohammad Sajid Anwar, C<< <mohammad.anwar at yahoo.com> >>
268  
269 =head1 REPOSITORY
270  
271 L<https://github.com/manwar/Map-Tube-API>
272  
273 =head1 BUGS
274  
275 Please report any bugs or feature requests to C<bug-map-tube-api at rt.cpan.org>,
276 or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Map-Tube-API>.
277 I will be notified, and then you'll automatically be notified of progress on your
278 bug as I make changes.
279  
280 =head1 SUPPORT
281  
282 You can find documentation for this module with the perldoc command.
283  
284 perldoc Map::Tube::API
285  
286 You can also look for information at:
287  
288 =over 4
289  
290 =item * BUGS / ISSUES
291  
292 L<https://github.com/manwar/Map-Tube-API/issues>
293  
294 =item * AnnoCPAN: Annotated CPAN documentation
295  
296 L<http://annocpan.org/dist/Map-Tube-API>
297  
298 =item * CPAN Ratings
299  
300 L<http://cpanratings.perl.org/d/Map-Tube-API>
301  
302 =item * Search MetaCPAN
303  
304 L<https://metacpan.org/pod/Map::Tube::API>
305  
306 =back
307  
308 =head1 LICENSE AND COPYRIGHT
309  
310 Copyright (C) 2024 - 2025 Mohammad Sajid Anwar.
311  
312 This program is free software; you can redistribute it and/or modify it under
313 the terms of the the Artistic License (2.0). You may obtain a copy of the full
314 license at:
315  
316 L<http://www.perlfoundation.org/artistic_license_2_0>
317  
318 Any use, modification, and distribution of the Standard or Modified Versions is
319 governed by this Artistic License.By using, modifying or distributing the Package,
320 you accept this license. Do not use, modify, or distribute the Package, if you do
321 not accept this license.
322  
323 If your Modified Version has been derived from a Modified Version made by someone
324 other than you,you are nevertheless required to ensure that your Modified Version
325 complies with the requirements of this license.
326  
327 This license does not grant you the right to use any trademark, service mark,
328 tradename, or logo of the Copyright Holder.
329  
330 This license includes the non-exclusive, worldwide, free-of-charge patent license
331 to make, have made, use, offer to sell, sell, import and otherwise transfer the
332 Package with respect to any patent claims licensable by the Copyright Holder that
333 are necessarily infringed by the Package. If you institute patent litigation
334 (including a cross-claim or counterclaim) against any party alleging that the
335 Package constitutes direct or contributory patent infringement,then this Artistic
336 License to you shall terminate on the date that such litigation is filed.
337  
338 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
339 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
340 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
341 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
342 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
343 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
344 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
345  
346 =cut
347  
348 1 1; # End of Map::Tube::API
↑ Summary API/UserAgent.pm »