lib/BioX/Workflow/Command/run/Rules/Directives/Types/Config.pm

filter: Statementstmt 45.0% 18 / 40 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 55.5% 5 / 9 Podpod 100% 1 / 1 totaltotal 42.8% 24 / 56 CC 4 SCAR 20.3
CC
4
Cov
39%
process_directive_config
20.0
__ANON__
2.0
__ANON__
2.0
CRAP 7.6
« lib/BioX/Workflow/Command/run/Rules/Directives/Types/Roles/File.pm ↑ Summary lib/BioX/Workflow/Command/run/Rules/Directives/Types/List.pm »
1 package BioX::Workflow::Command::run::Rules::Directives::Types::Config;
2  
3 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 with 'BioX::Workflow::Command::run::Rules::Directives::Types::Roles::File';
7  
8 1 ▶use Config::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 0 ▶after 'BUILD' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
12 0 my $self = shift;
13  
14 0 $self->set_register_types(
15 'config',
16 {
17 builder => 'create_reg_attr',
18 lookup => [
19 '.*_json$', '.*_yaml$', '.*_yml$', '.*_jsn$',
20 ]
21 }
22 );
23  
24 0 $self->set_register_process_directives(
25 'config',
26 {
27 builder => 'process_directive_config',
28 lookup => [
29 '.*_json$', '.*_yaml$', '.*_yml$', '.*_jsn$',
30 ],
31 }
32 );
33 1 };
34  
35 =head3 process_directive_config
36  
37 ##TODO Think about adding in multiple files - supported by Config::Any
38  
39 This only takes the argument file
40 For now only one file per entry is supported
41  
42 =cut
43  
44 0 ▶sub process_directive_config {
Subroutine process_directive_config: not called CC=4 SCAR=30.0
Pod documented
45 0 my $self = shift;
46 0 my $k = shift;
47 0 my $v = shift;
48  
49 0 ▶ return unless ref($v);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $v 0 0 0
50  
51 0 my $file = $self->check_file_exists( $k, $v );
52 0 ▶ return unless $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 0 0 0
53  
54 0 my $cfg;
55 0 my $valid = 1;
56 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
57 0 $cfg = Config::Any->load_files( { files => [$file], use_ext => 1 } );
58 }
59 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
60 0 $self->app_log->warn(
61 "Unable to load the config with '. $k .' The following error was received.\n"
62 );
63 0 $self->app_log->warn("$_\n");
64 0 $valid = 0;
65 0 };
66  
67 0 ▶ if ( !$valid ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($valid) 0 0 0
68 0 $self->$k($v);
69 0 return;
70 }
71  
72 0 $cfg = $cfg->[0];
73 0 my $config = $cfg->{$file};
74 0 $self->$k($config);
75 }
76  
77 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
78  
79 1 1;
« lib/BioX/Workflow/Command/run/Rules/Directives/Types/Roles/File.pm ↑ Summary lib/BioX/Workflow/Command/run/Rules/Directives/Types/List.pm »