Class::ConfigMgr is a base class for implementing a singleton object configuration manager.
# a basic subclass package Foo::ConfigMgr; use Class::ConfigMgr; @Foo::ConfigMgr::ISA = qw( Class::ConfigMgr ); sub init { my $cfg = shift; $cfg->define(Foo,Default=>1); $cfg->define(Bar,Default=>1); $cfg->define(Baz); $cfg->define(Fred); } # example config file foo.cfg Bar 0 Fred RightSaid # Foo 40 # application code Foo::ConfigMgr->read_config('foo.cfg') or die Foo::ConfigMgr->errstr; my $cfg = Foo::ConfigMgr->instance; print $cfg->Foo; # 1 (default. 40 was commented out.) print $cfg->Bar; # 0 print $cfg->Fred; # RightSaid print $cfg->Baz; # (undefined) # print $cfg->Quux; # ERROR!
Class::ConfigMgr is a base class for implementing a singleton object configuration manager. This module is based off of the configuration manager found in Movable Type and a limited subset of AppConfig configuration files.
Initializes the configuration manager by reads the configuration file specified by $file. Returns undefined if the configuration file could not be read. Use the errstr to retreive the error message. This method should only be called once and before any use of the instance method.
errstr
instance
instance returns a reference to the singleton object that is managing the configuration. As a singleton object, developers should ALWAYS call this method rather the call than new,
new
This method defines which directives are recognized by the application and optionally a default value if the directive is not explicted defined in the configuration file. define is most commonly used within the init method all subclasses must implement.
define
init
Captures an error message and return undef. Inherited from Class::ErrorHandler.
undef
Returns the last captured error message set by error. Inherited from Class::ErrorHandler.
error
Subclassing Class::ConfigMgr is easy and only requires one method, init, to be implemented.
All subclasses of Class::ConfigMgr must implement an init method that defines which directives are recognized and any associated default values. This method is automatically called by read_config before the actual configuration file is read. It is passed a reference to the singleton and the return value is ignored. See the example subclass in the SYNOPSIS.
read_config
Class::ErrorHandler
The software is released under the Artistic License. The terms of the Artistic License are described at http://www.perl.com/language/misc/Artistic.html.
Except where otherwise noted, Class::ConfigMgr is Copyright 2005, Timothy Appnel, tima@cpan.org. All rights reserved.
1 POD Error
The following errors were encountered while parsing the POD:
=begin without a target?
To install Class::ConfigMgr, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::ConfigMgr
CPAN shell
perl -MCPAN -e shell install Class::ConfigMgr
For more information on module installation, please visit the detailed CPAN module installation guide.