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