lib/Daje/Workflow/Config.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 47 CC 2 SCAR 11.5
CC
2
Cov
0%
param
6.0
load
2.0
BEGIN
2.0
CRAP 3.1
1 package Daje::Workflow::Config;
2 use v5.40;
3 use Mojo::Base -base;
4  
5 # NAME
6 # ====
7 #
8 # Daje::Workflow::Config - Loads the JSON based configs and put them in a hash
9 #
10 # SYNOPSIS
11 # ========
12 #
13 # use Daje::Workflow::Config;
14 #
15 # # Single file
16 # my $config = Daje::Workflow::Config->new(
17 # path => "path",
18 # )->load($filename);
19 #
20 # my $parameter = "key";
21 #
22 # my $value = $config->param($parameter);
23 #
24 # my $parameter = "key1.key2";
25 #
26 # my $value = $config->param($parameter);
27 #
28 # DESCRIPTION
29 # ===========
30 #
31 # Daje::Config is loading workflows from JSON files in a set folder
32 #
33 # LICENSE
34 # =======
35 #
36 # Copyright (C) janeskil1525.
37 #
38 # This library is free software; you can redistribute it and/or modify
39 # it under the same terms as Perl itself.
40 #
41 # AUTHOR
42 # ======
43 #
44 # janeskil1525 E<lt>janeskil1525@gmail.comE<gt>
45 #
46  
47 our $VERSION = "0.02";
48  
49 use Daje::Config;
50 use Mojo::File;
51  
52 has 'path' => "";
53 has 'config';
54 has 'error' => '';
55  
56 sub load($self, $filename) {
57  
58 try {
59 my $config = Daje::Config->new(
60 path => $self->path,
61 )->load($filename);
62 my $path = Mojo::File->new($self->path . $filename);
63 my $tag = substr($path->basename(), 0, index($path->basename(), '.json'));
64 $self->config($config->{$tag});
65 } catch($e) {
66 $self->error($e);
67 };
68  
69 return $self;
70 }
71  
72 sub param($self, $parameter) {
73 my $result = "";
74  
75 if (index($parameter,'.') == -1) {
76 try {
77 $result = $self->config->{$parameter};
78 }
79 catch ($e) {
80 $self->error($e);
81 };
82 } else {
83 try {
84 while (index($parameter,'.') > -1) {
85 my $key = substr($parameter, 0, index($parameter, '.'));
86 $result = $self->config->{$key};
87 $parameter = substr($parameter, rindex($parameter, '.') + 1);
88 }
89 $result = $result->{$parameter};
90 } catch($e) {
91 $self->error($e);
92 }
93 }
94  
95 return $result;
96 }
97  
98  
99 1;
100 __END__