Bot-Cobalt
view release on metacpan or search on metacpan
lib/Bot/Cobalt/Conf/File.pm view on Meta::CPAN
package Bot::Cobalt::Conf::File;
$Bot::Cobalt::Conf::File::VERSION = '0.021003';
use v5.10;
use strictures 2;
use Carp;
use Bot::Cobalt::Common ':types';
use Bot::Cobalt::Serializer;
use Try::Tiny;
use Types::Path::Tiny -types;
use List::Objects::WithUtils;
use List::Objects::Types -types;
use Moo;
with 'Bot::Cobalt::Conf::Role::Reader';
has cfg_path => (
required => 1,
is => 'rwp',
isa => Path,
coerce => 1,
);
has cfg_as_hash => (
lazy => 1,
is => 'rwp',
isa => HashObj,
coerce => 1,
builder => '_build_cfg_hash',
);
has debug => (
is => 'rw',
isa => Bool,
builder => sub { 0 },
);
sub BUILD {
my ($self) = @_;
$self->cfg_as_hash
}
sub _build_cfg_hash {
my ($self) = @_;
if ($self->debug) {
warn
ref $self, " (debug) reading cfg_as_hash from ", $self->cfg_path, "\n"
}
my $cfg = $self->readfile( $self->cfg_path );
my $err; try {
$self->validate($cfg)
} catch {
$err = $_;
undef
} or croak "Conf validation failed for ". $self->cfg_path .": $err";
$cfg
}
sub rehash {
my ($self) = @_;
$self->_set_cfg_as_hash( $self->_build_cfg_hash )
( run in 0.536 second using v1.01-cache-2.11-cpan-5837b0d9d2c )