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) = @_;


  # Override validate() to check for correctness:
  around 'validate' => sub {
    my ($orig, $self, $cfg_hash) = @_;
    die "Missing directive: Opts"
      unless defined $cfg_hash->{Opts};


  ## Use cfg file elsewhere:
  package MyPackage;
  my $cfg = MyPackage::Conf->new(
    cfg_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 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.


The cfg_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 cfg_path.


Jon Portnoy <>