line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Terse::Plugin::Config; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
972
|
use base 'Terse::Plugin'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
462
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
440
|
use Data::LNPath qw/lnpath/; |
|
1
|
|
|
|
|
1789
|
|
|
1
|
|
|
|
|
6
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub build_plugin { |
8
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
9
|
0
|
0
|
|
|
|
|
if (!$self->config_file) { |
10
|
0
|
|
|
|
|
|
my $file = $0; |
11
|
0
|
|
|
|
|
|
($self->config_file = $0) =~ s/(\.psgi)?$/.json/; |
12
|
|
|
|
|
|
|
} |
13
|
0
|
|
|
|
|
|
$self->data = $self->_read_file($self->config_file); |
14
|
0
|
|
|
|
|
|
return $self; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub find { |
18
|
0
|
|
|
0
|
0
|
|
my ($self, $path) = @_; |
19
|
0
|
|
|
|
|
|
return lnpath($self->config, $path); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _read_file { |
23
|
0
|
|
|
0
|
|
|
my ($self, $file) = @_; |
24
|
0
|
0
|
|
|
|
|
open my $fh, '<', $file or die "Cannot open config file: $file"; |
25
|
0
|
|
|
|
|
|
my $content = do { local $/; <$fh> }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
close $fh; |
27
|
0
|
|
|
|
|
|
$self->_parse_config($content); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _parse_config { |
31
|
0
|
|
|
0
|
|
|
my ($self, $content) = @_; |
32
|
0
|
|
|
|
|
|
$self->graft('data', $content); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
1; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
__END__ |