|
/home/cpanrun/depot/main/contrib-patched/perl/CPAN/src/Class-ConfigMgr/blib/lib/Class/ConfigMgr.pm |
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!
=head1 DESCRIPTION
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 the AppConfig manpage configuration files.
read_config($file)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,
define is most commonly used within the init method
all subclasses must implement.
undef. Inherited
from the Class::ErrorHandler manpage.
error.
Inherited from the Class::ErrorHandler manpage.
Subclassing Class::ConfigMgr is easy and only requires one
method, init, to be implemented.
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
the SYNOPSIS manpage.
the Class::ErrorHandler manpage
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.
|
/home/cpanrun/depot/main/contrib-patched/perl/CPAN/src/Class-ConfigMgr/blib/lib/Class/ConfigMgr.pm |