NAME

OpenInteract::Config::Ini - Read/write INI-style (++) configuration files

SYNOPSIS

my $config = OpenInteract::Config::Ini->new({ filename => 'myconf.ini' });
print "Main database driver is:", $config->{db_info}{main}{driver}, "\n";
$config->{db_info}{main}{username} = 'mariolemieux';
$config->write_file;

DESCRIPTION

This is a very simple implementation of a configuration file reader/writer that preserves comments and section order, enables multivalue fields and one or two-level sections.

Yes, there are other configuration file modules out there to manipulate INI-style files. But this one takes several features from them while providing a very simple and uncluttered interface.

  • From Config::IniFiles we take comment preservation and the idea that we can have multi-level sections like:

    [Section subsection]
  • From Config::Ini and AppConfig we borrow the usage of multivalue keys:

    item = first
    item = second

Example

Given the following configuration in INI-style:

[datasource]
default_connection_db = main
db                    = main
db                    = other

[db_info main]
db_owner      =
username      = captain
password      = whitman
dsn           = dbname=usa
db_name       =
driver_name   = Pg
sql_install   =
long_read_len = 65536
long_trunc_ok = 0

[db_info other]
db_owner      =
username      = tyger
password      = blake
dsn           = dbname=britain
db_name       =
driver_name   = Pg
sql_install   =
long_read_len = 65536
long_trunc_ok = 0

You would get the following Perl data structure:

$config = {
  datasource => {
     default_connection_db => 'main',
     db                    => [ 'main', 'other' ],
  },
  db_info => {

     main => {
          db_owner      => undef,
          username      => 'captain',
          password      => 'whitman',
          dsn           => 'dbname=usa',
          db_name       => undef,
          driver_name   => 'Pg',
          sql_install   => undef,
          long_read_len => '65536',
          long_trunc_ok => '0',
     },

     other => {
          db_owner      => undef,
          username      => 'tyger',
          password      => 'blake',
          dsn           => 'dbname=britain',
          db_name       => undef,
          driver_name   => 'Pg',
          sql_install   => undef,
          long_read_len => '65536',
          long_trunc_ok => '0',
     },
  },
};

'Global' Key

Anything under the 'Global' key in the configuration will be available under the configuration object root. For instance:

[Global]
DEBUG = 1

will be available as:

$CONFIG->{DEBUG}

SEE ALSO

AppConfig

Config::Ini

Config::IniFiles

COPYRIGHT

Copyright (c) 2001-2002 intes.net, inc.. All rights reserved.

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

AUTHORS

Chris Winters <chris@cwinters.com>