File Coverage

lib/OneTool/Configuration.pm
Criterion Covered Total %
statement 26 26 100.0
branch 8 8 100.0
condition 2 3 66.6
subroutine 7 7 100.0
pod 2 2 100.0
total 45 46 97.8


line stmt bran cond sub pod time code
1             package OneTool::Configuration;
2              
3             =head1 NAME
4              
5             OneTool::Configuration - OneTool Configuration module
6              
7             =cut
8              
9 1     1   697 use strict;
  1         2  
  1         39  
10 1     1   5 use warnings;
  1         2  
  1         33  
11              
12 1     1   6 use FindBin;
  1         3  
  1         49  
13 1     1   960 use File::Slurp;
  1         12763  
  1         88  
14 1     1   11 use JSON;
  1         3  
  1         9  
15              
16             my $DIR_CONFIG = "$FindBin::Bin/../conf";
17              
18             =head1 FUNCTIONS
19              
20             =head2 Directory($directory)
21              
22             Sets (if $directory provided) and returns $DIR_CONFIG value
23              
24             =cut
25              
26             sub Directory
27             {
28 2     2 1 1346 my $directory = shift;
29              
30 2 100       7 if (defined $directory)
31             {
32 1         2 $DIR_CONFIG = $directory;
33             }
34              
35 2         5 return ($DIR_CONFIG);
36             }
37              
38             =head2 Get($param)
39              
40             Gets configuration from file $param->{file} or for module $param->{module}
41              
42             =cut
43              
44             sub Get
45             {
46 3     3 1 1257 my $param = shift;
47              
48 3 100       14 my $file = (
    100          
49             defined $param->{module}
50             ? "$DIR_CONFIG/$param->{module}.conf"
51             : (defined $param->{file} ? $param->{file} : undef)
52             );
53              
54 3 100 66     100 if ((defined $file) && (-r $file))
55             {
56 2         6 my $json_str = read_file($file);
57 2         186 my $conf = from_json($json_str);
58              
59 2         52 return ($conf);
60             }
61              
62 1         3 return (undef);
63             }
64              
65             1;
66              
67             =head1 AUTHOR
68              
69             Sebastien Thebert
70              
71             =cut