OME::Configuration - OME Configuration variables
# This is how the configuration variables are originally written to the DB
use OME::Configuration;
my $conf = new OME::Configuration ($factory,{var1 => 123, var2 => 'foo'});
# Normally, the Configuration object is retreived from the OME::Session object
my $conf = $session->Configuration();
my $var1 = $conf->var1();
The Configuration object is used to get configuration variables
established when OME was installed. In normal use, the variables are
read only, and the Configuration object is retreived from the
OME::Session object.
The constructor can be called from an installation script and passed a
configuration hash along with an OME::Factory
object:
my $conf = new OME::Configuration ($factory,{var1 => 123, var2 => 'foo'});
If there are already configuration variables in the DB, the hash will
be ignored. An
OME::Configuration::Variable object
will be loaded for each variable in the DB. If the DB does not
contain configuration variables, a new
OME::DBObject of type
OME::Configuration::Variable will
be made for each key-value pair in the hash, and written to the DB.
The names of the
OME::Configuration::Variable
objects will be made available as methods of Configuration, returning
the value of the variable when called. From the example above,
$conf->var1() will return 123. The two mutator methods are
described below.
It is likely that some of the configuration variables will be foreign keys into other database tables. These variables are defined in the %FOREIGN_KEY_VARS hash (currently inaccessible outside of the OME::Configuration module). The keys of the hash are the names of the variables as they should be called by code using the Configuration object; the Configuration constructor will create accessor/mutators with these names that expect instances of the foreign key object class. The values of the hash are an anonymous array specifying the name of the Configuration variable containing the foreign key ID, and the name of the foreign key class. An example is appropriate:
my %FOREIGN_KEY_VARS =
(
import_chain => {
DBColumn => 'import_chain_id',
FKClass => 'OME::AnalysisChain',
},
);
This defines a logical configuration variable called import_chain
which points to an instance of the OME::AnalysisChain class. This
variable is stored in the database in the actual configuration
variable import_chain_id.
Each Configuration object will have an accessor/mutator called
import_chain which expects instances of OME::AnalysisChain, and one
called import_chain_id which expects integer database ID's.
Similarly, when creating a new Configuration object with the hash
parameter to new, the parameter hash can contain either an
import_chain entry keyed to an instance of OME::AnalysisChain,
or an import_chain_id entry keyed to the ID of an analysis
chain.
Arrays and hashes are serialized to text using perl syntax, and are made available as references by the accessor method defined in the %SERIALIZED_VARS hash:
my %SERIALIZED_VARS =
(
import_formats => 'ARRAY',
foo_conf => 'HASH',
);
my $conf = OME::Configuration->new();
my $conf = OME::Configuration->new($factory, {
import_chain => $chain,
import_formats => [qw/ome-xml tiff ome-tiff/],
foo_conf => $foo,
});
The constructor can be called parameterless to retreive the configuration stored in the DB. If there is a configuration in the DB, the parameters have no effect. Cnfiguration parameters can be provided when initially recording the installation settings.
my $conf = OME::Configuration->update($factory, {
foo_conf => $foo2,
});
This call will update the configuration as specified by the supplied hash. This should really only be called during a synchronized updaate, where there are no extant processes that may have cached the configuration.
... All of the configuration variables specified in new()
or update() are also available as accessor methods.
Ilya Goldberg <igg@nih.gov>, Open Microscopy Environment