Plugin/Config.pm

filter: Statementstmt 66.6% 4 / 6 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 75.0% 6 / 8 CC 1 SCAR 1.4
CC
1
Cov
67%
BEGIN
1.3
BEGIN
1.0
CRAP 1.1
↑ Summary Config.pm »
1 package Terse::Plugin::Config;
2  
3 1 ▶use base 'Terse::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=2.6
5 use Data::LNPath qw/lnpath/;
6  
7 sub build_plugin {
8 my ($self) = @_;
9 if (!$self->config_file) {
10 my $file = $0;
11 ($self->config_file = $0) =~ s/(\.psgi)?$/.json/;
12 }
13 $self->{data} = $self->_read_file($self->config_file);
14 return $self;
15 }
16  
17 sub find {
18 my ($self, $path) = @_;
19 return lnpath($self->{data}, $path);
20 }
21  
22 sub _read_file {
23 my ($self, $file) = @_;
24 open my $fh, '<', $file or die "Cannot open config file: $file";
25 my $content = do { local $/; <$fh> };
26 close $fh;
27 $self->_parse_config($content);
28 }
29  
30 sub _parse_config {
31 my ($self, $content) = @_;
32 return JSON->new->decode($content);
33 }
34  
35 1;
36  
37 __END__
↑ Summary Config.pm »