|
|
DBM::Any - object-oriented interface to AnyDBM_File
BEGIN { @AnyDBM_File::ISA = qw(DB_File GDBM_File SDBM_File); } use DBM::Any;
$db = new DBM::Any($filename, $flags, $mode[, optional...]);
$val = $db->get($key);
$db->put($key, $val);
$db->delete($key);
if ($db->exists($key)) { ... }
for my $k ($db->keys()) { ... }
for my $v ($db->values()) { ... }
while (($k, $v) = $db->each()) { ... }
$db->close();
DBM::Any provides an object-oriented complement to AnyDBM_File's tied interface. It was written because it didn't seem to exist on CPAN, and the author likes BerkeleyDB's object-oriented interface, but doesn't want to force people to get BerkeleyDB if they don't want.
The interface is a least common denominator among all available database types; it contains the basic elements for keeping a persistent hash on disk.
The methods should map fairly well to regular operations on hashes. Which is why I won't painstakingly document every method here; you should already know how to deal with hashes.
DBM::Any Objects should be considered opaque. Even if you know what sort of database is underneath, you're a very naughty person if you attempt to circumvent the prescribed intreface. :-)
Currently only supports DB_File access to Sleepycat's Berkeley DB. I'd like to support BerkeleyDB.pm access as well. If there is an elegant solution to this, I need more time to figure it out.
The exists()
method could be called on a database format which does
not support a simple existence check. For these I use a heuristic,
and attempt to retrieve the value associated with the key in
question. If the value is defined, then we say it exists. Because of this, I advise against explicit storage
Tony Monroe <tmonroe+perl@nog.net>