| 1 | package Ham::DXCC::Lookup; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use Exporter 'import'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use FindBin qw($Bin); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use Ham::DXCC::Lookup::DB::ctydat_full; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | our $db = Ham::DXCC::Lookup::DB::ctydat_full->new({ directory => "$Bin/../data" }); | ||||||||||
| 11 | our @prefixes; | ||||||||||
| 12 | |||||||||||
| 13 | our @EXPORT_OK = qw(lookup_dxcc); | ||||||||||
| 14 | our $VERSION = '0.01'; | ||||||||||
| 15 | |||||||||||
| 16 | =head1 NAME | ||||||||||
| 17 | |||||||||||
| 18 | Ham::DXCC::Lookup - Look up DXCC entity from amateur radio callsign | ||||||||||
| 19 | |||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||
| 21 | |||||||||||
| 22 | use Ham::DXCC::Lookup qw(lookup_dxcc); | ||||||||||
| 23 | |||||||||||
| 24 | my $info = lookup_dxcc('G4ABC'); | ||||||||||
| 25 | print "DXCC: $info->{dxcc_name}\n"; | ||||||||||
| 26 | |||||||||||
| 27 | =head1 DESCRIPTION | ||||||||||
| 28 | |||||||||||
| 29 | This module provides a simple lookup mechanism to return the DXCC entity from a given amateur radio callsign. | ||||||||||
| 30 | |||||||||||
| 31 | =head1 FUNCTIONS | ||||||||||
| 32 | |||||||||||
| 33 | =head2 lookup_dxcc($callsign) | ||||||||||
| 34 | |||||||||||
| 35 | Returns a hashref with C<dxcc> for the given callsign. | ||||||||||
| 36 | |||||||||||
| 37 | =cut | ||||||||||
| 38 | |||||||||||
| 39 | sub lookup_dxcc | ||||||||||
| 40 | { | ||||||||||
| 41 | 0 | ▶ | my $callsign = shift; | ||||||||
|
Subroutine
lookup_dxcc: not called CC=5 SCAR=34.0
| |||||||||||
| 42 | |||||||||||
| 43 | 0 | ▶ | if(my $rc = $db->fetchrow_hashref({ prefix => "=$callsign" })) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | return $rc; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 0 | ▶ | if(scalar(@prefixes) == 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 0 | @prefixes = $db->prefix(); | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 0 | for my $prefix (sort { length($b) <=> length($a) } @prefixes) { | |||||||||
| 52 | 0 | ▶ | if(index($callsign, $prefix) == 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 0 | return $db->fetchrow_hashref({ prefix => $prefix }); | |||||||||
| 54 | } | ||||||||||
| 55 | } | ||||||||||
| 56 | 0 | return {}; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 1; | ||||||||||
| 60 | |||||||||||
| 61 | __END__ | ||||||||||
| 62 | |||||||||||
| 63 | =head1 SUPPORT | ||||||||||
| 64 | |||||||||||
| 65 | This module is provided as-is without any warranty. | ||||||||||
| 66 | |||||||||||
| 67 | =head1 AUTHOR | ||||||||||
| 68 | |||||||||||
| 69 | Nigel Horne, C<< <njh at nigelhorne.com> >> | ||||||||||
| 70 | |||||||||||
| 71 | =head1 SEE ALSO | ||||||||||
| 72 | |||||||||||
| 73 | L<https://www.country-files.com/> | ||||||||||
| 74 | |||||||||||
| 75 | =head1 LICENCE AND COPYRIGHT | ||||||||||
| 76 | |||||||||||
| 77 | Copyright 2025 Nigel Horne. | ||||||||||
| 78 | |||||||||||
| 79 | Usage is subject to licence terms. | ||||||||||
| 80 | |||||||||||
| 81 | The licence terms of this software are as follows: | ||||||||||
| 82 | |||||||||||
| 83 | =over 4 | ||||||||||
| 84 | |||||||||||
| 85 | =item * Personal single user, single computer use: GPL2 | ||||||||||
| 86 | |||||||||||
| 87 | =item * All other users (including Commercial, Charity, Educational, Government) | ||||||||||
| 88 | must apply in writing for a licence for use from Nigel Horne at the | ||||||||||
| 89 | above e-mail. | ||||||||||
| 90 | |||||||||||
| 91 | =back | ||||||||||
| 92 | |||||||||||
| 93 | =cut | ||||||||||
| 94 | |||||||||||
| 95 | 1; | ||||||||||