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