| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 3 | ▶ | if ((defined $file) && (-r $file)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $file and -r $file
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
| |||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||