Jon Portnoy > Bot-Cobalt-0.016000 > Bot::Cobalt::Conf::File

Download:
Bot-Cobalt-0.016000.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.016000   Source   Latest Release: Bot-Cobalt-0.016002

NAME ^

Bot::Cobalt::Conf::File - Base class for Bot::Cobalt cfg files

SYNOPSIS ^

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

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

path

The 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 path.

AUTHOR ^

Jon Portnoy <avenj@cobaltirc.org>

syntax highlighting: