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

NAME

Config::File::Simple - a module to parse and edit a configuration file

SYNOPSIS

    use Config::File::Simple;

    my $configuration_file = 'path/to/the/config/file';
    my $config = new Config::File::Simple($configuration_file);

DESCRIPTION

Config::File::Simple is a OO module to parse and edit configuration files. The configuration file's syntax is simple:

    VARIABLE1 = VALUE1
    variable2 = value \# 2! # This is a comment
    # This is another comment

Special characters mustn't contained in the variable's name. Hashs in value have to be escaped with a backslash: \#, but Config::File::Simple will do this for you (see METHODS).

METHODS

Parse the config file

Get the value of a variable is simple, too. You can use read() to do this.

Usage:

    my $value_of_foo = $config->read('foo');

If there's only one variable given, read() will return it's value.

If you give more than one arguments, read() will return a hash with the variables and the values:

    my %hash = $config->read('foo', 'bar', 'quux');
    my $value_of_foo = $hash{'foo'};

Of course you can give arrays as arguments:

    my @array = qw/foo bar quux/;
    my %hash = $config->read(@array);
    my $value_of_foo = $hash{'foo'};

If there are escaped hash (\#) in the value, read() will unescape them for you:

Example:

This is the config file:

    foo = bar
    quux = qu \#u ux

And this is the Perl script:

    print $config->read('quux');

The output will be:

    qu #u ux

Edit the config file

There are two methods, to create and edit the configuration file: set() and add_comment().

set()

set() is a wrapper which uses the commands add() and change(). It changes the value of a variable. If the variable doesn't exist, it will add this variable.

Usage of set():

    my $variable = 'foo';
    my $value = 'bar';
    if ($config->set($variable, $value)) {
        print "Success!\n";
    }

Now the variable foo has got the value bar.

You can't give more than one arguments, and so you can't use it in list context. I hope this will be fixed in a new version

add_comment()

add_comment() adds a comment at the end of the file.

Usage:

    my $comment = 'This is a test!';
    if ($config->add_comment($comment)) {
        print "Success!\n";
    }

Now there is a new line at the end of the file:

    # This is a test!

In list context add_comment() will add all comments:

    my @comments = ('Comment 1', 'Comment 2');
    if ($config->add_comment(@comments)) {
        print "Success!\n";
    }

Now there are these two lines at the end of the file:

    # Comment 1
    # Comment 2

AUTHOR

The module id developed by Kai Wilker. You can send questions to this module to kaiw@cpan.org.

BUGS

Feel free to send bug-reports to kaiw@cpan.org.

SEE ALSO

See also Config::File, Config::Simple, Config::Any.

COPYRIGHT AND LICENSE

Copyright (C) 2008 by Kai Wilker. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.