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 2.05

AWARD

Map::Tube has been granted the "Famous Software Award" by Download.FamousWhy.com on Tue 09 Nov 2010.

http://download.famouswhy.com/map_tube/

SYNOPSIS

      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. It covers Bakerloo, Central, Circle, District, DLR, Hammersmith & City, Jubilee, Metropolitan, Northern, Overground, Piccadilly, Victoria and Waterloo & City. Here is the link to the official London Tube Map: http://www.tfl.gov.uk/assets/downloads/standard-tube-map.pdf

CONSTRUCTOR

The constructor expects no parameters. This setup the default node definitions. By default the DEBUG is turned off.

  use strict; use warnings;
  use Map::Tube;

  # Setup the default node with DEBUG turned OFF.
  my $map = Map::Tube->new();

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.

  use strict; use warnings;
  use Map::Tube;

  # Setup the default node defintion with DEBUG turned OFF.
  my $map = Map::Tube->new();

  # Find the shortest route from 'Bond Street' to 'Euston'.
  my @route = $map->get_shortest_route('Bond Street', 'Euston');

get_tube_lines()

This method accept node code and returns the line name of the given node code. This applies mainly to the default node definitions. However if user has provided line information then it will use them.

  use strict; use warnings;
  use Map::Tube;

  # This setup the default node ready to be use.
  my $map = Map::Tube->new();

  # Get tube lines for the node 'Wembley Park'.
  my @lines = $map->get_tube_lines('Wembley Park');

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 see garbage out.

  use strict; use warnings;
  use Map::Tube;

  # This setup the default node ready to be use.
  my $map = Map::Tube->new();

  # Define node
  my $node = { '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'],};

  # However user can override the node definition.
  $map->set_node($node);

  # Find the shortest route from 'C' to 'H'
  my @route = $map->get_shortest_route('C', 'H');

set_default_node()

This method set the default node definition.

  use strict; use warnings;
  use Map::Tube;

  # This setup the default node ready to be use.
  my $map = Map::Tube->new();

  # Define node
  my $node = { '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'],};

  # However user can override the node definition.
  $map->set_node($node);

  # Find the shortest route from 'C' to 'H'
  my @route = $map->get_shortest_route('C', 'H');

  # Revert back to the default node definition.
  $map->set_default_node();

  # Find the shortest route from 'Bond Street' to 'Euston'.
  @route = $map->get_shortest_route('Bond Street', 'Euston');

get_node()

Returns all the node's map defintions.

  use strict; use warnings;
  use Map::Tube;

  # Setup the default node defintion with DEBUG turned OFF.
  my $map = Map::Tube->new();

  # Get the node's map definition.
  my $node = $map->get_node();

get_line()

Returns all the tube line's defintions. For user defined node, it would return line definition provided by the user, if any, otherwise UNDEF.

  use strict; use warnings;
  use Map::Tube;

  # Setup the default node defintion with DEBUG turned OFF.
  my $map = Map::Tube->new();

  # Get the tube line's definition.
  my $line = $map->get_line();

set_line()

Set the user defined line defintions.

  use strict; use warnings;
  use Map::Tube;

  # Setup the default node defintion with DEBUG turned OFF.
  my $map  = Map::Tube->new();

  my $node = { 'A' => ['B'],
               'B' => ['A','C'],
               'C' => ['B','D','F'],
               'D' => ['C','E'],
               'E' => ['D','F'],
               'F' => ['C','E'] };

  # Set the user node.
  $map->set_node($node);

  # Define line.
  my $line = { 'Line1' => ['A','B','C','D','E','F'],
               'Line2' => ['C','F','E'] };

  # Set the user defined line definitions.
  $map->set_line($line);

get_element()

Returns all the elements i.e. node defintions.

  use strict; use warnings;
  use Map::Tube;

  # Setup the default node defintion with DEBUG turned OFF.
  my $map = Map::Tube->new();

  # Get all the elements i.e. node definition.
  my $element = $map->get_element();

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.

  use strict; use warnings;
  use Map::Tube;

  # Setup the default node defintion with DEBUG turned OFF.
  my $map = Map::Tube->new();

  # Get node name for the given node code.
  my $name = $map->get_name('BST');

set_debug()

This method enables to turn the debug on or off.

  use strict; use warnings;
  use Map::Tube;

  # Setup the default node defintion with DEBUG turned OFF.
  my $map = Map::Tube->new();

  # Debug is turned on.
  $map->set_debug(1);

show_map_chart()

This method dumps the map chart used internally to find the shortest route to the STDOUT. This should only be called after get_shortest_route() to get some reasonable data. The map chart is generated by the internal method _process_node() which gets called by the method get_shortest_route(). This method takes no parameter. It has three columns by the title "N" - Node Code, "P" - Path to here and "L" - Length to reach "N" from "P".

  use strict; use warnings;
  use Map::Tube;

  # This setup the default node ready to be use.
  my $map = Map::Tube->new();

  # Define node
  my $node = { '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'],};

  # However user can override the node definition.
  $map->set_node($node);

  # Find the shortest route from 'C' to 'H'
  my @route = $map->get_shortest_route('C', 'H');

  # The map chart will have meaningfull data only after you
  # have called method get_shortest_route().
  $map->show_map_chart();

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.