The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

OpenPlugin::Config::Ini - Read Ini style configuration files

PARAMETERS

  • src

    Path and filename to the config file. If you don't wish to pass this parameter into OpenPlugin, you may instead set the package variable:

    $OpenPlugin::Config::Src = /path/to/config.conf

  • config

    Config passed in as a hashref

  • dir

    Directory to look for the config file in. This is usually unnecessary, as most will choose to make this directory part of the 'src' parameter.

  • type

    Driver to use for the config file. In most cases, the driver is determined by the extension of the file. If that may be unreliable for some reason, you can use this parameter.

 Example:
 my $OP = OpenPlugin->new( config => { src => '/some/file/name.ini' } );

CONFIG OPTIONS

There is no need to define a driver for a config file. However, within a "ini" config file, you'll want to use the following syntax:

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 main]
 type          = DBI
 db_owner      =
 username      = captain
 password      = whitman
 dsn           = dbname=usa
 db_name       =
 driver_name   = Pg
 sql_install   =
 long_read_len = 65536
 long_trunc_ok = 0

 [datasource other]
 type          = DBI
 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-2003 Eric Andreychek. All rights reserved.

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

AUTHORS

Eric Andreychek <eric@openthought.net>

Chris Winters <chris@cwinters.com>