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.42';
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.42
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 B<"Introduction to Map::Tube"> at B<German Perl Workshop 2018>.
29  
30 It currently only covers the following metro lines.
31  
32 =over 4
33  
34 =item * L<L1|Map::Tube::Madrid::Line::L1>
35  
36 =item * L<L2|Map::Tube::Madrid::Line::L2>
37  
38 =item * L<L3|Map::Tube::Madrid::Line::L3>
39  
40 =item * L<L4|Map::Tube::Madrid::Line::L4>
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 * L6
53  
54 =item * L7
55  
56 =item * L8
57  
58 =item * L9
59  
60 =item * L10
61  
62 =item * L12
63  
64 =back
65  
66 =head1 MAP DATA
67  
68 The map data collected from L<this website|https://en.wikipedia.org/wiki/Madrid_Metro>.
69  
70 =head1 CONSTRUCTOR
71  
72 The constructor DO NOT expects parameters.This setup the default node definitions.
73  
74 use strict; use warnings;
75 use Map::Tube::Madrid;
76  
77 my $metro = Map::Tube::Madrid->new;
78  
79 =head1 METHODS
80  
81 =head2 get_shortest_route($from, $to)
82  
83 It expects C<$from> and C<$to> station name, required param. It returns an object
84 of type L<Map::Tube::Route>. On error it throws exception of type L<Map::Tube::Exception>.
85  
86 use strict; use warnings;
87 use Map::Tube::Madrid;
88  
89 my $metro = Map::Tube::Madrid->new;
90 my $route = $metro->get_shortest_route('Sol', 'Delicias');
91  
92 print "Route: $route\n";
93  
94 =head2 as_image($line_name)
95  
96 It expects the plugin L<Map::Tube::Plugin::Graph> to be installed. Returns line
97 image as base64 encoded string if C<$line_name> passed in otherwise it returns
98 base64 encoded string of the entire map.
99  
100 use strict; use warnings;
101 use MIME::Base64;
102 use Map::Tube::Madrid;
103  
104 my $metro = Map::Tube::Madrid->new;
105  
106 # Entire map image
107 my $map = $metro->name;
108 open(my $MAP_IMAGE, ">", "$map.png")
109 or die "ERROR: Can't open [$map.png]: $!";
110 binmode($MAP_IMAGE);
111 print $MAP_IMAGE decode_base64($metro->as_image);
112 close($MAP_IMAGE);
113  
114 # Just a particular line map image
115 my $line = 'L3';
116 open(my $LINE_IMAGE, ">", "$line.png")
117 or die "ERROR: Can't open [$line.png]: $!";
118 binmode($LINE_IMAGE);
119 print $LINE_IMAGE decode_base64($metro->as_image($line));
120 close($LINE_IMAGE);
121  
122 The L<Madrid Metro Map|https://raw.githubusercontent.com/manwar/Map-Tube-Madrid/master/maps/Madrid-Metro.png>
123 map as generated by plugin L<Map::Tube::Plugin::Graph>.
124  
125 =begin html
126  
127 <a href = "https://raw.githubusercontent.com/manwar/Map-Tube-Madrid/master/maps/Madrid-Metro.png">
128 <img src = "https://raw.githubusercontent.com/manwar/Map-Tube-Madrid/master/maps/Madrid-Metro.png"
129 alt = "Madrid Metro Map"
130 width = "500px"
131 height = "900px"/>
132 </a>
133  
134 =end html
135  
136 =head1 AUTHOR
137  
138 Mohammad Sajid Anwar, C<< <mohammad.anwar at yahoo.com> >>
139  
140 =head1 BUGS
141  
142 Please report any bugs or feature requests through the web interface at L<https://github.com/manwar/Map-Tube-Madrid/issues>.
143 I will be notified and then you'll automatically be notified of progress on your
144 bug as I make changes.
145  
146 =head1 SUPPORT
147  
148 You can find documentation for this module with the perldoc command.
149  
150 perldoc Map::Tube::Madrid
151  
152 You can also look for information at:
153  
154 =over 4
155  
156 =item * BUG Report
157  
158 L<https://github.com/manwar/Map-Tube-Madrid/issues>
159  
160 =item * CPAN Ratings
161  
162 L<http://cpanratings.perl.org/d/Map-Tube-Madrid>
163  
164 =item * Search MetaCPAN
165  
166 L<https://metacpan.org/dist/Map-Tube-Madrid/>
167  
168 =back
169  
170 =head1 LICENSE AND COPYRIGHT
171  
172 Copyright (C) 2018 - 2025 Mohammad Sajid Anwar.
173  
174 This program is free software; you can redistribute it and / or modify it under
175 the terms of the the Artistic License (2.0). You may obtain a copy of the full
176 license at:
177  
178 L<http://www.perlfoundation.org/artistic_license_2_0>
179  
180 Any use, modification, and distribution of the Standard or Modified Versions is
181 governed by this Artistic License.By using, modifying or distributing the Package,
182 you accept this license. Do not use, modify, or distribute the Package, if you do
183 not accept this license.
184  
185 If your Modified Version has been derived from a Modified Version made by someone
186 other than you,you are nevertheless required to ensure that your Modified Version
187 complies with the requirements of this license.
188  
189 This license does not grant you the right to use any trademark, service mark,
190 tradename, or logo of the Copyright Holder.
191  
192 This license includes the non-exclusive, worldwide, free-of-charge patent license
193 to make, have made, use, offer to sell, sell, import and otherwise transfer the
194 Package with respect to any patent claims licensable by the Copyright Holder that
195 are necessarily infringed by the Package. If you institute patent litigation
196 (including a cross-claim or counterclaim) against any party alleging that the
197 Package constitutes direct or contributory patent infringement,then this Artistic
198 License to you shall terminate on the date that such litigation is filed.
199  
200 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
201 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
202 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
203 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
204 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
205 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
206 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
207  
208 =cut
209  
210 1; # End of Map::Tube::Madrid
↑ Summary Madrid/Line/L1.pm »