File Coverage

blib/lib/XT/Util.pm
Criterion Covered Total %
statement 27 27 100.0
branch 3 4 75.0
condition 2 3 66.6
subroutine 8 8 100.0
pod n/a
total 40 42 95.2


line stmt bran cond sub pod time code
1             package XT::Util;
2              
3 3     3   79193 use 5.008;
  3         12  
  3         111  
4 3     3   16 use strict;
  3         6  
  3         95  
5 3     3   1982 use utf8;
  3         7  
  3         17  
6              
7             our @EXPORT;
8             BEGIN {
9 3     3   7 $XT::Util::AUTHORITY = 'cpan:TOBYINK';
10 3         5 $XT::Util::VERSION = '0.001';
11            
12 3         59 @EXPORT = qw/__CONFIG__/;
13             }
14              
15 3     3   3450 use JSON qw/from_json/;
  3         59086  
  3         19  
16 3     3   603 use base qw/Exporter/;
  3         6  
  3         1153  
17              
18             sub __CONFIG__ (;$)
19             {
20 2     2   46 my ($package, $file) = caller(0);
21 2 50       9 $file = shift if @_;
22 2         7 _config_file($file);
23             }
24              
25             {
26             my %files;
27             sub _config_file
28             {
29 2     2   4 my $name = shift;
30             $files{ $name } ||= do
31 2   66     13 {
32 2         15 (my $config_file = $name) =~ s{\.(PL|pl|pm|pmc|t)$}{};
33 2         4 from_json do {
34 2 100       68 open my $fh, '<', "$config_file\.config"
35             or return $files{$name} = +{};
36 1         35 local $/ = <$fh>
37             };
38             };
39             }
40             }
41              
42             __PACKAGE__
43             __END__