blib/lib/Ham/DXCC.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 # -*- mode: cperl; tab-width: 8; indent-tabs-mode: nil; basic-offset: 2 -*-
2 # vim:ts=8:sw=2:et:sta:sts=2
3 #########
4 # Author: rmp
5 # Last Modified: $Date: 2013-11-25 22:31:26 +0000 (Mon, 25 Nov 2013) $
6 # Id: $Id: DXCC.pm 271 2013-11-25 22:31:26Z rmp $
7 # $HeadURL: svn+ssh://psyphi.net/repository/svn/iotamarathon/trunk/lib/Ham/DXCC.pm $
8 #
9 # built from clublog cty.xml
10 #
11 package Ham::DXCC;
12 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 0 ▶use XML::XPath;
Subroutine BEGIN: called CC=1 SCAR=2.6
15 use LWP::Simple;
16 use Carp;
17  
18 our $APIKEY = q[];
19 our $SOURCE = q[https://secure.clublog.org/cty.php?api=%s];
20 our $VERSION = q[1.2];
21  
22 sub new {
23 my ($class) = @_;
24 my $self = {};
25  
26 bless $self, $class;
27 return $self;
28 }
29  
30 sub fetch {
31 my ($self, $filename) = @_;
32 my $apikey = $self->{apikey} || $APIKEY || $ENV{DXCC_APIKEY};
33  
34 if(!$apikey) {
35 croak q[You need to specify an api key in obj->{apikey}, Ham::DXCC::APIKEY or ENV{APIKEY}];
36 }
37  
38 my $source = sprintf $SOURCE, $apikey;
39  
40 getstore($SOURCE, "$filename.gz");
41 system qw(gzip -fd), "$filename.gz";
42 return 1;
43 }
44  
45 sub parse {
46 my ($self, $filename, $schema) = @_;
47  
48 if($self->{parse}) {
49 return $self->{parse};
50 }
51  
52 my $doc = XML::XPath->new(filename => $filename);
53 my $results = {};
54  
55 my $SECTIONS = {
56 '/clublog/exceptions/exception' => [qw(call entity adif cqz ituz cont long lat start end)],
57 '/clublog/prefixes/prefix' => [qw(call entity adif cqz ituz cont long lat start end)],
58 '/clublog/invalid_operations/invalid' => [qw(call start end)],
59 '/clublog/zone_exceptions/zone_exception' => [qw(call start end zone)],
60 };
61  
62 for my $section (keys %{$SECTIONS}) {
63 my $things_in = [$doc->find($section)->get_nodelist];
64 my $things_out = [];
65  
66 for my $in (@{$things_in}) {
67 my $out = {};
68  
69 #########
70 # standard fields
71 #
72 my $rec = $in->getAttribute('record');
73 $out->{record} = $rec;
74 for my $field (@{$SECTIONS->{$section}}) {
75 my $val = $doc->find("./$field", $in)->string_value;
76 if(!$val) {
77 next;
78 }
79 $out->{lc $field} = $val;
80 }
81  
82 push @{$things_out}, $out;
83 }
84  
85 my ($root) = $section =~ m{^/clublog/(\S+)/}smx;
86 $results->{$root} = $things_out;
87 }
88  
89 $self->{parse} = $results;
90 return $results;
91 }
92  
93 1;
94  
95 __END__
↑ Summary