ePages 6.0 Patch 8 - DE_EPAGES/Installer/API/CPANHelper/IniConfig.pm

Package DE_EPAGES::Core::API::IniConfig

Module for working with Windows-style .ini files.

Example
my $IniConfig = DE_EPAGES::Core::API::IniConfig->new(
    FileName => 'c:/test/test.ini'
);
my $Value = $IniConfig->get( 'Section 1', 'Key 1' );
$IniConfig->set( 'Section1', 'key2', 'value2' );
$IniConfig->rewrite();

An ini file has the following structure:
[Section 1]
Key 1=value1
key2=value2

private attributes ( for use inside this module only ):
{FileName}  - name of the config file
{CaseSensitive}    - flag set if keys and sections are case insensitive
{Values}    - hash of sections
$self->{Values}->{$Section} is a hash of key-value pairs
$self->{Values}->{$Section}->{$key} is a single value

Package DE_EPAGES::Installer::API::CPANHelper::IniConfig

Functions

addSection
fileName
new
read
section
sectionNames
set

addSection

Adds a section to the ini file if the section not exists.

Syntax
$IniConfig->addSection($Section);
Return
$Section (string)
section name

fileName

Sets or returns the config file name.

Syntax
$IniConfig->fileName( $FileName );
$FileName = $IniConfig->fileName;
Input
$FileName (string)
config file name
Return
$FileName (string)
config file name

new

Constructs a new config file object. By default, key and section names are case insensitive.

Syntax
$IniConfig = DE_EPAGES::Core::API::IniConfig->new(
    FileName => $FileName,
    CaseSensitive => $CaseSensitive,
    Create => $Create,
    flock => $flock,
);
Example
$IniConfig = DE_EPAGES::Core::API::IniConfig->new(
    FileName => 'win.ini'
);
Input
$FileName (string)
config file name
$CaseSensitive (boolean)
if true, then key and section names are case sensitive
$Create (boolean)
(optional, default=0) if true, no error is thrown when the
file does not exist
$flock (boolean)
(optional, default=1) if true, the file is locked for reading
and writing using
DE_EPAGES::Core::API::File::LockFile
to prevent file corruption
$CaseSensitive (boolean)
if true, then key and section names are case sensitive
Return
$IniConfig (object)
an IniConfig object

read

Reads the configuration file in the windows ini file format.

Syntax
$IniConfig->read( $FileName );
Example
$IniConfig->read( 'database.ini' );
Input
$FileName (string)
config file name

section

Returns the specified section with key-value pairs as a hash reference or creates a section with the new hash. Returns an empty hash reference if the section does not exist.

Syntax
$hSection = $IniConfig->section( $Section );
$hSection = $IniConfig->section( $Section, $hSection );
Example
$hDatabase = $IniConfig->section( 'Database' );
Input
$Section (string)
section name
$hSection (hash ref)
key-value pairs (optional)
Return
$hSection (hash ref)
key-value pairs

sectionNames

Returns all section names found in the config file.

Syntax
$aSections = $IniConfig->sectionNames
Return
$aSections (array ref)
section names

set

Sets a value in the config file. Calls $IniConfig->rewrite to make the changes persistent.

Syntax
$IniConfig->set( $Section, $Key, $Value );
Example
$IniConfig->set( 'Database', 'User', 'sa' );
Input
$Section (string)
section name
$Key (string)
key name
$Value (string)
configuration value