Making tests easier, finding things in London, and SnogWiki

Kake on 2003-03-17T16:53:46

I got around to writing CGI::Wiki::Plugin::Locator::UK. It's not as complicated as I was going on about in my last journal entry, because it doesn't actually need write access to the database tables.

use CGI::Wiki;
use CGI::Wiki::Plugin::Locator::UK;

my $wiki = CGI::Wiki->new;
my $locator = CGI::Wiki::Plugin::Locator::UK->new(
    wiki => $wiki );

$wiki->write_node( "Jerusalem Tavern",
                   "A good pub",
                   $checksum,
                   { os_x => 531674,
                     os_y => 181950
                   }
                  );

# Just retrieve the co-ordinates.
my ( $x, $y ) = $locator->coordinates(
    node => "Jerusalem Tavern" );

# Find the straight-line distance between two nodes,
# in kilometres.
my $distance = $locator->distance(
    from_node => "Jerusalem Tavern",
    to_node   => "Calthorpe Arms" );

# Find all the things within 200 metres of a given place.
my @others = $locator->find_within_distance(
    node   => "Albion",
    metres => 200 );
The only change I needed to make to CGI::Wiki was to put in an extra utility module to make it easier to write standalone tests that can be run at any time after the core distribution is installed. So you can write a CGI::Wiki plugin, use CGI::Wiki::TestConfig::Utilities, and your tests can be run on every backend that was configured for testing last time CGI::Wiki was installed.

But, anyway, the Locator plugin. Feel the shininess! Want to see everything that grubstreet knows about within 500 metres of Holborn Station? No problem.

Simon noted that the idea of linking wiki nodes using co-ordinates can be extended to all kinds of evilness, hence the title of this entry. $locator->find_chain_between will be written, but my primary motivation is really the more innocent one of pub crawling.