use strict;
use warnings;
+BEGIN
+{
+ @AnyDBM_File::ISA = (qw(GDBM_File DB_File GDBM_File SDBM_File NDBM_File ODBM_File));
+}
+
use Carp qw(carp confess);
+use Fcntl (qw(O_RDWR O_CREAT));
use AnyDBM_File;
use Onis::Config (qw(get_config));
=over 4
-=item B<gdbm_directory>: I<E<lt>dirE<gt>>
+=item B<dbm_directory>: I<E<lt>dirE<gt>>
-Directory in which the GDBM-files are kept.
+Directory in which the DBM-files are kept.
=back
=cut
-our $DBMDirectory = get_config ('gdbm_directory') || 'var';
+our $DBMDirectory = get_config ('dbm_directory') || 'var';
$DBMDirectory =~ s#/$##g;
if (!$DBMDirectory or !-d $DBMDirectory)
my $id = $caller . ':' . $name;
$id =~ s#/##g;
- $filename = "$GDBMDirectory/$id.gdbm";
+ $filename = "$DBMDirectory/$id.dbm";
if (exists ($Objects{$id}))
{
return (undef);
}
- $Objects{$id} = $obj;
+ no strict (qw(subs));
+ tie (%hash, 'AnyDBM_File', $filename, O_RDWR | O_CREAT, 0666) or die ("tie: $!");
- $obj->{'data'} = tie (%hash, 'AnyDBM_File', $filename, O_CREAT|O_RDWR, 0664);
+ $obj->{'data'} = tied %hash;
$obj->{'key'} = $key;
$obj->{'fields'} = [@fields];
$obj->{'num_fields'} = scalar (@fields);
print STDOUT $/, $dbg;
}
- return (bless ($obj, $pkg));
+ $Objects{$id} = bless ($obj, $pkg);
+ return ($Objects{$id});
}
sub put
if (!exists ($obj->{'cache'}{$key}))
{
- if ($db->get ($key, $val))
+ $val = $db->FETCH ($key);
+ if (!defined ($val))
{
$obj->{'cache'}{$key} = undef;
}
my $key;
my $val;
+ no strict (qw(subs));
for ($db->seq ($key, $val, R_FIRST); $db->seq ($key, $val, R_NEXT) == 0;)
{
next if (defined ($obj->{'cache'}{$key}));
}
return (sort
- sub {
+ {
for (@field_indizes)
{
my $d = $obj->{'cache'}{$a}[$_] cmp $obj->{'cache'}{$b}[$_];
return ($d) if ($d);
}
- }, @keys);
+ } (keys %{$obj->{'cache'}}));
}
sub del
my $obj = shift;
my $db = $obj->{'data'};
- for (keys %{$obj->{'cache'}})
+ for (CORE::keys %{$obj->{'cache'}})
{
my $key = $_;
+ next unless (defined ($obj->{'cache'}{$key}));
+
my $val = join ($Alarm, @{$obj->{'cache'}{$key}});
$db->put ($key, $val);
END
{
- for (keys (%Objects))
+ for (CORE::keys (%Objects))
{
- my $obj = $_;
+ my $key = $_;
+ my $obj = $Objects{$key};
$obj->sync ();
}
}