| Apache2-WebApp-Toolkit documentation | Contained in the Apache2-WebApp-Toolkit distribution. |
Apache2::WebApp::AppConfig - AppConfig extension for parsing config files
$c->config->parse('/path/to/file.cfg');
print $c->config->{$key}, "\n"; # key = value format
A module for accessing application configuration settings.
Return the configuration name/value pairs as a reference to a hash.
$c->config->parse($config);
# this is a comment foo = bar # bar is the value of 'foo' url = index.html#hello # 'hello' is treated as a comment
[block1] foo = bar # bar is the value of 'block1_foo' [block2] foo = baz # baz is the value of 'block2_foo'
Marc S. Brooks, <mbrooks@cpan.org> - http://mbrooks.info
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| 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__