OneTool/Configuration.pm

filter: Statementstmt 100% 28 / 28 Branchbran 100% 8 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 96.0% 48 / 50 CC 6 SCAR 10.4
CC
6
Cov
97%
Get
5.0
Directory
2.0
BEGIN
1.0
CRAP 2.8
↑ Summary OneTool.pm »
1 package OneTool::Configuration;
2  
3 =head1 NAME
4  
5 OneTool::Configuration - OneTool Configuration module
6  
7 =cut
8  
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 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 2 ▶{
Subroutine Directory: called CC=2 SCAR=6.9
Pod documented
28 2 my $directory = shift;
29  
30 2 ▶ if (defined $directory)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $directory) 1 1 2
31 {
32 1 $DIR_CONFIG = $directory;
33 }
34  
35 2 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 3 ▶{
Subroutine Get: called CC=5 SCAR=16.1
Pod documented
46 3 my $param = shift;
47  
48 my $file = (
49 defined $param->{module}
50 ? "$DIR_CONFIG/$param->{module}.conf"
51 : (defined $param->{file} ? $param->{file} : undef)
52 3 ▶ );
Branch: 2 branches
BranchTrueFalseTotal
defined $param->{'module'} ? : 1 2 3
defined $param->{'file'} ? : 1 1 2
53  
54 3 ▶ if ((defined $file) && (-r $file))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file and -r $file) 2 1 3
Condition66%2/3
defined $file and -r $file
!ll&&!rl&&r
102
MC/DC50%1/2
defined $file and -r $file
defined $file -r $file
Truth table66%2/3
A and B
A= defined $fileB= -r $file
ABresult
0X0
100
111
55 {
56 2 my $json_str = read_file($file);
57 2 my $conf = from_json($json_str);
58  
59 2 return ($conf);
60 }
61  
62 1 return (undef);
63 }
64  
65 1 1;
66  
67 =head1 AUTHOR
68  
69 Sebastien Thebert <contact@onetool.pm>
70  
71 =cut
↑ Summary OneTool.pm »