App-Alice

 view release on metacpan or  search on metacpan

lib/App/Alice/Config.pm  view on Meta::CPAN

  mkdir $self->path unless -d $self->path;
}

sub load {
  my $self = shift;
  my $config = {};
  if (-e $self->fullpath) {
    $config = require $self->fullpath;
  }
  else {
    say STDERR "No config found, writing a few config to ".$self->fullpath;
    $self->write;
  }
  my ($port, $debug, $address) = @_;
  GetOptions("port=i" => \$port, "debug" => \$debug, "address=s" => \$address);
  $self->commandline->{port} = $port if $port and $port =~ /\d+/;
  $self->commandline->{debug} = 1 if $debug;
  $self->commandline->{address} = $address if $address;
  $self->merge($config);
}

lib/App/Alice/Config.pm  view on Meta::CPAN

  return $self->debug;
}

sub merge {
  my ($self, $config) = @_;
  for my $key (keys %$config) {
    if (exists $config->{$key} and my $attr = $self->meta->get_attribute($key)) {
      $self->$key($config->{$key}) if $attr->has_write_method;
    }
    else {
      say STDERR "$key is not a valid config option";
    }
  }
}

sub write {
  my ($self, $data) = @_;
  my $config = $data || $self->serialized;
  mkdir $self->path if !-d $self->path;
  open my $fh, ">", $self->fullpath;
  {



( run in 1.150 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )