Conf::Libconfig(3p)

NAME
Conf::Libconfig - Perl extension for libconfig

SYNOPSIS
  use Conf::Libconfig;
  my $self = new Conf::Libconfig;
  $self->read_file($cfg);
  $self->read_string("test:{key = \"only for test!\";};");
  my $value = $self->lookup_value("abc.edf");
  print $value;

  use Data::Dumper;
  my $arrayref = $self->fetch_array("cdef.abcd.arrayref");
  print Dumper $arrayref;
  my $hashref = $self->fetch_hashref("cdef.abcd.hashref");
  print Dumper $hashref;

  $self->add("fghj.rtyu", "binarykey", "0b1");
  $self->add_boolscalar("fghj.rtyu", "binarykey", 0);

  # if program is over, DESTROY can auto exit, and you can ignore function delete.
  $self->delete();

DESCRIPTION
You can use "Conf::Libconfig" for perl config, and support Scalar, Array and Hash data structures etc. like C or C++ function. "Conf::Libconfig" could reduce your config file and quote by C/C++ transportability.

  EXPORT
None by default.

  $self->new()
construct.

  $self->delete()
destruct.

  $self->DESTROY()
destruct and auto release memory.

  $self->getversion()
get current libconfig version.

  $self->read($buffer)
read a handle buffer.

  $self->read_file ($file)
read from a config file.

  $self->read_string ($string)
read from a string, require libconfig version > 1.4.

  $self->write($buffer)
write to a handle buffer.

  $self->write_file($filename)
write to a file.

  $self->get_include_dir()
get a include directory, like @include './conf/config.cfg', and get a absolute path, require libconfig version > 1.4.

  $self->set_include_dir($path)
set a include directory, you can search the content of @include in $path, require libconfig version > 1.4.

  $self->lookup_value ($path)
automatically check and get value from config file, suggest use it.

  $self->setting_lookup ($path)
return setting resource.

  $self->fetch_array ($path)
return array list from path.

  $self->fetch_hashref ($path)
return hash reference from path.

  $self->add($path, $key, $item)
add a struct data for $key.

  $self->add_boolscalar($path, $key, $boolvalue)
add a bool value for $key.

  $self->add_scalar ($path, $key, $value)
add a pair of key and value node to handle and return true if add successfully.

  $self->modify_scalar ($path, $value)
modify new value to handle and return true if add successfully.

  $self->modify_boolscalar ($path, $value)
modify new bool value to handle and return true if add successfully.

  $self->add_array ($path, $key, \@array)
add array value to handle and return true if add successfully, but the elements must all be scalar values of the same type.

  $self->add_list ($path, $key, \@list)
the same as add_array, add list value to handle and return true if add successfully.

  $self->add_hash ($path, $key, \%hash)
add hash value to handle and return true if add successfully.

  $self->add_boolhash ($path, $key, \%hash)
add bool hash value to handle and return true if add successfully.

  $self->delete_node ($path)
return true if delete node of path successfully.

  $self->delete_node_key ($path, $key)
return true if delete node key of path successfully.

  $self->delete_node_elem ($path, $idx)
return true if delete node element of path successfully.

  $setting->length ()
return count of setting resource.

  $setting->get_item ($i)
return value of the $i item.

  $setting->get_type ()
return value type of setting resource.

  $self->lookup_bool ($path)
only get value type of bool from config file, please use lookup_value replace it.

  $self->lookup_int ($path)
only get value type of long int from config file, please use lookup_value replace it.

  $self->lookup_int64 ($path)
only get value type of long long int from config file, please use lookup_value replace it.

  $self->lookup_float ($path)
only get value type of float from config file, please use lookup_value replace it.

  $self->lookup_string ($path)
only get value type of string from config file, please use lookup_value replace it.

PREREQUISITES
This module requires the libconfig library from <http://www.hyperrealm.com/libconfig/>.

SOURCE CONTROL
You can always get the latest Conf::Libconfig source from its public Git repository:

    http://github.com/cnangel/Conf-Libconfig/tree/master

If you have a branch for me to pull, please let me know ;)

TO DO

•   Support xml config and yaml config.

SEE ALSO
You can compare this module Conf::Libconfig to Config, Config::General, Config::JSON.

http://my.huhoo.net/

AUTHOR
Cnangel, <cnangel@gmail.com>

COPYRIGHT AND LICENSE
This module as well as its programs are licensed under the BSD License.

Copyright (c) 2009, Alibaba Search Center, Alibaba Inc. All rights reserved.

Copyright (C) 2009 by cnangel

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

•   Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

•   Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

•   Neither the name of the Alibaba Search Center, Alibaba Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

  DISCLAIMER OF WARRANTY
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.