NAME
Config::Abstract::Ini - Perl extension for handling ini style files
SYNOPSIS
my
$ini
= new Config::Abstract::Ini(
'test.ini'
);
DESCRIPTION
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
'test.ini'
to be:
[myentry]
;comment
thisssetting = that
thatsetting=this
;end of ini
my
$settingsfile
=
'test.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'
);
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
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:
(
"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 2003 Eddie Olsson.
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.
2 POD Errors
The following errors were encountered while parsing the POD:
- Around line 219:
'=item' outside of any '=over'
- Around line 243:
You forgot a '=back' before '=head1'