/usr/share/perl5/App/Alice/Config.pm is in alice 0.19-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | package App::Alice::Config;
use FindBin;
use Data::Dumper;
use File::ShareDir qw/dist_dir/;
use Getopt::Long;
use Any::Moose;
has assetdir => (
is => 'ro',
isa => 'Str',
default => sub {
if (-e "$FindBin::Bin/../share/templates") {
return "$FindBin::Bin/../share";
}
return dist_dir('App-Alice');
}
);
has images => (
is => 'rw',
isa => 'Str',
default => "show",
);
has avatars => (
is => 'rw',
isa => 'Str',
default => "show",
);
has style => (
is => 'rw',
isa => 'Str',
default => 'default',
);
has timeformat => (
is => 'rw',
isa => 'Str',
default => '24',
);
has alerts => (
is => 'rw',
isa => 'Str',
default => 'show',
);
has quitmsg => (
is => 'rw',
isa => 'Str',
default => 'alice.',
);
has debug => (
is => 'rw',
isa => 'Bool',
default => 0,
);
has port => (
is => 'rw',
isa => 'Str',
default => "8080",
);
has address => (
is => 'rw',
isa => 'Str',
default => '127.0.0.1',
);
has auth => (
is => 'rw',
isa => 'HashRef[Str]',
default => sub {{}},
);
has highlights => (
is => 'rw',
isa => 'ArrayRef[Str]',
default => sub {[]},
);
has servers => (
is => 'rw',
isa => 'HashRef[HashRef]',
default => sub {{}},
);
has order => (
is => 'rw',
isa => 'ArrayRef[Str]',
default => sub {[]},
);
has monospace_nicks => (
is => 'rw',
isa => 'ArrayRef[Str]',
default => sub {['Shaniqua']},
);
has path => (
is => 'ro',
isa => 'Str',
default => "$ENV{HOME}/.alice",
);
has file => (
is => 'ro',
isa => 'Str',
default => "config",
);
has fullpath => (
is => 'ro',
isa => 'Str',
lazy => 1,
default => sub {$_[0]->path ."/". $_[0]->file},
);
has commandline => (
is => 'ro',
isa => 'HashRef',
default => sub {{}},
);
has ignore => (
is => 'rw',
isa => 'ArrayRef',
default => sub {[]},
);
has message_store => (
is => 'rw',
isa => 'Str',
default => 'Memory'
);
has static_prefix => (
is => 'rw',
isa => 'Str',
default => '/static/',
);
sub ignores {@{$_[0]->ignore}}
sub add_ignore {push @{shift->ignore}, @_}
sub BUILD {
my $self = shift;
$self->load;
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);
}
sub http_port {
my $self = shift;
if ($self->commandline->{port}) {
return $self->commandline->{port};
}
return $self->port;
}
sub http_address {
my $self = shift;
if ($self->commandline->{address}) {
return $self->commandline->{address};
}
if ($self->address eq "localhost") {
$self->address("127.0.0.1");
}
return $self->address;
}
sub show_debug {
my $self = shift;
if ($self->commandline->{debug}) {
return 1;
}
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;
{
local $Data::Dumper::Terse = 1;
local $Data::Dumper::Indent = 1;
print $fh Dumper($config)
or warn "Can not write config file: $!\n";
}
}
sub serialized {
my $self = shift;
return {
map {
my $name = $_->name;
$name => $self->$name;
} grep {$_->has_write_method}
$self->meta->get_all_attributes
};
}
__PACKAGE__->meta->make_immutable;
1;
|