use DXUtil;
use LRU;
use File::Copy;
+use Data::Structure::Util qw(unbless);
+use Time::HiRes qw(gettimeofday tv_interval);
+use IO::File;
++use JSON;
use strict;
}
}
# only store users that are reasonably active or have useful information
- print $fh "$key\t" . $ref->asc_encode($basic_info_only) . "\n";
+ print $fh "$key\t" . encode($ref) . "\n";
++$count;
} else {
- LogDbg('DXCommand', "Export Error3: $key\t" . carp($val) ."\n$@");
+ LogDbg('DXCommand', "Export Error3: '$key'\t" . carp($val) ."\n$@");
eval {$dbm->del($key)};
- dbg(carp("Export Error3: $key\t$val\n$@")) if $@;
+ dbg(carp("Export Error3: delete '$key' => '$val' $@")) if $@;
++$err;
}
}
package QSL;
use strict;
--use DXVars;
++use SysVar;
use DXUtil;
use DB_File;
use DXDebug;
use Prefix;
++use JSON;
++use Data::Structure::Util qw(unbless);
use vars qw($qslfn $dbm $maxentries);
--$qslfn = 'qsl';
++$qslfn = 'dxqsl';
$dbm = undef;
$maxentries = 50;
--localdata_mv("$qslfn.v1");
++my $json;
++
++localdata_mv("$qslfn.v1j");
sub init
{
my $mode = shift;
-- my $ufn = localdata("$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;
undef $dbm;
if ($mode) {
my $r = $dbm->get($key, $value);
return undef if $r;
-- return thaw($value);
++ return decode($value);
}
sub put
return unless $dbm;
my $self = shift;
my $key = $self->[0];
-- my $value = nfreeze($self);
++ my $value = encode($self);
$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;
$end = 0;
$SIG{TERM} = $SIG{INT} = sub { $end++ };
--my $qslfn = "qsl";
++my $qslfn = "dxqsl";
$main::systime = time;
--unlink "$data/qsl.v1";
--unlink "$local_data/qsl.v1";
--
++QSL::remove_files();
QSL::init(1) or die "cannot open QSL file";
my $base = localdata("spots");