Config-Parser

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

  # Access a configuration setting
  print $cf->get('core', 'root');
  
  __DATA__
  # Declare valid keywords:
  [core]
     root = STRING :default /
     umask = OCTAL
  [user]
     uid = NUMBER
     gid = NUMBER

INSTALLATION

To install this module type the following:

   perl Makefile.PL
   make
   make test
   make install

lib/Config/Parser/Ini.pm  view on Meta::CPAN


  use Config::Parser::Ini;
  my $cf = new Config::Parser::Ini(filename => "config.ini");

  __DATA__
  [core]
     root = STRING :default /
     umask = OCTAL
  [user]
     uid = NUMBER
     gid = NUMBER

This code specifies that the configuration file can contain at most two
sections: C<[core]> and C<[user]>. Two keywords are defined within each
section.  Data types are specified for each keyword, so the parser will
bail out in case of type mismatches. If the B<core.root> setting is not
present in the configuration, the default one will be created with the
value C</>.

It is often advisable to create a subclass of B<Config::Parser::Ini> and
use it for parsing.  For instance:

  package App::MyConf;
  use Config::Parser::Ini;
  1;
  __DATA__
  [core]
     root = STRING :default /
     umask = OCTAL
  [user]
     uid = NUMBER
     gid = NUMBER

Then, to parse the configuration file, it will suffice to do:

  $cf = my App::MyConf(filename => "config.ini");

One advantage of this approach is that it will allow you to install
additional validation for the configuration statements using the
B<:check> option.  The argument to this option is the name of a
method which will be invoked after parsing the statement in order
to verify its value.  It is described in detail below (see the section

lib/Config/Parser/Ini.pm  view on Meta::CPAN

      }
      return 1;
  }
  1;
  __DATA__
  [core]
     root = STRING :default / :check=dir_exists
     umask = OCTAL
  [user]
     uid = NUMBER
     gid = NUMBER

=head1 CONSTRUCTOR

    $cfg = new Config::Parser::Ini(%opts)

Creates a new parser object.  Keyword arguments are:

=over 4

=item B<filename>



( run in 1.198 second using v1.01-cache-2.11-cpan-5735350b133 )