Bot::Cobalt::Conf::File - Base class for Bot::Cobalt cfg files
## Subclass for a particular cfg file: package MyPackage::Conf; use Moo; extends 'Bot::Cobalt::Conf::File'; # 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( path => $path_to_yaml_cfg, ); my $opts = $cfg->opts;
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 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.
The path attribute is required at construction-time; this is the actual path to the YAML configuration file.
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.
The rehash method attempts to reload the current cfg_as_hash from path.
Jon Portnoy <avenj@cobaltirc.org>
To install Bot::Cobalt, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Bot::Cobalt
CPAN shell
perl -MCPAN -e shell install Bot::Cobalt
For more information on module installation, please visit the detailed CPAN module installation guide.