esmith::DB - virtual interface to E-Smith databases
# Note: Do not instantiate this class directly. Use a subclass. # Examples in this documentation where you see it being used directly # are merely for consistency. Substitute a subclass in our examples. use esmith::DB; my $db = esmith::DB->create($filename) or die esmith::DB->error; my $db = esmith::DB->open($filename) or die esmith::DB->error; my $db = esmith::DB->open_ro($filename) or die esmith::DB->error;
my %DB = esmith::DB->as_hash($filename) or die esmith::DB->error;
my $file = $db->file;
my $record = $db->new_record($key, \%properties);
my $record = $db->get($key); my @all_records = $db->get_all; my @all_records_by_prop = $db->get_all_by_prop($prop => $val);
$db->set_prop($key, $prop, $value); $db->set_value($key, $value);
$db->set_prop($key, $prop, $value, type => $type); $db->set_value($key, $value, create => 0);
This module is a general interface to E-Smith's databases of various types and formats. It is not intended to be used directly, but that subclasses will implement the interface presented here to provide a single interface no matter what the underlying format.
For example, there is esmith::DB::db to interface with esmith::db flatfile databases. There could also be esmith::DB::Berkeley to use Berkeley database files, or even esmith::DB::DBI.
Most of the methods herein are "virtual". They don't exist. The subclass is responsible for impelmenting them. There are a handful of concrete methods that have been implemented for you that should work with any subclass.
This is the esmith::DB interface. Subclassers are expected to implement these methods.
These are all implemented in terms of the esmith::DB interface and its not necessary for a subclass to implement them.
Process the fragments in the migration queue for this database, using processTemplate.
The defaults are loaded from /etc/e-smith/db/<dbname>/migrate by default, but the environment variable ESMITH_DB_DEFAULTSDIR can be set to use a different hierarchy if required.
The entries in "migrate" are perl fragments which will be evaluated and so can munge anything they choose to. But, please be gentle :-)
So you could have
which is a perl fragment which does something funky to migrate the access property from some old value to some new value.
After running all the migration scripts, and reloading the DB's data into its local cache, the private method _loadDefaults is called to set any missing default values and any forced settings.
Reset all entries to their default values, if defaults exist. This calls the internal method _loadDefaults with the forceReset flag set. It should not be used lightly!!
Returns true if there are defaults or force directories for the given record name
This is a private method.
Load the default properties for a given database. Caller can provide a flag to force resetting properties that already exist.
Any forced properties will be evaluated after setting the default properties.
The defaults are loaded from the following directories in order (the environment variable ESMITH_DB_DEFAULTSDIR can be set to use a different hierarchy if required):
Each of these directories is arranged as a set of subdirectories, with the directory name equal to the key for the given database. With these subdirectories are files, which are named by the properties of these database keys.
The entries in "defaults" will be skipped if the existing key/property already exists (unless the $forceReset argument is provided). These are simple files, whose contents are the value to be used for that property.
The entries in "force" are always loaded into the given key/property. These are again simple files, like "defaults".
To make this concrete, you might have:
containing the single word "private", which would be the default. This value would only be used if no "access" property existed, or the $forceReset option is passed.
You can override both "defaults" and "migrate" with
containing the single word "public" to force the value of that property.
Retrieve the value of the named key, return it, and delete the record. If the key does not exist, it returns undef. This is normally called from migration code.
Retrieve the named property of the named key, return the value, and delete the property from the record. Returns undef if the property or key does not exist. This is normally called from migration code.
SME Server Developers <email@example.com>
Site consacré à la distribution Linux SME Server
Site sous licence Creative Commons (by, nc, sa)