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);
27 localdata_mv("$qslfn.v1j");
32 my $ufn = localdata("$qslfn.v1j");
34 $json = JSON->new->canonical(1);
36 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 ($!)";
57 my ($pkg, $call) = @_;
58 return bless [uc $call, []], $pkg;
61 # called $self->update(comment, time, spotter)
62 # $self has the callsign as the first argument in an array of array references
63 # the format of each entry is [manager, times found, last time, last reporter]
73 return unless length $line && $line =~ /\b(?:QSL|VIA)\b/i;
74 foreach my $man (split /\b/, uc $line) {
77 if (is_callsign($man) && !is_qra($man)) {
78 my @pre = Prefix::extract($man);
79 $tok = $man if @pre && $pre[0] ne 'Q';
80 } elsif ($man =~ /^BUR/) {
82 } elsif ($man =~ /^LOTW/) {
84 } elsif ($man eq 'HC' || $man =~ /^HOM/ || $man =~ /^DIR/) {
86 } elsif ($man =~ /^QRZ/) {
92 my ($r) = grep {$_->[0] eq $tok} @{$self->[1]};
101 $r = [$tok, 1, $t, $by];
102 unshift @{$self->[1]}, $r;
105 # prune the number of entries
106 pop @{$self->[1]} while (@{$self->[1]} > $maxentries);
109 $self->put if $changed;
114 return undef unless $dbm;
118 my $r = $dbm->get($key, $value);
120 return decode($value);
127 my $key = $self->[0];
128 my $value = encode($self);
129 $dbm->put($key, $value);
134 unlink "$main::data/$qslfn.v1j";
135 unlink "$main::local_data/$qslfn.v1j";
143 eval { $ref = $json->decode($s) };
145 return bless $ref, 'QSL';
157 eval {$s = $json->encode($ref) };