Geo::Hashing::Source::Peeron - Retrieve DJIA opening values from irc.peeron.com


Geo-Hashing documentation Contained in the Geo-Hashing distribution.

Index


Code Index:

NAME

Top

Geo::Hashing::Source::Peeron - Retrieve DJIA opening values from irc.peeron.com

SYNOPSIS

Top

  use Geo::Hashing;
  my $g = new Geo::Hashing(source => 'peeron');
  printf "Today's offset is at %.6f, %.6f.\n", $g->lat, $g->lon;

DESCRIPTION

Top

  See documentation of Geo::Hashing.

AUTHOR

Top

Dan Boger, <zigdon@gmail.com>

COPYRIGHT AND LICENSE

Top


Geo-Hashing documentation Contained in the Geo-Hashing distribution.
#!/usr/bin/perl -w
#
# $Id: Peeron.pm 255 2008-06-21 03:48:46Z dan $
#

package Geo::Hashing::Source::Peeron;

use strict;
use warnings;
use Carp;
require Exporter;
use LWP::Simple qw/$ua get/;

$ua->agent("Geo::Hashing/" . $Geo::Hashing::VERSION);
my $URL = "http://irc.peeron.com/xkcd/map/data/%04d/%02d/%02d";

our @ISA = qw/Exporter/;
our @EXPORT = qw/get_djia/;

sub get_djia {
  my $self = shift;
  my $date = shift;

  croak "Invalid call to get_djia - missing date!" unless $date;

  my ($y, $m, $d) = split /-/, $date, 3;
  croak "Invalid year $y" unless $y and $y >= 1928;
  croak "Invalid month $m" unless $m and $m >= 1 and $m <= 12;
  croak "Invalid day $d" unless $d and $d >= 1 and $m <= 31;

  my $page = get(sprintf($URL, $y, $m, $d));

  return $page;
}

1;