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 1.2

SYNOPSIS

Here is sample map

    B --------  C 
   /  \       /  \
  /    \     /    \
 /      \   /      \
A ------  G ------- D
 \      /   \      /
  \    /     \    /
   \  /       \  / 
    F -------- E 
   /
  /
 /  
H
 \
  \
   \
    I 
   

which can be defined as below:

{ 'A' => ['B','F','G'], 'B' => ['A','C','G'], 'C' => ['B','D','G'], 'D' => ['C','E','G'], 'E' => ['D','F','G'], 'F' => ['A','E','G','H'], 'G' => ['A','B','C','D','E','F'], 'H' => ['F','I'], 'I' => ['H'] }

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, Piccadilly and Victoria. I shall be finishing the last remaining Waterloo & City line very soon. 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 insensitive. It returns back the node sequence from FROM to TO.

set_node()

This method accept the node defintion from user. It does some basic check i.e. the node data has to be reference to a HASH and each key has a value which is a reference to an ARRAY. It doesn't, however, checks the mapping currently. Beware if you have any error in mapping, you might get an awkard response. Please note key of each node has to be a string. For example refer to unit test case [test-case-14.t].

set_default_node()

This method set the default node definition.

get_node()

Returns all the node's map defintions.

get_element()

Returns all the elements i.e. node defintions.

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_name()

This method takes a node code and returns its name. If the node belongs to user defined mapping then it simply returns the node code itself.

_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.

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.