The Perl Advent Calendar needs more articles for 2022. Submit your idea today!


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;
 # 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.


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,


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.


Captures an error message and return undef. Inherited from Class::ErrorHandler.


Returns the last captured error message set by error. Inherited from Class::ErrorHandler.


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.




The software is released under the Artistic License. The terms of the Artistic License are described at


Except where otherwise noted, Class::ConfigMgr is Copyright 2005, Timothy Appnel, All rights reserved.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 86:

=begin without a target?