Ham-Locator-0.1000/0000755017777601777760000000000011514610327013521 5ustar nobodynogroupHam-Locator-0.1000/Changes0000644017777601777760000000061411514610225015012 0ustar nobodynogroupRevision history for Perl extension Ham::Locator. 0.1000 Sun Jan 16 15:35:00 2011 - Version 0.1000 for beta releas 0.0003 Sat Jan 15 19:35:00 2011 - Updated documentation 0.0002 Sat Jan 15 19:20:00 2011 - latlng2loc implemented - output precision option added (see 'set_precision') - updated tests 0.0001 Fri Dec 17 21:04:00 2010 - Initial module release. - Added POD documentation Ham-Locator-0.1000/README0000644017777601777760000000122411514610225014375 0ustar nobodynogroupHam-Locator version 0.1000 =========================== Ham::Locator provides methods for converting between Maidenhead locators and latitude/longitude. INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: Carp Class::Accessor COPYRIGHT AND LICENCE Copyright (C) 2010, 2011 by Andy Smith This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available. Ham-Locator-0.1000/lib/0000755017777601777760000000000011514610327014267 5ustar nobodynogroupHam-Locator-0.1000/lib/Ham/0000755017777601777760000000000011514610327014774 5ustar nobodynogroupHam-Locator-0.1000/lib/Ham/Locator.pm0000644017777601777760000001314411514610225016735 0ustar nobodynogroup#!/usr/bin/perl #======================================================================= # Locator.pm / Ham::Locator # $Id: Locator.pm 10 2011-01-16 15:36:53Z andys $ # $HeadURL: http://daedalus.dmz.dn7.org.uk/svn/Ham-Locator/lib/Ham/Locator.pm $ # (c)2010 Andy Smith #----------------------------------------------------------------------- #:Description # Module to easily convert between Maidenhead locators and coordinates # in latitude and longitude format. #----------------------------------------------------------------------- #:Synopsis # # use Ham::Locator; # my $m = new Ham::Locator; # $m->set_loc('IO93lo'); # my ($latitude, $longitude) = $m->loc2latlng; #======================================================================= # # With thanks to:- # * http://home.arcor.de/waldemar.kebsch/The_Makrothen_Contest/fmaidenhead.js # * http://no.nonsense.ee/qthmap/index.js # The pod (Perl documentation) for this module is provided inline. For a # better-formatted version, please run:- # $ perldoc Locator.pm =head1 NAME Ham::Locator - Convert between Maidenhead locators and latitude/longitude. =head1 SYNOPSIS use Ham::Locator; my $m = new Ham::Locator; $m->set_loc('IO93lo'); my ($latitude, $longitude) = $m->loc2latlng; =head1 DEPENDENCIES =over4 =item * Carp - for error handling =item * Class::Accessor - for accessor method generation =back =cut # Module setup package Ham::Locator; use strict; use warnings; our $VERSION = '0.1000'; # Module inclusion use Carp; use Data::Dumper; use POSIX qw(floor fmod); # Set up accessor methods with Class::Accessor use base qw(Class::Accessor); __PACKAGE__->follow_best_practice; __PACKAGE__->mk_accessors( qw(loc latlng precision) ); =head1 CONSTRUCTORS =head2 Locator->new Creates a new C object. =head1 ACCESSORS =head2 $locator->set_loc(I) Sets the locator to use for conversion to latitude and longitude. =head2 $locator->set_latlng((I, I)) Sets the longitude and latitude to use for conversion to the locator. =head2 $locator->set_precision(I) Sets the number of characters of the locator reference to return when calling B. =cut sub l2n { my ($self, $letter) = @_; my $lw = lc $letter; my $index = { 'a' => 0, 'b' => 1, 'c' => 2, 'd' => 3, 'e' => 4, 'f' => 5, 'g' => 6, 'h' => 7, 'i' => 8, 'j' => 9, 'k' => 10, 'l' => 11, 'm' => 12, 'n' => 13, 'o' => 14, 'p' => 15, 'q' => 16, 'r' => 17, 's' => 18, 't' => 19, 'u' => 20, 'v' => 21, 'w' => 22, 'x' => 23 }; return $index->{$lw}; }; sub n2l { my ($self, $number) = @_; my $index = { 0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd', 4 => 'e', 5 => 'f', 6 => 'g', 7 => 'h', 8 => 'i', 9 => 'j', 10 => 'k', 11 => 'l', 12 => 'm', 13 => 'n', 14 => 'o', 15 => 'p', 16 => 'q', 17 => 'r', 18 => 's', 19 => 't', 20 => 'u', 21 => 'v', 22 => 'w', 23 => 'x' }; return $index->{$number}; }; =head1 METHODS =head2 $locator->latlng2loc converts the latitude and longitude set by B to the locator, and returns it as a string. =cut sub latlng2loc { my ($self) = @_; if($self->get_latlng eq "") { return 0; } my $latlng = $self->get_latlng; my $field_lat = @{$latlng}[0]; my $field_lng = @{$latlng}[1]; my $locator; my $lat = $field_lat + 90; my $lng = $field_lng + 180; # Field $lat = ($lat / 10) + 0.0000001; $lng = ($lng / 20) + 0.0000001; $locator .= uc($self->n2l(floor($lng))).uc($self->n2l(floor($lat))); # Square $lat = 10 * ($lat - floor($lat)); $lng = 10 * ($lng - floor($lng)); $locator .= floor($lng).floor($lat); # Subsquare $lat = 24 * ($lat - floor($lat)); $lng = 24 * ($lng - floor($lng)); $locator .= $self->n2l(floor($lng)).$self->n2l(floor($lat)); # Extended square $lat = 10 * ($lat - floor($lat)); $lng = 10 * ($lng - floor($lng)); $locator .= floor($lng).floor($lat); # Extended Subsquare $lat = 24 * ($lat - floor($lat)); $lng = 24 * ($lng - floor($lng)); $locator .= $self->n2l(floor($lng)).$self->n2l(floor($lat)); if($self->get_precision) { return substr $locator, 0, $self->get_precision; } else { return $locator; } } =head2 $locator->loc2latlng Converts the locator set by B to latitude and longitude, and returns them as an array of two values. =cut sub loc2latlng { my ($self) = @_; if($self->get_loc eq "") { return 0; } my $loc = $self->get_loc; if(length $loc lt 4) { $loc .= "55LL55LL"; } elsif(length $loc lt 6) { $loc .= "LL55LL"; } elsif(length $loc lt 8) { $loc .= "55LL"; } elsif(length $loc lt 10) { $loc .= "LL"; } if($loc !~ m/[a-rA-R]{2}[0-9]{2}[a-xA-X]{2}[0-9]{2}[a-xA-X]{2}/) { print "Not a valid locator.\n"; return 0; } $loc = lc($loc); my $i = 0; my @l = (); while ($i < 10) { my $a = substr $loc, $i, 1; if($a =~ m/[a-zA-Z]/) { $l[$i] = $self->l2n($a); } else { $l[$i] = int(substr $loc, $i, 1); } $i++; } my $lng = (($l[0] * 20) + ($l[2] * 2) + ($l[4]/12) + ($l[6]/120) + ($l[8]/2880) - 180); my $lat = (($l[1] * 10) + $l[3] + ($l[5]/24) + ($l[7]/240) + ($l[9]/5760) - 90); return ($lat, $lng); }; =head1 CAVEATS =head1 BUGS =item1 * None, hopefully! This module was written by B . =head1 COPYRIGHT $Id: Locator.pm 10 2011-01-16 15:36:53Z andys $ (c)2009 Andy Smith (L) This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; Ham-Locator-0.1000/MANIFEST0000644017777601777760000000013711502751026014652 0ustar nobodynogroupChanges lib/Ham/Locator.pm Makefile.PL MANIFEST This list of files README t/00-Ham-Locator.t Ham-Locator-0.1000/t/0000755017777601777760000000000011514610327013764 5ustar nobodynogroupHam-Locator-0.1000/t/00-Ham-Locator.t0000644017777601777760000000336111514372053016500 0ustar nobodynogroup# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl IPTables-Log.t' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use Test::More tests => 11; BEGIN { use_ok('Ham::Locator') }; ######################### # Insert your test code below, the Test::More module is use()ed here so read # its man page ( perldoc Test::More ) for help writing this test script. # Create new IPTables::Log object my $l = new_ok( Ham::Locator ); # Check it's of the correct type ok(ref($l) eq "Ham::Locator", "Object is of type Ham::Locator"); diag("Testing methods"); can_ok($l, qw(latlng2loc loc2latlng n2l l2n)); diag("Testing loc2latlng..."); $l->set_loc("IO93lo72hn"); my @latlng = $l->loc2latlng(); like($latlng[0], qr/^53.593923/, "Correct latitude returned"); like($latlng[1], qr/^-1.022569/, "Correct longitude returned"); diag("Testing latlng2loc..."); $l->set_latlng((53.593923, -1.022569)); my $loc = $l->latlng2loc(); like($loc, qr/IO93lo72hn/, "Correct locator returned"); diag("Testing precision (to 8 places)..."); $l->set_precision(8); $loc = $l->latlng2loc(); like($loc, qr/IO93lo72/, "Correct locator returned (to 6 places)"); diag("Testing precision (to 6 places)..."); $l->set_precision(6); $loc = $l->latlng2loc(); like($loc, qr/IO93lo/, "Correct locator returned (to 6 places)"); diag("Testing precision (to 4 places)..."); $l->set_precision(4); $loc = $l->latlng2loc(); like($loc, qr/IO93/, "Correct locator returned (to 4 places)"); diag("Testing precision (to 2 places)..."); $l->set_precision(2); $loc = $l->latlng2loc(); like($loc, qr/IO/, "Correct locator returned (to 4 places)"); Ham-Locator-0.1000/Makefile.PL0000644017777601777760000000113611502750764015503 0ustar nobodynogroup# Makefile.PL # $Id: Makefile.PL 17 2009-12-15 01:36:48Z andys $ use 5.010000; use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( NAME => 'Ham::Locator', VERSION_FROM => 'lib/Ham/Locator.pm', # finds $VERSION PREREQ_PM => {'Class::Accessor' => 0.34}, ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'lib/Ham/Locator.pm', # retrieve abstract from module AUTHOR => 'Andy Smith ') : ()), );