Apache2::WebApp::AppConfig - AppConfig extension for parsing config files


Apache2-WebApp-Toolkit documentation Contained in the Apache2-WebApp-Toolkit distribution.

Index


Code Index:

NAME

Top

Apache2::WebApp::AppConfig - AppConfig extension for parsing config files

SYNOPSIS

Top

  $c->config->parse('/path/to/file.cfg');

  print $c->config->{$key}, "\n";    # key = value format

DESCRIPTION

Top

A module for accessing application configuration settings.

OBJECT METHODS

Top

parse

Return the configuration name/value pairs as a reference to a hash.

  $c->config->parse($config);

FILE FORMAT

Top

STANDARD

  # this is a comment
  foo = bar               # bar is the value of 'foo'
  url = index.html#hello  # 'hello' is treated as a comment

BLOCKED

  [block1]
  foo = bar               # bar is the value of 'block1_foo'

  [block2]
  foo = baz               # baz is the value of 'block2_foo' 

SEE ALSO

Top

Apache2::WebApp, AppConfig

AUTHOR

Top

Marc S. Brooks, <mbrooks@cpan.org> - http://mbrooks.info

COPYRIGHT

Top


Apache2-WebApp-Toolkit documentation Contained in the Apache2-WebApp-Toolkit distribution.

#----------------------------------------------------------------------------+
#
#  Apache2::WebApp::AppConfig - AppConfig extension for parsing config files
#
#  DESCRIPTION
#  A module for accessing application configuration settings.
#
#  AUTHOR
#  Marc S. Brooks <mbrooks@cpan.org>
#
#  This module is free software; you can redistribute it and/or
#  modify it under the same terms as Perl itself.
#
#----------------------------------------------------------------------------+

package Apache2::WebApp::AppConfig;

use strict;
use warnings;
use base 'Apache2::WebApp::Base';
use AppConfig qw( :argcount );
use Params::Validate qw( :all );

our $VERSION = 0.01;

#~~~~~~~~~~~~~~~~~~~~~~~~~~[  OBJECT METHODS  ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

#----------------------------------------------------------------------------+
# parse($file)
#
# Return the configuration name/value pairs as a reference to a hash.

sub parse {
    my ($self, $file)
      = validate_pos(@_,
          { type => OBJECT },
          { type => SCALAR }
      );

    my $config;

    eval {
        $config = AppConfig->new(
            {
                CREATE => 1,
                GLOBAL => {
                    ARGCOUNT => ARGCOUNT_ONE,
                },
            }
          );
        $config->file($file);
      };

    if ($@) {
        $self->error("Failed to parse config '$file'");
    }

    return $config->{FILE}->{STATE}->{VARIABLE};
}

1;

__END__