NAME
Config::Yacp - Yet Another Configuration Module
SYNOPSIS
use Config::Yacp;
my $config = Config::Yacp->new(FileName=>'Config.ini');
#retrieve the sections of the file
my @sections = $config->retrieve_sections;
#retrieve the parameters of a specific section
my @parameters = $config->retrieve_parameters("Section1");
#retrieve the value of a specific parameter
my $value = $config->retrieve_value("Section1","Parameter1");
#retrieve any comments attached to a parameter
my $comment = $config->retrieve_comment("Section2","Parameter3");
#add a new section
$config->add_section("Section3");
#add a parameter/value/comment to a section
$config->add_parameter("Section3","Parameter5","Value5","Optional Comment");
#change the value of a parameter
$config->change_value("Section3","Parameter5","Value10");
#delete a parameter
$config->delete_parameter("Section3","Parameter5");
#delete a section
$config->delete_section("Section3");
#delete a comment
$config->delete_comment("Section2","Parameter3");
#display the config file (uses Data::Dumper)
$config->display_config;
#save the .ini file with any changes
$config->save;
DESCRIPTION
- new
-
my $config = Config::Yacp->new(FileName=>'config.ini',CommentMarker=>';');
This method creates the Config::Yacp object and loads the file into an internal hash within the object. The filename parameter is mandatory, and the CommentMarker parameter is an optional one. Both parameter names are case insensitive. The default comment marker is the # character. The only other character that can be used as a comment marker is the ; character, which is used by Unreal Tournament config files.
- retrieve_sections
-
my @sections = $config->retrieve_sections;
This method retrieves the section names from the ini file.
- retrieve_parameters
-
my @params = $config->retrieve_parameters("Section1");
This method retrieves the parameters for a given section. This method will croak if the section does not exist.
- retrieve_value
-
my $value = $config->retrieve_value('Section1','Parameter2');
This method will retrieve the value of a given parameter within the specified section. It will croak if it receives a non-existent section or parameter.
- retrieve_comment
-
my $comment = $config->retrieve_comment('Section2','Parameter2');
This method will retrieve the comment attached to given parameter within a section. It will give a warning if the parameter does not have a comment. It will croak if the given section or parameter is invalid.
- change_value
-
$config->change_value('Section2','Parameter4','NewValue');
This method allows for the value of a specified parameter to be changed to a new value. It will croak if the given section or parameter is invalid.
- add_comment
-
$config->add_comment('Section1','Parameter2',"New comment");
This method will add a comment to a specified parameter within a section. It will croak if the given section or parameter is invalid.
- add_section
-
$config->add_section('Section3');
This method adds a new section to the configuration. It will give a warning if the section already exists.
- add_parameter
-
$config->add_parameter('Section3','Parameter5','Value5',"Optional comment");
This method will add a new parameter and value to a specified section, along with an optiona comment. It will croak if the section is invalid.
- delete_section
-
$config->delete_section('Section3');
This method will delete the given section. If there are any parameter/values still associated with it, they will be deleted as well. It will croak if the given section name is invalid.
- delete_parameter
-
$config->delete_parameter('Section3','Parameter5');
This method will delete a specified parameter within a section. It will also remove any comments associated with that parameter. It will croak if either the section or parameter name is invalid.
- delete_comment
-
$config->delete_comment('Section2','Parameter4');
This method will delete a comment associated with the specified parameter within a section. It will give a warning if a comment is not associated with the paramter.
- display_config
-
$config->display_config;
This method uses Data::Dumper to print to STDOUT the contents of the configuration variable within the Config::Yacp object.
- save
-
$config->save;
This method saves the contents of the configuration hash back to the file that it initially loaded the hash from.
EXPORT
None by default.
TODO
The configuration is stored inside a hash. It should be changed to an AoA to provide less overhead and an increase in performance.
SEE ALSO
AUTHOR
Thomas Stanley, <Thomas_J_Stanley@msn.com>
COPYRIGHT AND LICENSE
Copyright (C) 2002-2007 by Thomas Stanley
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.