3 # Local 'autoqsl' module for DXSpider
5 # Copyright (c) 2003 Dirk Koopman G1TLH
17 use Data::Structure::Util qw(unbless);
19 use vars qw($qslfn $dbm $maxentries);
26 localdata_mv("$qslfn.v1j");
31 my $ufn = localdata("$qslfn.v1j");
33 $json = JSON->new->canonical(1);
35 Prefix::load() unless Prefix::loaded();
41 $dbm = tie (%u, 'DB_File', $ufn, O_CREAT|O_RDWR, 0666, $DB_BTREE) or confess "can't open qsl file: $qslfn ($!)";
43 $dbm = tie (%u, 'DB_File', $ufn, O_RDONLY, 0666, $DB_BTREE) or confess "can't open qsl file: $qslfn ($!)";
55 my ($pkg, $call) = @_;
56 return bless [uc $call, []], $pkg;
59 # called $self->update(comment, time, spotter)
60 # $self has the callsign as the first argument in an array of array references
61 # the format of each entry is [manager, times found, last time, last reporter]
71 return unless length $line && $line =~ /\b(?:QSL|VIA)\b/i;
72 foreach my $man (split /\b/, uc $line) {
75 if (is_callsign($man) && !is_qra($man)) {
76 my @pre = Prefix::extract($man);
77 $tok = $man if @pre && $pre[0] ne 'Q';
78 } elsif ($man =~ /^BUR/) {
80 } elsif ($man =~ /^LOTW/) {
82 } elsif ($man eq 'HC' || $man =~ /^HOM/ || $man =~ /^DIR/) {
84 } elsif ($man =~ /^QRZ/) {
90 my ($r) = grep {$_->[0] eq $tok} @{$self->[1]};
99 $r = [$tok, 1, $t, $by];
100 unshift @{$self->[1]}, $r;
103 # prune the number of entries
104 pop @{$self->[1]} while (@{$self->[1]} > $maxentries);
107 $self->put if $changed;
112 return undef unless $dbm;
116 my $r = $dbm->get($key, $value);
118 return decode($value);
125 my $key = $self->[0];
126 my $value = encode($self);
127 $dbm->put($key, $value);
132 unlink "$main::data/qsl.v1j";
133 unlink "$main::local_data/qsl.v1j";
141 eval { $ref = $json->decode($s) };
143 return bless $ref, 'QSL';
155 eval {$s = $json->encode($ref) };