Eddie Olsson > Config-Abstract > Config::Abstract::Ini

Download:
Config-Abstract-0.16.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.16   Source  

NAME ^

Config::Abstract::Ini - Perl extension for handling ini style files

SYNOPSIS ^

 use Config::Abstract::Ini;
 my $ini = new Config::Abstract::Ini('testdata.ini');

DESCRIPTION ^

 Have you ever wanted an easy to use interface to your own
 config files, but ended up doing 'require  mysettings.pl'
 because you couldn't be bothered?  Config::Abstract::Ini solves
 that  for  you, giving you an object in  exchange for the
 name of your settings file.
 
 For compatibility with other config file formats, Ini can
 understand  hierarchical ini files using double colons as
 delimiters.  Just make sure you don't create name clashes
 by assigning both a value and a subentry to the same name
 in the file. This is currently supported for one sublevel
 only, which will have to be improved in future releases.

EXAMPLES ^

 We assume the content of the file 'testdata.ini' to be:
 [myentry]
 ;comment
 thisssetting = that
 thatsetting=this
 ;end of ini
 
 
 use Config::Abstract::Ini;
 my $settingsfile = 'testdata.ini';
 my $settings = new Config::Abstract::Ini($Settingsfile);
 
 # Get all settings
 my %allsettings = $settings->get_all_settings;
 
 # Get a subsection (called an entry here, but it's 
 # whatever's beneath a [section] header)
 my %entry = $settings->get_entry('myentry');
 
 # Get a specific setting from an entry
 my $value = $settings->get_entry_setting('myentry',
                                          'thissetting');

 # Get a specific setting from an entry, giving a default
 # to fall back on
 my value = $settings->get_entry_setting('myentry',
                                         'missingsetting',
                                         'defaultvalue');
 We can also make use of subentries, with a ini file like
 this:

 [book]
 title=A book of chapters
 author=Me, Myself and Irene

 [book::chapter1]
 title=The First Chapter, ever
 file=book/chapter1.txt

 [book::chapter2]
 title=The Next Chapter, after the First Chapter, ever
 file=book/chapter2.txt
 # btw, you can use unix style comments, too...
 ;end of ini

 use Config::Abstract::Ini;
 my $settingsfile = 'test2.ini';
 my $ini = new Config::Abstract::Ini($Settingsfile);
 
 my %book = $ini->get_entry('book');
 my %chap1 = $ini->get_entry_setting('book','chapter1');
 my $chap1title = $chapter1{'title'};
 
 # Want to see the inifile?
 # If you can live without comments and blank lines ;),
 # try this:
 print("My inifile looks like this:\n$ini\nCool, huh?\n");

METHODS ^

get_all_settings

Returns a hash of all settings found in the processed file

get_entry ENTRYNAME

Returns a hash of the settings within the entry ENTRYNAME

get_entry_setting ENTRYNAME,SETTINGNAME [,DEFAULTVALUE]

Returns the value corresponding to ENTRYNAME,SETTINGSNAME. If the value isn't set it returns undef or, optionally, the DEFAULTVALUE

set_all_settings SETTINGSHASH

Fill settings with data from SETTINGSHASH

set_entry ENTRYNAME,ENTRYHASH

Fill the entry ENTRYNAME with data from ENTRYHASH

set_entry_setting ENTRYNAME,SETTINGNAME,VALUE

Set the setting ENTRYNAME,SETTINGSNAME to VALUE

BUGS ^

* Comments have to be on their own lines, end of line comments won't work properly * Serialisation does not take original line ordering into consideration, so comments may end up far from what they're supposed to document

COPYRIGHT ^

Copyright (c) 2003 Eddie Olsson. All rights reserved.

 This library is free software; you can redistribute it
 and/or modify it under the same terms as Perl itself.

AUTHOR ^

Eddie Olsson <ewt@avajadi.org>

SEE ALSO ^

perl.

syntax highlighting: