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