NAME
PXP::Config
SYNOPSIS
# do this only once at server initialization:
PXP::Config::init(file=>$finename);
# then from anywhere:
my $global_configuration_hash = PXP::Config::getGlobal();
# only from a plugin class:
my $plugin_configuration_hash = PXP::Config::get();
DESCRIPTION
PXP::Config is a PXP component which provides a unified and simplified API for the PXP server and PXP plugins to read and store there configuration.
PXP::Config uses the XML::Simple module to access a centralized XML configuration file. This file (/opt/etc/imc.xml by default) contains root element named imc which has a global child for the PXP server configuration and a plugins child which has itself a child per plugin configuration (the child name must be the plugin name for this class to automatically retrieve a plugin configuration.
As plugins configurations are retrived by plugin name in a centralized location, the only thing a plugin has to do in order to get its configuration is to call the PXP::Config::get() method which returns a hash convertion of the plugin XML configuration.
Configuring plugins can be made in two manners:
1) the simple way - use it when you don't need to update the configuration from the application itself and when your plugin configuration has a very simple structure:
simply add a tag with the name of your plugin in the etc/imc.xml file, the plugin configuration can then be accessed as a has by calling the PXP::Config::get() method
2) the sophisticated way - use it in other cases:
create a new package in a file MyConfig/PLUGIN_NAME.pm under your plugin directory
in this file, define a package that inherits from PXP::MyConfig class and which overrode the config, loadFile and synchro methods (see plugins/LogViewer/MyConfig/LogViewer.pm for an example)
edit your plugin.xml and add your new package as an extension to the PXP::MyConfig extension point:
<extension
id="MyConfig::LogViewer"
name="Plugin configuration"
version="0.1"
point="IMC::MyConfig"/>
<file value='/tmp/imc.xml'/>
</extension>
You can ommit the file tag, configuration file will then default to the main configuration file (the one passed to the server with the -c switch or etc/imc.xml by default).
See the PXP::Config and PXP::MyConfig APIs for using configuration inside plugins.
METHODS
init(file=>$filename)
Initialize a single PXP::Config instance with the whole XML file $filename converted as a hash.
getGlobal()
Returns a hash convertion of the XML subnode with name "global"
file()
Returns conf filename.
getPluginConfig($plugin_name)
Returns a hash convertion of the XML configuration subnode with path "plugins/$plugin_name"
get($section)
Return a hash converted from the XML subnode with path "plugins/$plugin_name" where $plugin_name is computed from the calling class. Behaviour when called from outside a plugin class is undefined.
You can specify a first level section to get only this section.
getMyConfig($section)
Returns the specific object of class derived from PXP::MyConfig for the calling plugin.
You can specify a first level section to get only this section.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 84:
You can't have =items (as at line 123) unless the first thing after the =over is an =item