Coder Social home page Coder Social logo

config-dot's Introduction

NAME
    Config::Dot - Module for simple configure file parsing.

SYNOPSIS
     my $cnf = Config::Dot->new(%params);
     my $struct_hr = $cnf->parse($string);
     $cnf->reset;
     my $serialized = $cnf->serialize;

METHODS
    "new(%params)"
             Constructor.

            *       "callback"

                     Callback code for adding parameter.
                     Callback arguments are:
                     $key_ar - Reference to array with keys.
                     $value - Key value.
                     Default is undef.

            *       "config"

                     Reference to hash structure with default config data.
                     This is hash of hashes structure.
                     Default value is reference to blank hash.

            *       "set_conflicts"

                     Set conflicts detection as error.
                     Default value is 1.

    "parse($string_or_array_ref)"
             Parse string $string_or_array_ref or reference to array $string_or_array_ref.
             Use $INPUT_RECORD_SEPARATOR variable to split lines.
             Returns hash structure with configuration.

    "reset()"
             Reset content in class (config parameter).
             Returns undef.

    "serialize()"
             Serialize 'config' hash to output.
             Use $INPUT_RECORD_SEPARATOR variable to join lines.
             Returns string with serialized configuration.

PARAMETER_FILE
     # Comment.
     # blabla

     # White space.
     /^\s*$/

     # Parameters.
     # Key must be '[-\w\.:,]+'.
     # Separator is '='.
     key=val
     key2.subkey.subkey=val

ERRORS
     new():
             Bad 'config' parameter.
             Parameter 'callback' isn't code reference.
             From Class::Utils::set_params():
                     Unknown parameter '%s'.

     parse():
             Bad key '%s' in string '%s' at line '%s'.
             From Config::Utils::hash():
                      Conflict in '%s'.

     serialize():
             Unsupported stay with newline in value.

EXAMPLE1
     # Pragmas.
     use strict;
     use warnings;

     # Modules.
     use Config::Dot;
     use Dumpvalue;

     # Object.
     my $struct_hr = Config::Dot->new->parse(<<'END');
     key1=value1
     key2=value2
     key3.subkey1=value3
     END

     # Dump
     my $dump = Dumpvalue->new;
     $dump->dumpValues($struct_hr);

     # Output:
     # 0  HASH(0x84b98a0)
     #    'key1' => 'value1',
     #    'key2' => 'value2',
     #    'key3' => HASH(0x8da3ab0)
     #       'subkey1' => 'value3',

EXAMPLE2
     # Pragmas.
     use strict;
     use warnings;

     # Modules.
     use Config::Dot;

     # Object with data.
     my $c = Config::Dot->new(
             'config' => {
                     'key1' => {
                             'subkey1' => 'value1',
                     },
                     'key2' => 'value2',
             },
     );

     # Serialize.
     print $c->serialize."\n";

     # Output:
     # key1=subkey1.value1
     # key2=value2

EXAMPLE3
     # Pragmas.
     use strict;
     use warnings;

     # Modules.
     use Config::Dot;
     use Dumpvalue;

     # Object.
     my $struct_hr = Config::Dot->new(
             'callback' => sub {
                    my ($key_ar, $value) = @_;
                    if ($key_ar->[0] eq 'key3' && $key_ar->[1] eq 'subkey1'
                            && $value eq 'value3') {

                            return 'FOOBAR';
                    }
                    return $value;
             },
     )->parse(<<'END');
     key1=value1
     key2=value2
     key3.subkey1=value3
     END

     # Dump
     my $dump = Dumpvalue->new;
     $dump->dumpValues($struct_hr);

     # Output:
     # 0  HASH(0x84b98a0)
     #    'key1' => 'value1',
     #    'key2' => 'value2',
     #    'key3' => HASH(0x8da3ab0)
     #       'subkey1' => 'FOOBAR',

DEPENDENCIES
    Class::Utils, Config::Utils, English, Error::Pure, Readonly.

SEE ALSO
    Config::Utils.

REPOSITORY
    <https://github.com/tupinek/Config-Dot>

AUTHOR
    Michal Špaček <mailto:[email protected]>

    <http://skim.cz>

LICENSE AND COPYRIGHT
    BSD license.

VERSION
    0.06

config-dot's People

Contributors

michal-josef-spacek avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.