ePages 6.11.0 - DE_EPAGES/Database/API/MyIniReader.pm

Package DE_EPAGES::Database::API::MyIniReader

Module for working with MySQL configuration files.

Example
my $MyIniReader = DE_EPAGES::Database::API::MyIniReader->new(
    FileName => 'c:/test/test.ini'
);
my $Value = $MyIniReader->get( 'Section 1', 'Key 1' );

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

private attributes ( for use inside this module only ):
{FileName}  - name of the config file
{Values}    - hash of sections
$self->{Values}->{$Section} is a hash of key-value pairs
$self->{Values}->{$Section}->{$key} is a single value

Functions

existsSection
fileName
get
getBool
new
section
sectionNames

existsSection

Returns true if the section exists in the ini file.

Syntax
$Exists = $MyIniReader->existsSection($Section);
Return
$Section (string)
section name

fileName

Returns the config file name.

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

get

Returns a value from the config file or $Default if the given key was not found. If the queried key is a flag without a value, undef is returned even if the flag is set. In this case, use getBool

Syntax
$MyIniReader->get( $Section, $Key );
$MyIniReader->get( $Section, $Key, $Default );
Example
$MyIniReader->get( 'mysqld', 'datadir', '/var/lib/mysql' );
Input
$Section (string)
section name
$Key (string)
key name
$Default (string)
(optional) default value, used if the key does not exist
Return
$Value (string)
configuration value

getBool

Returns a value from the config file or $Default if the given key was not found. Returns false if the key does not exist. Returns false if the value is 0, OFF, FALSE, N or NO (case insensitive). Returns true if the value is 1, ON, TRUE, Y or YES (case insensitive). Returns true if the key has no value. Returns true if the key has another value.

Syntax
$Value = $MyIniReader->getBool( $Section, $Flag );
Example
my $Value = $MyIniReader->get( 'mysqld', 'binlog' );
Input
$Section (string)
section name
$Key (string)
key name
$Default (string)
(optional) default value, used if the key does not exist
Return
$Value (boolean)
configuration value

new

Constructs a new my.ini parser object.

Syntax
$MyIniReader = DE_EPAGES::Database::API::MyIniReader->new(
    FileName => $FileName
    );
Example
$MyIniReader = DE_EPAGES::Database::API::MyIniReader->new(
    FileName => 'my.ini'
);
Input
$FileName (string)
config file name
Return
$MyIniReader (object)
an MyIniReader object

section

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

Syntax
$hSection = $MyIniReader->section( $Section );
Example
$hDatabase = $MyIniReader->section( 'mysqld' );
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 = $MyIniReader->sectionNames
Return
$aSections (array ref)
section names