Why not adopt me?
NAME
Bot::Cobalt::Conf::File - Base class for Bot::Cobalt cfg files
SYNOPSIS
## Subclass for a particular cfg file:
package
MyPackage::Conf;
use
Moo;
# An attribute filled from loaded YAML cfg_as_hash:
has
opts
=> (
lazy
=> 1,
is
=>
'rwp'
,
default
=>
sub
{
my
(
$self
) =
@_
;
$self
->cfg_as_hash->{Opts}
},
);
# Override validate() to check for correctness:
around
'validate'
=>
sub
{
my
(
$orig
,
$self
,
$cfg_hash
) =
@_
;
die
"Missing directive: Opts"
unless
defined
$cfg_hash
->{Opts};
1
};
## Use cfg file elsewhere:
package
MyPackage;
my
$cfg
= MyPackage::Conf->new(
cfg_path
=>
$path_to_yaml_cfg
,
);
my
$opts
=
$cfg
->opts;
DESCRIPTION
This is the base class for Bot::Cobalt configuration files. It consumes the Bot::Cobalt::Conf::Role::Reader role and loads a configuration hash from a YAML file specified by the required cfg_path attribute.
The validate method is called at load-time and passed the configuration hash before it is loaded to the cfg_as_hash attribute; this method can be overriden by subclasses to do some load-time checking on a configuration file.
cfg_path
The cfg_path attribute is required at construction-time; this is the actual path to the YAML configuration file.
cfg_as_hash
The cfg_as_hash attribute returns the loaded file as a hash reference. This is normally used by subclasses to fill attributes, and not used directly.
rehash
The rehash method attempts to reload the current cfg_as_hash from cfg_path.
AUTHOR
Jon Portnoy <avenj@cobaltirc.org>