line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package BioSAILs::Utils::LoadConfigs; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
3059490
|
use 5.010; |
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
5
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
23
|
use namespace::autoclean; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
9
|
|
7
|
1
|
|
|
1
|
|
349
|
use MooseX::App::Role; |
|
1
|
|
|
|
|
1846
|
|
|
1
|
|
|
|
|
4
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
9008
|
use Config::Any; |
|
1
|
|
|
|
|
1332
|
|
|
1
|
|
|
|
|
32
|
|
10
|
1
|
|
|
1
|
|
408
|
use File::HomeDir; |
|
1
|
|
|
|
|
5298
|
|
|
1
|
|
|
|
|
73
|
|
11
|
1
|
|
|
1
|
|
9
|
use Cwd; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
12
|
1
|
|
|
1
|
|
404
|
use MooseX::Types::Path::Tiny qw/Path Paths AbsPaths AbsFile/; |
|
1
|
|
|
|
|
513995
|
|
|
1
|
|
|
|
|
14
|
|
13
|
1
|
|
|
1
|
|
3520
|
use Path::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
72
|
|
14
|
1
|
|
|
1
|
|
10
|
use Try::Tiny; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
60
|
|
15
|
1
|
|
|
1
|
|
476
|
use Hash::Merge qw( merge ); |
|
1
|
|
|
|
|
2444
|
|
|
1
|
|
|
|
|
1186
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
option 'no_configs' => ( |
18
|
|
|
|
|
|
|
is => 'rw', |
19
|
|
|
|
|
|
|
isa => 'Bool', |
20
|
|
|
|
|
|
|
default => 0, |
21
|
|
|
|
|
|
|
documentation => '--no_configs tells HPC::Runner not to load any configs', |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
option 'config' => ( |
25
|
|
|
|
|
|
|
isa => 'Str', |
26
|
|
|
|
|
|
|
is => 'rw', |
27
|
|
|
|
|
|
|
required => 0, |
28
|
|
|
|
|
|
|
documentation => 'Override the search paths and supply your own config.', |
29
|
|
|
|
|
|
|
isa => AbsFile, |
30
|
|
|
|
|
|
|
coerce => 1, |
31
|
|
|
|
|
|
|
predicate => 'has_config', |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
option 'config_base' => ( |
35
|
|
|
|
|
|
|
is => 'rw', |
36
|
|
|
|
|
|
|
isa => 'Str', |
37
|
|
|
|
|
|
|
default => '.config', |
38
|
|
|
|
|
|
|
documentation => 'Basename of config files', |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
option 'search' => ( |
42
|
|
|
|
|
|
|
traits => ['Bool'], |
43
|
|
|
|
|
|
|
is => 'rw', |
44
|
|
|
|
|
|
|
isa => 'Bool', |
45
|
|
|
|
|
|
|
default => 1, |
46
|
|
|
|
|
|
|
handles => { |
47
|
|
|
|
|
|
|
'no_search' => 'unset', |
48
|
|
|
|
|
|
|
}, |
49
|
|
|
|
|
|
|
documentation => |
50
|
|
|
|
|
|
|
'Search for config files in ~/.config.(ext) and in your current working directory.' |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
option 'search_path' => ( |
54
|
|
|
|
|
|
|
traits => ['Array'], |
55
|
|
|
|
|
|
|
is => 'rw', |
56
|
|
|
|
|
|
|
isa => 'ArrayRef[Str]', |
57
|
|
|
|
|
|
|
default => sub { [ File::HomeDir->my_home, getcwd() ] }, |
58
|
|
|
|
|
|
|
handles => { |
59
|
|
|
|
|
|
|
all_search_path => 'elements', |
60
|
|
|
|
|
|
|
append_search_path => 'push', |
61
|
|
|
|
|
|
|
prepend_search_path => 'unshift', |
62
|
|
|
|
|
|
|
map_search_path => 'map', |
63
|
|
|
|
|
|
|
has_search_path => 'count', |
64
|
|
|
|
|
|
|
}, |
65
|
|
|
|
|
|
|
documentation => |
66
|
|
|
|
|
|
|
'Enable a search path for configs. Default is the home dir and your cwd.' |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
has 'filter_keys' => ( |
70
|
|
|
|
|
|
|
is => 'rw', |
71
|
|
|
|
|
|
|
traits => ['Array'], |
72
|
|
|
|
|
|
|
is => 'rw', |
73
|
|
|
|
|
|
|
isa => 'ArrayRef[Str]', |
74
|
|
|
|
|
|
|
default => sub { [] }, |
75
|
|
|
|
|
|
|
handles => { |
76
|
|
|
|
|
|
|
all_filter_keys => 'elements', |
77
|
|
|
|
|
|
|
append_filter_keys => 'push', |
78
|
|
|
|
|
|
|
prepend_filter_keys => 'unshift', |
79
|
|
|
|
|
|
|
map_filter_keys => 'map', |
80
|
|
|
|
|
|
|
has_filter_keys => 'count', |
81
|
|
|
|
|
|
|
}, |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
has 'config_files' => ( |
85
|
|
|
|
|
|
|
traits => ['Array'], |
86
|
|
|
|
|
|
|
is => 'rw', |
87
|
|
|
|
|
|
|
isa => AbsPaths, |
88
|
|
|
|
|
|
|
coerce => 1, |
89
|
|
|
|
|
|
|
default => sub { [] }, |
90
|
|
|
|
|
|
|
handles => { |
91
|
|
|
|
|
|
|
all_config_files => 'elements', |
92
|
|
|
|
|
|
|
append_config_files => 'push', |
93
|
|
|
|
|
|
|
prepend_config_files => 'unshift', |
94
|
|
|
|
|
|
|
map_config_files => 'map', |
95
|
|
|
|
|
|
|
has_config_files => 'count', |
96
|
|
|
|
|
|
|
count_config_files => 'count', |
97
|
|
|
|
|
|
|
}, |
98
|
|
|
|
|
|
|
); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
has '_config_data' => ( |
101
|
|
|
|
|
|
|
is => 'rw', |
102
|
|
|
|
|
|
|
isa => 'ArrayRef', |
103
|
|
|
|
|
|
|
predicate => 'has_config_data', |
104
|
|
|
|
|
|
|
default => sub { [] }, |
105
|
|
|
|
|
|
|
); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
has '_merged_config_data' => ( |
108
|
|
|
|
|
|
|
is => 'rw', |
109
|
|
|
|
|
|
|
isa => 'HashRef', |
110
|
|
|
|
|
|
|
predicate => 'has_merged_config_data', |
111
|
|
|
|
|
|
|
default => sub { return {} }, |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
0
|
0
|
|
sub BUILD { } |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
before 'BUILD' => sub { |
117
|
|
|
|
|
|
|
my $self = shift; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
return if $self->no_configs; |
120
|
|
|
|
|
|
|
$self->decide_search_configs; |
121
|
|
|
|
|
|
|
}; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub decide_search_configs { |
124
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
125
|
|
|
|
|
|
|
|
126
|
0
|
0
|
|
|
|
|
if ( $self->has_config ) { |
|
|
0
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
$self->append_config_files( $self->config ); |
128
|
0
|
|
|
|
|
|
$self->load_configs; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
elsif ( $self->search ) { |
131
|
0
|
|
|
|
|
|
$self->search_configs; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub search_configs { |
136
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
137
|
0
|
|
|
|
|
|
my $extension = shift; |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
foreach my $extension ( Config::Any->extensions ) { |
140
|
0
|
|
|
|
|
|
foreach my $dir ( $self->all_search_path ) { |
141
|
0
|
|
|
|
|
|
my $dir = $dir . '/'; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
#We will check with and without extensions |
144
|
0
|
|
|
|
|
|
my $check_file; |
145
|
0
|
|
|
|
|
|
$check_file = File::Spec->catfile( $dir . $self->config_base ); |
146
|
0
|
0
|
|
|
|
|
$self->append_config_files($check_file) if -f $check_file; |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
$check_file = |
149
|
|
|
|
|
|
|
File::Spec->catfile( |
150
|
|
|
|
|
|
|
$dir . $self->config_base . '.' . $extension ); |
151
|
0
|
0
|
|
|
|
|
$self->append_config_files($check_file) if -f $check_file; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
$self->load_configs; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub load_configs { |
160
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
161
|
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
my $command_name = $self->{_original_class_name}; |
163
|
0
|
|
|
|
|
|
my $cfg = |
164
|
|
|
|
|
|
|
Config::Any->load_files( { files => $self->config_files, use_ext => 1 } ); |
165
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
$self->_config_data($cfg); |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
$self->apply_configs; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub apply_configs { |
172
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
173
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
my $command_name = $self->{_original_class_name}; |
175
|
0
|
|
|
|
|
|
for ( my $x = 0 ; $x < $self->count_config_files ; $x++ ) { |
176
|
0
|
|
|
|
|
|
my $c = $self->_config_data->[$x]->{ $self->config_files->[$x] }; |
177
|
0
|
|
|
|
|
|
my $old = $self->_merged_config_data; |
178
|
0
|
|
|
|
|
|
my $new = merge($c, $old); |
179
|
0
|
|
|
|
|
|
$self->_merged_config_data($new); |
180
|
|
|
|
|
|
|
|
181
|
0
|
|
|
|
|
|
my @keys = keys %{$c}; |
|
0
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
|
183
|
0
|
0
|
|
|
|
|
if ( !$self->has_filter_keys ) { |
184
|
0
|
|
|
|
|
|
my @filter_keys = grep { $_ ne 'global' } @keys; |
|
0
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
$self->filter_keys( \@filter_keys ); |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
#Global is always applied |
189
|
0
|
0
|
|
|
|
|
$self->apply_attributes( $c, 'global' ) if exists $c->{global}; |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
map { $self->apply_attributes( $c, $_ ) } $self->all_filter_keys; |
|
0
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub apply_attributes { |
197
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
198
|
0
|
|
|
|
|
|
my $conf = shift; |
199
|
0
|
|
|
|
|
|
my $attr = shift; |
200
|
|
|
|
|
|
|
|
201
|
0
|
0
|
|
|
|
|
return unless ref($conf) eq 'HASH'; |
202
|
0
|
0
|
|
|
|
|
return unless ref( $conf->{$attr} ) eq 'HASH'; |
203
|
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
|
while ( my ( $key, $value ) = each %{ $conf->{$attr} } ) { |
|
0
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
|
206
|
0
|
0
|
|
|
|
|
if ( $self->can($key) ) { |
207
|
|
|
|
|
|
|
try { |
208
|
0
|
|
|
0
|
|
|
$self->$key($value); |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
catch { |
211
|
0
|
|
|
0
|
|
|
warn 'You tried to assign ' . $key . ' to ' . $value . "\n"; |
212
|
0
|
|
|
|
|
|
}; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
1; |