projects
/
spider.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'mojo' into users.v3j
[spider.git]
/
perl
/
QSL.pm
diff --git
a/perl/QSL.pm
b/perl/QSL.pm
index 9ed00f30d1c37ec2049d89d63d662db1fac7dffa..e303e123aaa1bedf87393cab649eb4b9a858b6fe 100644
(file)
--- a/
perl/QSL.pm
+++ b/
perl/QSL.pm
@@
-8,35
+8,35
@@
package QSL;
use strict;
package QSL;
use strict;
-use
DXVars
;
+use
SysVar
;
use DXUtil;
use DB_File;
use DXDebug;
use Prefix;
use DXUtil;
use DB_File;
use DXDebug;
use Prefix;
+use JSON;
+use Data::Structure::Util qw(unbless);
-use vars qw($qslfn $dbm);
-$qslfn = 'qsl';
+use vars qw($qslfn $dbm
$maxentries
);
+$qslfn = '
dx
qsl';
$dbm = undef;
$dbm = undef;
+$maxentries = 50;
+
+my $json;
+
+localdata_mv("$qslfn.v1j");
sub init
{
my $mode = shift;
sub init
{
my $mode = shift;
- my $ufn =
"$main::root/data/$qslfn.v1"
;
+ my $ufn =
localdata("$qslfn.v1j")
;
-
Prefix::load() unless Prefix::loaded(
);
+
$json = JSON->new->canonical(1
);
- eval {
- require Storable;
- };
+ Prefix::load() unless Prefix::loaded();
- if ($@) {
- dbg("Storable appears to be missing");
- dbg("In order to use the QSL feature you must");
- dbg("load Storable from CPAN");
- return undef;
- }
- import Storable qw(nfreeze freeze thaw);
+
my %u;
my %u;
+ undef $dbm;
if ($mode) {
$dbm = tie (%u, 'DB_File', $ufn, O_CREAT|O_RDWR, 0666, $DB_BTREE) or confess "can't open qsl file: $qslfn ($!)";
} else {
if ($mode) {
$dbm = tie (%u, 'DB_File', $ufn, O_CREAT|O_RDWR, 0666, $DB_BTREE) or confess "can't open qsl file: $qslfn ($!)";
} else {
@@
-56,7
+56,9
@@
sub new
return bless [uc $call, []], $pkg;
}
return bless [uc $call, []], $pkg;
}
-# the format of each entry is [manager, times found, last time]
+# called $self->update(comment, time, spotter)
+# $self has the callsign as the first argument in an array of array references
+# the format of each entry is [manager, times found, last time, last reporter]
sub update
{
return unless $dbm;
sub update
{
return unless $dbm;
@@
-65,19
+67,24
@@
sub update
my $t = shift;
my $by = shift;
my $changed;
my $t = shift;
my $by = shift;
my $changed;
-
+
+ return unless length $line && $line =~ /\b(?:QSL|VIA)\b/i;
foreach my $man (split /\b/, uc $line) {
my $tok;
foreach my $man (split /\b/, uc $line) {
my $tok;
- if (is_callsign($man)) {
+ if (is_callsign($man)
&& !is_qra($man)
) {
my @pre = Prefix::extract($man);
$tok = $man if @pre && $pre[0] ne 'Q';
} elsif ($man =~ /^BUR/) {
$tok = 'BUREAU';
my @pre = Prefix::extract($man);
$tok = $man if @pre && $pre[0] ne 'Q';
} elsif ($man =~ /^BUR/) {
$tok = 'BUREAU';
+ } elsif ($man =~ /^LOTW/) {
+ $tok = 'LOTW';
} elsif ($man eq 'HC' || $man =~ /^HOM/ || $man =~ /^DIR/) {
$tok = 'HOME CALL';
} elsif ($man =~ /^QRZ/) {
$tok = 'QRZ.com';
} elsif ($man eq 'HC' || $man =~ /^HOM/ || $man =~ /^DIR/) {
$tok = 'HOME CALL';
} elsif ($man =~ /^QRZ/) {
$tok = 'QRZ.com';
+ } else {
+ next;
}
if ($tok) {
my ($r) = grep {$_->[0] eq $tok} @{$self->[1]};
}
if ($tok) {
my ($r) = grep {$_->[0] eq $tok} @{$self->[1]};
@@
-93,6
+100,8
@@
sub update
unshift @{$self->[1]}, $r;
$changed++;
}
unshift @{$self->[1]}, $r;
$changed++;
}
+ # prune the number of entries
+ pop @{$self->[1]} while (@{$self->[1]} > $maxentries);
}
}
$self->put if $changed;
}
}
$self->put if $changed;
@@
-106,7
+115,7
@@
sub get
my $r = $dbm->get($key, $value);
return undef if $r;
my $r = $dbm->get($key, $value);
return undef if $r;
- return
thaw
($value);
+ return
decode
($value);
}
sub put
}
sub put
@@
-114,8
+123,40
@@
sub put
return unless $dbm;
my $self = shift;
my $key = $self->[0];
return unless $dbm;
my $self = shift;
my $key = $self->[0];
- my $value =
nfreez
e($self);
+ my $value =
encod
e($self);
$dbm->put($key, $value);
}
$dbm->put($key, $value);
}
+sub remove_files
+{
+ unlink "$main::data/qsl.v1j";
+ unlink "$main::local_data/qsl.v1j";
+}
+
+# thaw the user
+sub decode
+{
+ my $s = shift;
+ my $ref;
+ eval { $ref = $json->decode($s) };
+ if ($ref && !$@) {
+ return bless $ref, 'QSL';
+ }
+ return undef;
+}
+
+# freeze the user
+sub encode
+{
+ my $ref = shift;
+ unbless($ref);
+ my $s;
+
+ eval {$s = $json->encode($ref) };
+ if ($s && !$@) {
+ bless $ref, 'QSL';
+ return $s;
+ }
+}
+
1;
1;