ZConf::backends::file - A configuration system allowing for either file or LDAP backed storage.
Version 2.1.0
use ZConf; #creates a new instance my $zconf = ZConf->new(); ...
my $zconf=ZConf->(\%args);
This initiates the ZConf object. If it can't be initiated, a value of undef is returned. The hash can contain various initization options.
When it is run for the first time, it creates a filesystem only config file.
This is the copy of the ZConf object intiating it.
This is the variables found in the ~/.config/zconf.zml.
my $zconfbe=ZConf::backends::file->new(\%args); if($zconfbe->error){ warn('error: '.$zconf->error.":".$zconf->errorString); }
This method methods exactly the same as configExists, but for the file backend.
No config name checking is done to verify if it is a legit name or not as that is done in configExists. The same is true for calling errorblank.
$zconfbe->configExistsFile("foo/bar"); if($zconf->error){ warn('error: '.$zconf->{error}.":".$zconf->errorString); }
This methods just like createConfig, but is for the file backend. This is not really meant for external use. The config name passed is not checked to see if it is legit or not.
$zconf->createConfigFile("foo/bar"); if($zconf->error){ warn('error: '.$zconf->error.":".$zconf->errorString); }
This removes a config. Any sub configs will need to removes first. If any are present, this method will error.
#removes 'foo/bar' $zconf->delConfig('foo/bar'); if(defined($zconf->error)){ warn('error: '.$zconf->error."\n".$zconf->errorString); }
This deletes a specified set, for the filesystem backend.
Two arguements are required. The first one is the name of the config and the and the second is the name of the set.
$zconf->delSetFile("foo/bar", "someset"); if($zconf->error){ warn('error: '.$zconf->error.":".$zconf->errorString); }
This is exactly the same as getAvailableSets, but for the file back end. For the most part it is not intended to be called directly.
my @sets = $zconf->getAvailableSets("foo/bar"); if($zconf->error){ warn('error: '.$zconf->error.":".$zconf->errorString); }
This fetches the revision for the speified config using the file backend.
A return of undef means that the config has no sets created for it yet or it has not been read yet by 2.0.0 or newer.
my $revision=$zconf->getConfigRevision('some/config'); if($zconf->error){ warn('error: '.$zconf->error.":".$zconf->errorString); } if(!defined($revision)){ print "This config has had no sets added since being created or is from a old version of ZConf.\n"; }
This gets any sub configs for a config. "" can be used to get a list of configs under the root.
One arguement is accepted and that is the config to look under.
#lets assume 'foo/bar' exists, this would return my @subConfigs=$zconf->getSubConfigs("foo"); if($zconf->error){ warn('error: '.$zconf->error.":".$zconf->errorString); }
This checks if a config is locked or not for the file backend.
One arguement is required and it is the name of the config.
The returned value is a boolean value.
my $locked=$zconf->isConfigLockedFile('some/config'); if($zconf->error){ warn('error: '.$zconf->error.":".$zconf->errorString); } if($locked){ print "The config is locked\n"; }
readFile methods just like read, but is mainly intended for internal use only. This reads the config from the file backend.
The config to load.
This specifies if override should be ran not.
If this is not specified, it defaults to 1, true.
The set for that config to load.
$zconf->readFile({config=>"foo/bar"}) if($zconf->error){ warn('error: '.$zconf->error.":".$zconf->errorString); }
This methods just like readChooser, but methods on the file backend and only really intended for internal use.
my $chooser = $zconf->readChooserFile("foo/bar"); if($zconf->error){ warn('error: '.$zconf->error.":".$zconf->errorString); }
This checks if the specified set exists.
Two arguements are required. The first arguement is the name of the config. The second arguement is the name of the set. If no set is specified, the default set is used. This is done by calling 'defaultSetExists'.
my $return=$zconf->setExists("foo/bar", "fubar"); if($zconf->error){ warn('error: '.$zconf->error.":".$zconf->errorString); }else{ if($return){ print "It exists.\n"; } }
This unlocks or logs a config for the file backend.
Two arguements are taken. The first is a the config name, required, and the second is if it should be locked or unlocked
#lock 'some/config' $zconf->setLockConfigFile('some/config', 1); if($zconf->error){ warn('error: '.$zconf->error.":".$zconf->errorString); } #unlock 'some/config' $zconf->setLockConfigFile('some/config', 0); if($zconf->error){ warn('error: '.$zconf->error.":".$zconf->errorString); } #unlock 'some/config' $zconf->setLockConfigFile('some/config'); if($zconf->error){ warn('error: '.$zconf->error.":".$zconf->errorString); }
This method is a internal method and largely meant to only be called writeChooser, which it methods the same as. It works on the file backend.
$zconf->writeChooserFile("foo/bar", $chooserString) if($zconf->error){ warn('error: '.$zconf->error.":".$zconf->errorString); }
This takes a hash and writes it to a config for the file backend. It takes two arguements, both of which are hashes.
The first hash contains
The second hash is the hash to be written to the config.
The config to write it to.
This is required.
This is the set name to use.
If not defined, the one will be choosen.
This is the revision string to use.
This is primarily meant for internal usage and is suggested that you don't touch this unless you really know what you are doing.
$zconf->writeSetFromHashFile({config=>"foo/bar"}, \%hash); if($zconf->error){ warn('error: '.$zconf->error.":".$zconf->errorString); }
This method writes a loaded config to a to a set, for the file backend.
One arguement is required.
$zconf->writeSetFromLoadedConfigFile({config=>"foo/bar"}); if($zconf->error){ warn('error: '.$zconf->error.":".$zconf->errorString); }
This writes a config set from a ZML object.
$zconf->writeSetFromZML({config=>"foo/bar", zml=>$zml}); if($zconf->error){ warn('error: '.$zconf->error.":".$zconf->errorString); }
This module uses Error::Helper for error handling. Below are the error codes returned by the error method.
config name contains ,
config name contains /.
config name contains //
config name contains ../
config name contains /..
config name contains ^./
config name ends in /
config name starts with /
could not sync to file
config name contains a \n
ZML dump failed.
config does not exist
file/dir does not exist
file/dir open failed
file/dir creation failed
file write failed
No variable name specified.
config key starts with a ' '
ZML object not specified.
set not found for config
LDAPmakepathSimple failed
skilling variable as it is not a legit name
set is not defined
Config is undefined.
Config not loaded.
Set name is not a legit name.
ZML->parse error.
Could not unlink the unlink the set.
The sets exist for the specified config.
Did not find a matching set.
Unable to choose a set.
Unable to remove the config as it has sub configs.
LDAP connection error
Can't use system mode and file together.
Could not create '/var/db/zconf'. This is a permanent error.
Could not create '/var/db/zconf/<sys name>'. This is a permanent error.
Sys name matched /\//.
Sys name matched /\./.
No chooser string specified.
No comment specified.
No meta specified.
Failed to open the revision file for the set.
Failed to open or unlink lock file.
Config is locked.
The base does not exist or could not be created.
No ZConf object passed.
No zconf.zml var hash passed.
This can be done by checking $zconf->{error} to see if it is defined. If it is defined, The number it contains is the corresponding error code. A description of the error can also be found in $zconf->{errorString}, which is set to "" when there is no error.
The default is 'xdf_config_home/zconf.zml', which is generally '~/.config/zconf.zml'. See perldoc ZML for more information on the file format. The keys are listed below.
This should be set to 'file' to use this backend.
This is a boolean value. If it is set to 1, only the file backend is used.
This will override 'backend'.
Basically the same as using the backend to 'file'.
This is the base directory to use for storing the configs in.
Zane C. Bowers-Hadley, <vvelox at vvelox.net>
<vvelox at vvelox.net>
Please report any bugs or feature requests to bug-zconf at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=ZConf. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-zconf at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc ZConf
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=ZConf
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/ZConf
CPAN Ratings
http://cpanratings.perl.org/d/ZConf
Search CPAN
http://search.cpan.org/dist/ZConf
Subversion Repository
http://eesdp.org/svnweb/index.cgi/pubsvn/browse/Perl/ZConf
Copyright 2011 Zane C. Bowers-Hadley, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install ZConf, copy and paste the appropriate command in to your terminal.
cpanm
cpanm ZConf
CPAN shell
perl -MCPAN -e shell install ZConf
For more information on module installation, please visit the detailed CPAN module installation guide.