The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Map::Tube - A very simple perl interface to the London Tube Map.

VERSION

Version 0.08

SYNOPSIS

Here is sample map

    1 --------  2 
   /  \       /  \
  /    \     /    \
 /      \   /      \
0 ------  6 ------- 3
 \      /   \      /
  \    /     \    /
   \  /       \  / 
    5 -------- 4 
   /
  /
 /  
7
 \
  \
   \
    8 
   

which can be defined as below:

{ 0 => [1,5,6], 1 => [0,2,6], 2 => [1,3,6], 3 => [2,4,6], 4 => [3,5,6], 5 => [0,4,6,7], 6 => [0,1,2,3,4,5], 7 => [5,8], 8 => [7],};

Description

The module intends to provide you as much information as possible from London Tube Map through perl interface. The very first thing anyone would like to know from any map is to find the shortest route between two point. This is exactly what I am trying to solve at the moment. However I would be adding more interesting information very soon. This module covers some of the underground lines managed by Travel for London. It is far from complete and bound to have missing links and incorrect mapping. Please feel free to shout back to me, if you find any error/issue. While trying to find the shortest route, it takes into account the number of stops one has to go through to reach the destination. I do agree, at times, you wouldn't mind going through few extra stops, to avoid changing lines. I might add this behaviour in future. Please note Map::Tube doesn't try to explain Dijkstra's algorithm but to provide a perl interface to the London Tube Map. As of today, it covers Bakerloo, Central, Circle, District, Hammersmith & City, Jubilee, Metropolitan, Northern and Victoria. I have been working hard to cover the remaining Picadilly and Waterloo & City. Here is the link to the official London Tube Map: http://www.tfl.gov.uk/assets/downloads/standard-tube-map.pdf

Example

  use Map::Tube;
  my $map = Map::Tube->new();
  my @route = $map->get_shortest_route('Bond Street', 'Euston');
  print "Shortest route from 'Bond Street' to 'Euston': " . join(" => ",@route) . "\n";  

  Output:
  Shortest route from Bond Street to Euston: Bond Street => Oxford Circus => Warren Street => Euston

CONSTRUCTOR

The constructor expects an optional debug flag which is 0(false) by default.

METHODS

get_shortest_route()

This method accepts FROM and TO node name. It is case sensitive at the moment. However I would make it case-insensitive very soon. It returns back the node sequence from FROM to TO.

show_map_chart()

This method takes no parameter. It prints map chart to STDOUT generated while looking for shortest route. It has three columns by the title "N" - Node Code, "P" - Path to here and "L" - Length to reach "N" from "P". At the moment it dumps node code used internally, however, I would change that to dump real node name instead soon.

get_nodes()

Returns all the node's map defintions.

get_elements()

Returns all the elements i.e. node defintions.

_process_node

This is an internal method of the module, which takes FROM node code only. This assumes all the node definitions are defined and map chart has been initialized.

_initialize_table()

This is an internal method and it simply initialize the map chart. It takes nodes definition as reference to a hash and return the table, which is also reference to a hash.

_get_name()

This is an internal method and not exposed to the outside world. It takes node code and gives us full name of the node. It is only called from the method get_shortest_route().

AUTHOR

Mohammad S Anwar, <mohammad.anwar@yahoo.com>

ACKNOWLEDGEMENTS

Peter Makholm (http://search.cpan.org/~pmakholm/) for valuable advice.

BUGS

Please report any bugs or feature requests to bug-map-tube@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Map-Tube. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Map::Tube

You can also look for information at:

LICENSE AND COPYRIGHT

Copyright 2010 Mohammad S Anwar.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.