Madrid.pm

filter: Statementstmt 100% 14 / 14 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 100% 19 / 19 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
↑ Summary Madrid/Line/L1.pm »
1 package Map::Tube::Madrid;
2  
3 $Map::Tube::Madrid::VERSION = '0.21';
4 $Map::Tube::Madrid::AUTHORITY = 'cpan:MANWAR';
5  
6 =head1 NAME
7  
8 Map::Tube::Madrid - Interface to the Madrid Metro Map.
9  
10 =head1 VERSION
11  
12 Version 0.21
13  
14 =cut
15  
16 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use File::ShareDir ':ALL';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 has json => (is => 'ro', default => sub { return dist_file('Map-Tube-Madrid', 'madrid-map.json') });
24 with 'Map::Tube';
25  
26 =head1 DESCRIPTION
27  
28 Built and released while giving talk on the topic "Introduction to Map::Tube" at
29 German Perl Workshop 2018.
30 Source: L<map|https://www.planometromadrid.org/mapas-metro/plano-metro-madrid-2018-01.png>
31  
32 It currently only covers the following metro lines.
33  
34 =over 4
35  
36 =item * L<L1|Map::Tube::Madrid::Line::L1>
37  
38 =item * L<L2|Map::Tube::Madrid::Line::L2>
39  
40 =item * L<L3|Map::Tube::Madrid::Line::L3>
41  
42 =item * L<L5|Map::Tube::Madrid::Line::L5>
43  
44 =item * L<L11|Map::Tube::Madrid::Line::L11>
45  
46 =back
47  
48 =head1 TODO (Metro Lines)
49  
50 =over 4
51  
52 =item * L4
53  
54 =item * L6
55  
56 =item * L7
57  
58 =item * L8
59  
60 =item * L9
61  
62 =item * L10
63  
64 =item * L12
65  
66 =back
67  
68 =head1 CONSTRUCTOR
69  
70 The constructor DO NOT expects parameters.This setup the default node definitions.
71  
72 use strict; use warnings;
73 use Map::Tube::Madrid;
74  
75 my $metro = Map::Tube::Madrid->new;
76  
77 =head1 METHODS
78  
79 =head2 get_shortest_route($from, $to)
80  
81 It expects C<$from> and C<$to> station name, required param. It returns an object
82 of type L<Map::Tube::Route>. On error it throws exception of type L<Map::Tube::Exception>.
83  
84 use strict; use warnings;
85 use Map::Tube::Madrid;
86  
87 my $metro = Map::Tube::Madrid->new;
88 my $route = $metro->get_shortest_route('Sol', 'Delicias');
89  
90 print "Route: $route\n";
91  
92 =head2 as_image($line_name)
93  
94 It expects the plugin L<Map::Tube::Plugin::Graph> to be installed. Returns line
95 image as base64 encoded string if C<$line_name> passed in otherwise it returns
96 base64 encoded string of the entire map.
97  
98 use strict; use warnings;
99 use MIME::Base64;
100 use Map::Tube::Madrid;
101  
102 my $metro = Map::Tube::Madrid->new;
103  
104 # Entire map image
105 my $map = $metro->name;
106 open(my $MAP_IMAGE, ">", "$map.png")
107 or die "ERROR: Can't open [$map.png]: $!";
108 binmode($MAP_IMAGE);
109 print $MAP_IMAGE decode_base64($metro->as_image);
110 close($MAP_IMAGE);
111  
112 # Just a particular line map image
113 my $line = 'L3';
114 open(my $LINE_IMAGE, ">", "$line.png")
115 or die "ERROR: Can't open [$line.png]: $!";
116 binmode($LINE_IMAGE);
117 print $LINE_IMAGE decode_base64($metro->as_image($line));
118 close($LINE_IMAGE);
119  
120 The L<Madrid Metro Map|https://raw.githubusercontent.com/manwar/Map-Tube-Madrid/master/maps/Madrid-Metro.png>
121 map as generated by plugin L<Map::Tube::Plugin::Graph>.
122  
123 =begin html
124  
125 <a href = "https://raw.githubusercontent.com/manwar/Map-Tube-Madrid/master/maps/Madrid-Metro.png">
126 <img src = "https://raw.githubusercontent.com/manwar/Map-Tube-Madrid/master/maps/Madrid-Metro.png"
127 alt = "Madrid Metro Map"
128 width = "500px"
129 height = "900px"/>
130 </a>
131  
132 =end html
133  
134 =head1 AUTHOR
135  
136 Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
137  
138 =head1 BUGS
139  
140 Please report any bugs or feature requests to C<bug-map-tube-madrid at rt.cpan.org>,
141 or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Map-Tube-Madrid>.
142 I will be notified, and then you'll automatically be notified of progress on your
143 bug as I make changes.
144  
145 =head1 SUPPORT
146  
147 You can find documentation for this module with the perldoc command.
148  
149 perldoc Map::Tube::Madrid
150  
151 You can also look for information at:
152  
153 =over 4
154  
155 =item * RT: CPAN's request tracker (report bugs here)
156  
157 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Map-Tube-Madrid>
158  
159 =item * AnnoCPAN: Annotated CPAN documentation
160  
161 L<http://annocpan.org/dist/Map-Tube-Madrid>
162  
163 =item * CPAN Ratings
164  
165 L<http://cpanratings.perl.org/d/Map-Tube-Madrid>
166  
167 =item * Search CPAN
168  
169 L<http://search.cpan.org/dist/Map-Tube-Madrid/>
170  
171 =back
172  
173 =head1 LICENSE AND COPYRIGHT
174  
175 Copyright (C) 2018 Mohammad S Anwar.
176  
177 This program is free software; you can redistribute it and / or modify it under
178 the terms of the the Artistic License (2.0). You may obtain a copy of the full
179 license at:
180  
181 L<http://www.perlfoundation.org/artistic_license_2_0>
182  
183 Any use, modification, and distribution of the Standard or Modified Versions is
184 governed by this Artistic License.By using, modifying or distributing the Package,
185 you accept this license. Do not use, modify, or distribute the Package, if you do
186 not accept this license.
187  
188 If your Modified Version has been derived from a Modified Version made by someone
189 other than you,you are nevertheless required to ensure that your Modified Version
190 complies with the requirements of this license.
191  
192 This license does not grant you the right to use any trademark, service mark,
193 tradename, or logo of the Copyright Holder.
194  
195 This license includes the non-exclusive, worldwide, free-of-charge patent license
196 to make, have made, use, offer to sell, sell, import and otherwise transfer the
197 Package with respect to any patent claims licensable by the Copyright Holder that
198 are necessarily infringed by the Package. If you institute patent litigation
199 (including a cross-claim or counterclaim) against any party alleging that the
200 Package constitutes direct or contributory patent infringement,then this Artistic
201 License to you shall terminate on the date that such litigation is filed.
202  
203 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
204 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
205 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
206 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
207 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
208 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
209 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
210  
211 =cut
212  
213 1; # End of Map::Tube::Madrid
↑ Summary Madrid/Line/L1.pm »