API.pm

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