Resolver/CLI.pm

filter: Statementstmt 47.4% 230 / 485 Branchbran 30.7% 64 / 208 Conditioncond 24.8% 40 / 161 MC/DCmcdc 12.7% 12 / 94 Subroutinesub 58.4% 31 / 53 Podpod 6.9% 2 / 29 totaltotal 36.8% 379 / 1030 CC 232 SCAR 39.1
CC
232
Cov
39%
process_manifest
134.3
process_manifest
134.3
write_output
132.0
CRAP 49.8
↑ Summary Resolver.pm »
1 package Config::Resolver::CLI;
2  
3 # general purpose script for merging secrets and configuration values
4 # to a template
5  
6 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 17 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 17 ▶use CLI::Simple::Constants qw(:booleans :chars :log-levels);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 17 ▶use Config::Resolver;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 17 ▶use Config::Resolver::Utils qw(is_hash is_array to_boolean slurp_file);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 17 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 17 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 17 ▶use File::Basename qw(basename);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 17 ▶use File::Temp qw(tempfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 17 ▶use Getopt::Long qw(:config no_ignore_case );
Subroutine BEGIN: called CC=1 SCAR=0.0
18 17 ▶use JSON -convert_blessed_universally;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 17 ▶use List::Util qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 17 ▶use Module::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 17 ▶use Query::Param;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 17 ▶use Scalar::Util qw(looks_like_number reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 17 ▶use YAML::Tiny qw(LoadFile Dump Load);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 17 __PACKAGE__->use_log4perl( level => 'warn' );
26  
27 17 ▶use parent qw(CLI::Simple);
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 17 ▶caller or __EXIT__->main;
Branch: 1 branch
BranchTrueFalseTotal
&CORE::GLOBAL::caller() or "__EXIT__"->main 17 0 17
30  
31 ########################################################################
32 17 our $VERSION = '1.0.12';
33 ########################################################################
34  
35 17 ▶use File::Basename; # <-- Make sure to 'use' this at the top of the file
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 ########################################################################
38 3 ▶sub process_manifest {
Subroutine process_manifest: called CC=22 SCAR=49.0
Pod undocumented
39 ########################################################################
40 0 ▶ my ($self) = @_;
Subroutine process_manifest: not called CC=22 SCAR=49.0
Pod undocumented
41  
42 0 my $logger = $self->get_logger;
43  
44 0 $logger->info('processing manifest file...');
45  
46 0 my $manifest_file = $self->get_manifest;
47  
48 0 ▶ croak "ERROR: no manifest file specified. Use -m or --manifest\n"
Branch: 2 branches
BranchTrueFalseTotal
unless $manifest_file 0 3 3
unless $manifest_file 0 0 0
49 if !$manifest_file;
50  
51 0 ▶ croak "ERROR: manifest file not found: $manifest_file\n"
Branch: 2 branches
BranchTrueFalseTotal
unless -e $manifest_file 0 3 3
unless -e $manifest_file 0 0 0
52 if !-e $manifest_file;
53  
54 0 my $manifest = $self->fetch_file($manifest_file);
55 0 ▶ croak "ERROR: manifest file must be a HASH\n"
Branch: 2 branches
BranchTrueFalseTotal
if ref $manifest ne "HASH" 0 3 3
if ref $manifest ne "HASH" 0 0 0
56 if ref $manifest ne 'HASH';
57  
58 0 ▶ my $globals = $manifest->{globals} || {};
Condition50%2/4
$manifest->{'globals'} || {}
l!l
21
$manifest->{'globals'} || {}
l!l
00
MC/DC100%1/1
$manifest->{'globals'} || {}
$manifest->{'globals'}
MC/DC0%0/1
$manifest->{'globals'} || {}
$manifest->{'globals'}
Truth table100%2/2
A
A= $manifest->{'globals'}
Aresult
11
00
Truth table0%0/2
A
A= $manifest->{'globals'}
Aresult
11
00
59 0 ▶ croak "ERROR: 'globals' section in manifest must be a HASH\n"
Branch: 2 branches
BranchTrueFalseTotal
if ref $globals ne "HASH" 0 3 3
if ref $globals ne "HASH" 0 0 0
60 if ref $globals ne 'HASH';
61  
62 0 my $jobs = $manifest->{jobs};
63 0 ▶ croak "ERROR: manifest file is missing required 'jobs' array\n"
Branch: 2 branches
BranchTrueFalseTotal
if not $jobs or ref $jobs ne "ARRAY" 0 3 3
if not $jobs or ref $jobs ne "ARRAY" 0 0 0
Condition16%1/6
not $jobs or ref $jobs ne "ARRAY"
l!l&&r!l&&!r
003
not $jobs or ref $jobs ne "ARRAY"
l!l&&r!l&&!r
000
MC/DC0%0/2
not $jobs or ref $jobs ne "ARRAY"
not $jobs ref $jobs ne "ARRAY"
MC/DC0%0/2
not $jobs or ref $jobs ne "ARRAY"
not $jobs ref $jobs ne "ARRAY"
Truth table33%1/3
not(A) or B
A= not $jobsB= ref $jobs ne "ARRAY"
ABresult
1X1
011
000
Truth table0%0/3
not(A) or B
A= not $jobsB= ref $jobs ne "ARRAY"
ABresult
1X1
011
000
64 if !$jobs || ref $jobs ne 'ARRAY';
65  
66 0 for my $job ( @{$jobs} ) {
67 # 1. Merge globals and job-specific configs
68 0 my $final_job = { %{$globals}, %{$job} };
69  
70 # 2. Extract final values
71 0 ▶ my $outfile = $final_job->{outfile} // q{};
Condition25%1/4
$final_job->{"outfile"} // ""
l!l
30
$final_job->{"outfile"} // ""
l!l
00
MC/DC0%0/1
$final_job->{"outfile"} // ""
$final_job->{"outfile"}
MC/DC0%0/1
$final_job->{"outfile"} // ""
$final_job->{"outfile"}
Truth table50%1/2
A
A= $final_job->{"outfile"}
Aresult
11
00
Truth table0%0/2
A
A= $final_job->{"outfile"}
Aresult
11
00
72 0 my $parameters = $final_job->{parameters};
73 0 ▶ my $template = $final_job->{template} // q{};
Condition50%2/4
$final_job->{"template"} // ""
l!l
21
$final_job->{"template"} // ""
l!l
00
MC/DC100%1/1
$final_job->{"template"} // ""
$final_job->{"template"}
MC/DC0%0/1
$final_job->{"template"} // ""
$final_job->{"template"}
Truth table100%2/2
A
A= $final_job->{"template"}
Aresult
11
00
Truth table0%0/2
A
A= $final_job->{"template"}
Aresult
11
00
74  
75 0 $logger->info( sprintf 'processing job: %s => %s', $template, $outfile );
76  
77 0 ▶ if ( !$template && $outfile && $final_job->{template_path} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $template and $outfile and $final_job->{"template_path"}) 1 2 3
if (not $template and $outfile and $final_job->{"template_path"}) 0 0 0
Condition33%4/12
not $template and $outfile and $final_job->{"template_path"}
!ll&&!rl&&r
201
not $template and $outfile
!ll&&!rl&&r
201
not $template and $outfile and $final_job->{"template_path"}
!ll&&!rl&&r
000
not $template and $outfile
!ll&&!rl&&r
000
MC/DC33%1/3
not $template and $outfile and $final_job->{"template_path"}
not $template $outfile $final_job->{"template_path"}
MC/DC0%0/3
not $template and $outfile and $final_job->{"template_path"}
not $template $outfile $final_job->{"template_path"}
Truth table50%2/4
not(A) and B and C
A= not $templateB= $outfileC= $final_job->{"template_path"}
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
not(A) and B and C
A= not $templateB= $outfileC= $final_job->{"template_path"}
ABCresult
0XX0
10X0
1100
1111
78 0 my $template_name = basename($outfile);
79 0 $template = sprintf '%s/%s.tpl', $final_job->{template_path}, $template_name;
80  
81 # Store the derived template path back in the hash
82 0 $final_job->{template} = $template;
83 }
84  
85 # 3. Validate the final, resolved job
86 0 ▶ if ( !$template || !$outfile || !$parameters ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($template and $outfile and $parameters) 0 3 3
unless ($template and $outfile and $parameters) 0 0 0
Condition16%2/12
$template and $outfile and $parameters
!ll&&!rl&&r
003
$template and $outfile
!ll&&!rl&&r
003
$template and $outfile and $parameters
!ll&&!rl&&r
000
$template and $outfile
!ll&&!rl&&r
000
MC/DC0%0/3
$template and $outfile and $parameters
$template $outfile $parameters
MC/DC0%0/3
$template and $outfile and $parameters
$template $outfile $parameters
Truth table25%1/4
A and B and C
A= $templateB= $outfileC= $parameters
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and B and C
A= $templateB= $outfileC= $parameters
ABCresult
0XX0
10X0
1100
1111
87 0 croak sprintf "ERROR: job is missing required keys (template, outfile, parameters)\n" . '(Job data: %s )',
88 Dumper($final_job);
89 }
90  
91 # 4. Check that files exist *before* trying to run
92 0 ▶ croak "ERROR: parameter file not found: $parameters\n" if !-e $parameters;
Branch: 2 branches
BranchTrueFalseTotal
unless -e $parameters 0 3 3
unless -e $parameters 0 0 0
93 0 ▶ croak "ERROR: template file not found: $template\n" if !-e $template;
Branch: 2 branches
BranchTrueFalseTotal
unless -e $template 0 3 3
unless -e $template 0 0 0
94  
95 # 5. Set object state and run the resolver
96 0 $self->set_parameter_file($parameters);
97 0 $self->set_template($template);
98 0 $self->set_outfile($outfile);
99 0 ▶ $self->set_umask( $final_job->{umask} ) if $final_job->{umask};
Branch: 2 branches
BranchTrueFalseTotal
if $final_job->{"umask"} 1 2 3
if $final_job->{"umask"} 0 0 0
100 $logger->info( sprintf 'resolving %s using %s => %s (umask %o)',
101 0 ▶ $template, $parameters, $outfile, $final_job->{umask} // 0 );
Condition50%2/4
$final_job->{"umask"} // 0
l!l
12
$final_job->{"umask"} // 0
l!l
00
MC/DC100%1/1
$final_job->{"umask"} // 0
$final_job->{"umask"}
MC/DC0%0/1
$final_job->{"umask"} // 0
$final_job->{"umask"}
Truth table100%2/2
A
A= $final_job->{"umask"}
Aresult
11
00
Truth table0%0/2
A
A= $final_job->{"umask"}
Aresult
11
00
102  
103 0 $self->fetch_parameters();
104 0 $self->resolve();
105  
106 0 ▶ $logger->info( sprintf '%s %s rendered', $outfile, -e $outfile ? 'sucessfully' : '*was not*' );
Branch: 2 branches
BranchTrueFalseTotal
-e $outfile ? : 0 3 3
-e $outfile ? : 0 0 0
107 }
108  
109 0 return $SUCCESS;
110 }
111  
112 ########################################################################
113 0 ▶sub build_manifest {
Subroutine build_manifest: not called CC=5 SCAR=34.0
Pod undocumented
114 ########################################################################
115 0 ▶ my ($self) = @_;
Subroutine build_manifest: not called CC=5 SCAR=34.0
Pod undocumented
116  
117 0 my $output_dir = $self->get_output_dir;
118 0 my $template_dir = $self->get_template;
119  
120 0 ▶ opendir my $dh, $template_dir
Branch: 2 branches
BranchTrueFalseTotal
opendir my $dh, $template_dir or croak("Can't opendir ${template_dir}: $Config::Resolver::CLI::OS_ERROR") 0 0 0
opendir my $dh, $template_dir or croak("Can't opendir ${template_dir}: $Config::Resolver::CLI::OS_ERROR") 0 0 0
121 or croak "Can't opendir $template_dir: $OS_ERROR";
122  
123 0 my @templates = map {"$template_dir/$_"} grep {/[.]tpl$/xsm} readdir $dh;
124 0 closedir $dh;
125  
126 0 ▶ croak "ERROR: no templates found, templates should have an .tpl extension\n"
Branch: 2 branches
BranchTrueFalseTotal
unless @templates 0 0 0
unless @templates 0 0 0
127 if !@templates;
128  
129 0 my ( $fh, $manifest_file ) = tempfile( 'manifest-XXXXX', SUFFIX => '.yml', UNLINK => $TRUE );
130  
131 0 my $parameter_file = $self->get_parameter_file;
132 0 ▶ my $umask = $self->get_umask // umask;
Condition0%0/6
$self->get_umask // umask
l!l&&r!l&&!r
000
$self->get_umask // umask
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_umask // umask
$self->get_umask umask
MC/DC0%0/2
$self->get_umask // umask
$self->get_umask umask
Truth table0%0/3
A // B
A= $self->get_umaskB= umask
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $self->get_umaskB= umask
ABresult
1X1
011
000
133  
134 0 print {$fh} <<"END_OF_MANIFEST";
135 ---
136 globals:
137 parameters: $parameter_file
138 umask: $umask
139  
140 jobs:
141 END_OF_MANIFEST
142  
143 0 foreach my $template (@templates) {
144 0 print {$fh} sprintf " - template: %s\n", $template;
145 0 print {$fh} sprintf " outfile: %s/%s\n\n", $output_dir, basename( $template, '.tpl' );
146 }
147  
148 0 close $fh;
149  
150 0 $self->set_manifest($manifest_file);
151  
152 0 return @templates;
153 }
154  
155 ########################################################################
156 0 ▶sub cmd_version {
Subroutine cmd_version: not called CC=1 SCAR=6.9
Pod undocumented
157 ########################################################################
158 0 ▶ my ($self) = @_;
Subroutine cmd_version: not called CC=1 SCAR=6.9
Pod undocumented
159  
160 0 print {*STDOUT} sprintf "%s v%s\n", basename($PROGRAM_NAME), $VERSION;
161  
162 0 return $SUCCESS;
163 }
164  
165 ########################################################################
166 0 ▶sub cmd_resolve {
Subroutine cmd_resolve: not called CC=8 SCAR=42.8
Pod undocumented
167 ########################################################################
168 0 ▶ my ($self) = @_;
Subroutine cmd_resolve: not called CC=8 SCAR=42.8
Pod undocumented
169  
170 0 ▶ return $self->process_manifest
Branch: 2 branches
BranchTrueFalseTotal
if $self->get_manifest 0 0 0
if $self->get_manifest 0 0 0
171 if $self->get_manifest;
172  
173 0 ▶ if ( $self->get_template && -d $self->get_template ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->get_template and -d $self->get_template) 0 0 0
if ($self->get_template and -d $self->get_template) 0 0 0
Condition0%0/6
$self->get_template and -d $self->get_template
!ll&&!rl&&r
000
$self->get_template and -d $self->get_template
!ll&&!rl&&r
000
MC/DC0%0/2
$self->get_template and -d $self->get_template
$self->get_template -d $self->get_template
MC/DC0%0/2
$self->get_template and -d $self->get_template
$self->get_template -d $self->get_template
Truth table0%0/3
A and B
A= $self->get_templateB= -d $self->get_template
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $self->get_templateB= -d $self->get_template
ABresult
0X0
100
111
174 0 my $parameter_file = $self->get_parameter_file;
175  
176 0 ▶ croak "ERROR: --parameter-file is missing or invalid\n"
Branch: 2 branches
BranchTrueFalseTotal
unless $parameter_file and -e $parameter_file 0 0 0
unless $parameter_file and -e $parameter_file 0 0 0
Condition0%0/6
$parameter_file and -e $parameter_file
!ll&&!rl&&r
000
$parameter_file and -e $parameter_file
!ll&&!rl&&r
000
MC/DC0%0/2
$parameter_file and -e $parameter_file
$parameter_file -e $parameter_file
MC/DC0%0/2
$parameter_file and -e $parameter_file
$parameter_file -e $parameter_file
Truth table0%0/3
A and B
A= $parameter_fileB= -e $parameter_file
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $parameter_fileB= -e $parameter_file
ABresult
0X0
100
111
177 if !$parameter_file || !-e $parameter_file;
178  
179 0 my $output_dir = $self->get_output_dir;
180 0 ▶ croak
Branch: 2 branches
BranchTrueFalseTotal
unless $output_dir and -d $output_dir 0 0 0
unless $output_dir and -d $output_dir 0 0 0
Condition0%0/6
$output_dir and -d $output_dir
!ll&&!rl&&r
000
$output_dir and -d $output_dir
!ll&&!rl&&r
000
MC/DC0%0/2
$output_dir and -d $output_dir
$output_dir -d $output_dir
MC/DC0%0/2
$output_dir and -d $output_dir
$output_dir -d $output_dir
Truth table0%0/3
A and B
A= $output_dirB= -d $output_dir
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $output_dirB= -d $output_dir
ABresult
0X0
100
111
181 "ERROR: --output-dir is missing or invalid. You must specify an output directory when you specify a template directory\n"
182 if !$output_dir || !-d $output_dir;
183  
184 0 $self->build_manifest();
185  
186 0 return $self->cmd_resolve();
187 }
188  
189 0 $self->resolve;
190  
191 0 return $SUCCESS;
192 }
193  
194 ########################################################################
195 0 ▶sub fetch_template {
Subroutine fetch_template: not called CC=3 SCAR=24.8
Pod undocumented
196 ########################################################################
197 0 ▶ my ($self) = @_;
Subroutine fetch_template: not called CC=3 SCAR=24.8
Pod undocumented
198  
199 # this will read from STDIN if there is content there
200 0 my $content = $self->fetch_file;
201  
202 0 ▶ if ( !$content && $self->get_template_file ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $content and $self->get_template_file) 0 0 0
if (not $content and $self->get_template_file) 0 0 0
Condition0%0/6
not $content and $self->get_template_file
!ll&&!rl&&r
000
not $content and $self->get_template_file
!ll&&!rl&&r
000
MC/DC0%0/2
not $content and $self->get_template_file
not $content $self->get_template_file
MC/DC0%0/2
not $content and $self->get_template_file
not $content $self->get_template_file
Truth table0%0/3
not(A) and B
A= not $contentB= $self->get_template_file
ABresult
0X0
100
111
Truth table0%0/3
not(A) and B
A= not $contentB= $self->get_template_file
ABresult
0X0
100
111
203 0 $content = $self->fetch_file( $self->get_template_file );
204 }
205  
206 0 $self->set_template($content);
207  
208 0 return;
209 }
210  
211 ########################################################################
212 2 ▶sub resolve {
Subroutine resolve: called CC=4 SCAR=19.6
Pod undocumented
213 ########################################################################
214 0 ▶ my ($self) = @_;
Subroutine resolve: not called CC=4 SCAR=19.6
Pod undocumented
215  
216 0 my $resolver = $self->get_resolver;
217  
218 0 my $parameters = $self->get_parameters_hash;
219  
220 0 ▶ croak "ERROR: no parameters available for merging\n"
Branch: 2 branches
BranchTrueFalseTotal
unless $parameters 0 2 2
unless $parameters 0 0 0
221 if !$parameters;
222  
223 0 my $output = $resolver->resolve($parameters);
224  
225 0 ▶ if ( my $template = $self->get_template ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $template = $self->get_template) 1 1 2
if (my $template = $self->get_template) 0 0 0
226 0 my $template_obj = $self->fetch_file($template);
227  
228 0 ▶ if ( !ref $template_obj ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $template_obj) { } 1 0 1
if (not ref $template_obj) { } 0 0 0
229 0 open my $fh, '<', \$template_obj;
230 0 $output = $self->resolve_stream( $fh, $output );
231 0 close $fh;
232 }
233 else {
234 0 $output = $resolver->resolve( $template_obj, $output );
235 }
236 }
237  
238 0 return $self->write_output($output);
239 }
240  
241 ########################################################################
242 2 ▶sub cmd_dump {
Subroutine cmd_dump: called CC=6 SCAR=28.1
Pod undocumented
243 ########################################################################
244 0 ▶ my ($self) = @_;
Subroutine cmd_dump: not called CC=6 SCAR=28.1
Pod undocumented
245  
246 0 my ($file) = $self->get_args;
247  
248 0 ▶ if ( !$file && !$self->get_parameters_hash ) {
Branch: 4 branches
BranchTrueFalseTotal
if (not $file || $self->get_parameters_hash) { } 0 2 2
elsif (not $self->get_parameters_hash || -e $file) { } 0 2 2
if (not $file || $self->get_parameters_hash) { } 0 0 0
elsif (not $self->get_parameters_hash || -e $file) { } 0 0 0
Condition16%1/6
$file || $self->get_parameters_hash
l!l&&r!l&&!r
200
$file || $self->get_parameters_hash
l!l&&r!l&&!r
000
MC/DC0%0/2
$file || $self->get_parameters_hash
$file $self->get_parameters_hash
MC/DC0%0/2
$file || $self->get_parameters_hash
$file $self->get_parameters_hash
Truth table33%1/3
A || B
A= $fileB= $self->get_parameters_hash
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $fileB= $self->get_parameters_hash
ABresult
1X1
011
000
249 0 croak "ERROR: no file specified for dump, use --parameter-file or dump filename\n";
250 }
251 ▶ elsif ( !$self->get_parameters_hash && !-e $file ) {
Condition16%1/6
$self->get_parameters_hash || -e $file
l!l&&r!l&&!r
200
$self->get_parameters_hash || -e $file
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_parameters_hash || -e $file
$self->get_parameters_hash -e $file
MC/DC0%0/2
$self->get_parameters_hash || -e $file
$self->get_parameters_hash -e $file
Truth table33%1/3
A || B
A= $self->get_parameters_hashB= -e $file
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $self->get_parameters_hashB= -e $file
ABresult
1X1
011
000
252 0 croak "ERROR: no such file - $file\n";
253 }
254 else {
255 0 $self->set_parameter_file($file);
256 0 $self->fetch_parameters();
257 }
258  
259 0 my $object = $self->get_parameters_hash;
260  
261 0 ▶ if ( my $key = $self->get_key ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $key = $self->get_key) { } 1 1 2
if (my $key = $self->get_key) { } 0 0 0
262 0 $self->write_output( $object->{$key} );
263 }
264 else {
265 0 $self->write_output($object);
266 }
267  
268 0 return $SUCCESS;
269 }
270  
271 # converts value to JSON string, undef to <undefined> or just returns value
272 ########################################################################
273 8 ▶sub format_value {
Subroutine format_value: called CC=8 SCAR=27.7
Pod undocumented
274 ########################################################################
275 0 ▶ my ( $self, $val, $key ) = @_;
Subroutine format_value: not called CC=8 SCAR=27.7
Pod undocumented
276  
277 0 ▶ if ( ref $val && $key ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $val and $key) 4 4 8
if (ref $val and $key) 0 0 0
Condition50%3/6
ref $val and $key
!ll&&!rl&&r
224
ref $val and $key
!ll&&!rl&&r
000
MC/DC100%2/2
ref $val and $key
ref $val $key
MC/DC0%0/2
ref $val and $key
ref $val $key
Truth table100%3/3
A and B
A= ref $valB= $key
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $valB= $key
ABresult
0X0
100
111
278 0 $val = $val->{$key};
279  
280 0 ▶ die "$key not found\n"
Branch: 2 branches
BranchTrueFalseTotal
if not defined $val and $self->get_warning_level eq "error" 1 3 4
if not defined $val and $self->get_warning_level eq "error" 0 0 0
Condition50%3/6
not defined $val and $self->get_warning_level eq "error"
!ll&&!rl&&r
211
not defined $val and $self->get_warning_level eq "error"
!ll&&!rl&&r
000
MC/DC100%2/2
not defined $val and $self->get_warning_level eq "error"
not defined $val $self->get_warning_level eq "error"
MC/DC0%0/2
not defined $val and $self->get_warning_level eq "error"
not defined $val $self->get_warning_level eq "error"
Truth table100%3/3
not(A) and B
A= not defined $valB= $self->get_warning_level eq "error"
ABresult
0X0
100
111
Truth table0%0/3
not(A) and B
A= not defined $valB= $self->get_warning_level eq "error"
ABresult
0X0
100
111
281 if !defined $val && $self->get_warning_level eq 'error';
282 }
283  
284 0 ▶ return '<undefined>'
Branch: 2 branches
BranchTrueFalseTotal
unless defined $val 2 5 7
unless defined $val 0 0 0
285 if !defined $val;
286  
287 0 ▶ return $val
Branch: 2 branches
BranchTrueFalseTotal
unless ref $val 2 3 5
unless ref $val 0 0 0
288 if !ref $val;
289  
290 0 ▶ return to_json(
Branch: 2 branches
BranchTrueFalseTotal
$self->get_pretty ? : 1 2 3
$self->get_pretty ? : 0 0 0
291 $val,
292 { allow_blessed => $TRUE,
293 convert_blessed => $TRUE,
294 pretty => $self->get_pretty ? $TRUE : $FALSE,
295 }
296 );
297 }
298  
299 ########################################################################
300 7 ▶sub fetch_parameters {
Subroutine fetch_parameters: called CC=4 SCAR=18.7
Pod undocumented
301 ########################################################################
302 0 ▶ my ($self) = @_;
Subroutine fetch_parameters: not called CC=4 SCAR=18.7
Pod undocumented
303  
304 0 ▶ if ( my $file = $self->get_parameter_file ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $file = $self->get_parameter_file) 6 1 7
if (my $file = $self->get_parameter_file) 0 0 0
305 0 ▶ my $parameters = $self->fetch_file($file) // {};
Condition25%1/4
$self->fetch_file($file) // {}
l!l
60
$self->fetch_file($file) // {}
l!l
00
MC/DC0%0/1
$self->fetch_file($file) // {}
$self->fetch_file($file)
MC/DC0%0/1
$self->fetch_file($file) // {}
$self->fetch_file($file)
Truth table50%1/2
A
A= $self->fetch_file($file)
Aresult
11
00
Truth table0%0/2
A
A= $self->fetch_file($file)
Aresult
11
00
306  
307 0 ▶ my $new_hash = { %{ $self->get_parameters_hash // {} }, %{$parameters} };
Condition50%2/4
$self->get_parameters_hash // {}
l!l
33
$self->get_parameters_hash // {}
l!l
00
MC/DC100%1/1
$self->get_parameters_hash // {}
$self->get_parameters_hash
MC/DC0%0/1
$self->get_parameters_hash // {}
$self->get_parameters_hash
Truth table100%2/2
A
A= $self->get_parameters_hash
Aresult
11
00
Truth table0%0/2
A
A= $self->get_parameters_hash
Aresult
11
00
308 0 $self->set_parameters_hash($new_hash);
309 }
310  
311 0 return $self->get_parameters_hash;
312 }
313  
314 ########################################################################
315 4 ▶sub to_object {
Subroutine to_object: called CC=5 SCAR=21.5
Pod undocumented
316 ########################################################################
317 0 ▶ my ($content) = @_;
Subroutine to_object: not called CC=5 SCAR=21.5
Pod undocumented
318  
319 0 ▶ croak "ERROR: no content\n"
Branch: 2 branches
BranchTrueFalseTotal
unless $content 0 4 4
unless $content 0 0 0
320 if !$content;
321  
322 0 ▶ local $SIG{__WARN__} = sub { };
Subroutine __ANON__: not called CC=1 SCAR=1.2
323  
324 0 my $obj = eval { from_json($content); };
325  
326 0 ▶ return $obj
Branch: 2 branches
BranchTrueFalseTotal
if $obj 1 3 4
if $obj 0 0 0
327 if $obj;
328  
329 0 $obj = eval { return Load($content) };
330  
331 0 ▶ return $obj
Branch: 2 branches
BranchTrueFalseTotal
if $obj 1 2 3
if $obj 0 0 0
332 if $obj;
333  
334 0 $obj = eval { from_ini_file($content); };
335  
336 0 ▶ return $obj
Branch: 2 branches
BranchTrueFalseTotal
if $obj 1 1 2
if $obj 0 0 0
337 if $obj;
338  
339 0 return;
340 }
341  
342 ########################################################################
343 7 ▶sub from_ini_file {
Subroutine from_ini_file: called CC=2 SCAR=6.9
Pod undocumented
344 ########################################################################
345 7 my ($content) = @_;
346  
347 7 require Config::INI::Tiny;
348  
349 7 my $config = Config::INI::Tiny->new->to_hash($content);
350 6 my $globals = delete $config->{q{}};
351 6 ▶ $globals //= {};
Condition100%2/2
$globals //= {}
l!l
33
MC/DC100%1/1
$globals //= {}
$globals
Truth table100%2/2
A
A= $globals
Aresult
11
00
352  
353 6 return { %{$globals}, %{$config} };
354 }
355  
356 ########################################################################
357 12 ▶sub fetch_file {
Subroutine fetch_file: called CC=11 SCAR=31.8
Pod undocumented
358 ########################################################################
359 12 my ( $self, $file ) = @_;
360  
361 12 ▶ if ( $file eq q{-} || ( !$file && !-t STDIN ) ) { ## no critic (ProhibitInteractiveTest)
Branch: 1 branch
BranchTrueFalseTotal
if ($file eq "-" or not $file || -t STDIN) 0 12 12
Condition33%2/6
$file eq "-" or not $file || -t STDIN
l!l&&r!l&&!r
0012
$file || -t STDIN
l!l&&r!l&&!r
1200
MC/DC0%0/3
$file eq "-" or not $file || -t STDIN
$file eq "-" $file -t STDIN
Truth table25%1/4
A or not(B || C)
A= $file eq "-"B= $fileC= -t STDIN
ABCresult
1XX1
0001
01X0
0010
362  
363 0 ▶ return if STDIN->eof();
Branch: 1 branch
BranchTrueFalseTotal
if "STDIN"->eof 0 0 0
364  
365 0 local $RS = undef;
366 0 my $content = <>;
367  
368 0 my $obj = eval { return to_object($content); };
369  
370 0 ▶ return $obj // $content;
Condition0%0/3
$obj // $content
l!l&&r!l&&!r
000
MC/DC0%0/2
$obj // $content
$obj $content
Truth table0%0/3
A // B
A= $objB= $content
ABresult
1X1
011
000
371 }
372  
373 12 my $obj = eval {
374  
375 12 ▶ return from_ini_file( slurp_file $file )
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /[.]config-resolverrc$/msx 2 10 12
376 if $file =~ /[.]config-resolverrc$/xsm;
377  
378 10 ▶ return LoadFile($file)
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /[.]ya?ml$/msx 4 6 10
379 if $file =~ /[.]ya?ml$/xsm;
380  
381 6 my $content = slurp_file($file);
382  
383 6 ▶ return from_json($content)
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /[.]json$/msx 5 1 6
384 if $file =~ /[.]json$/xsm;
385  
386 1 return $content;
387 };
388  
389 12 ▶ croak "ERROR: could not fetch object from $file\n$EVAL_ERROR"
Branch: 1 branch
BranchTrueFalseTotal
if not $obj or $Config::Resolver::CLI::EVAL_ERROR 0 12 12
Condition33%1/3
not $obj or $Config::Resolver::CLI::EVAL_ERROR
l!l&&r!l&&!r
0012
MC/DC0%0/2
not $obj or $Config::Resolver::CLI::EVAL_ERROR
not $obj $Config::Resolver::CLI::EVAL_ERROR
Truth table33%1/3
not(A) or B
A= not $objB= $Config::Resolver::CLI::EVAL_ERROR
ABresult
1X1
011
000
390 if !$obj || $EVAL_ERROR;
391  
392 12 return $obj;
393 }
394  
395 ########################################################################
396 3 ▶sub fetch_query_params {
Subroutine fetch_query_params: called CC=4 SCAR=13.9
Pod undocumented
397 ########################################################################
398 3 my ($self) = @_;
399  
400 3 ▶ my $query_string = $ENV{QUERY_STRING} // $self->get_parameters;
Condition66%2/3
$ENV{"QUERY_STRING"} // $self->get_parameters
l!l&&r!l&&!r
120
MC/DC0%0/2
$ENV{"QUERY_STRING"} // $self->get_parameters
$ENV{"QUERY_STRING"} $self->get_parameters
Truth table66%2/3
A // B
A= $ENV{"QUERY_STRING"}B= $self->get_parameters
ABresult
1X1
011
000
401  
402 return
403 3 ▶ if !$query_string;
Branch: 1 branch
BranchTrueFalseTotal
unless $query_string 0 3 3
404  
405 3 my $qparams = Query::Param->new($query_string);
406  
407 3 ▶ my $new_hash = { %{ $self->get_parameters_hash // {} }, %{ $qparams->params } };
Condition100%2/2
$self->get_parameters_hash // {}
l!l
12
MC/DC100%1/1
$self->get_parameters_hash // {}
$self->get_parameters_hash
Truth table100%2/2
A
A= $self->get_parameters_hash
Aresult
11
00
408 3 $self->set_parameters_hash($new_hash);
409  
410 3 return $self->get_parameters_hash;
411 }
412  
413 ########################################################################
414 1 ▶sub resolve_stream {
Subroutine resolve_stream: called CC=5 SCAR=16.3
Pod undocumented
415 ########################################################################
416 1 my ( $self, $fh, $parameters ) = @_;
417  
418 1 my $resolver = $self->get_resolver;
419  
420 1 my $output = $EMPTY;
421  
422 1 ▶ return $output
Branch: 1 branch
BranchTrueFalseTotal
if not $fh or $fh->eof 0 1 1
Condition33%1/3
not $fh or $fh->eof
l!l&&r!l&&!r
001
MC/DC0%0/2
not $fh or $fh->eof
not $fh $fh->eof
Truth table33%1/3
not(A) or B
A= not $fhB= $fh->eof
ABresult
1X1
011
000
423 if !$fh || $fh->eof();
424  
425 1 ▶ while ( my $line = <$fh> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 3 1 4
426 3 ▶ if ( $line =~ /[$][{](.*)[}]/xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /[$][{](.*)[}]/msx) 1 2 3
427 1 my $ref = $resolver->resolve( { value => $line }, $parameters );
428 1 $output .= $ref->{value};
429 1 next;
430 }
431  
432 2 $output .= $line;
433 }
434  
435 1 return $output;
436 }
437  
438 ########################################################################
439 0 ▶sub choose(&) { ## no critic
Subroutine choose: not called CC=1 SCAR=6.9
Pod undocumented
440 ########################################################################
441 0 return $_[0]->();
442 }
443  
444 ########################################################################
445 0 ▶sub write_output {
Subroutine write_output: not called CC=11 SCAR=48.8
Pod undocumented
446 ########################################################################
447 0 my ( $self, $obj ) = @_;
448  
449 0 my $outfile = $self->get_outfile;
450  
451 0 ▶ my $fh = choose {
Subroutine __ANON__: not called CC=4 SCAR=30.0
452 0 ▶ return *STDOUT
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get_outfile 0 0 0
453 if !$self->get_outfile;
454  
455 0 ▶ if ( $self->get_umask ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_umask) 0 0 0
456 0 umask $self->get_umask;
457 }
458  
459 0 ▶ open my $fh, '>', $outfile
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $outfile or croak("ERROR: could not open $outfile for writing\n$Config::Resolver::CLI::OS_ERROR\n") 0 0 0
460 or croak "ERROR: could not open $outfile for writing\n$OS_ERROR\n";
461  
462 0 return $fh;
463 0 };
464  
465 0 ▶ if ( ref $obj ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $obj) { } 0 0 0
466 0 ▶ my $format = $self->get_format // 'json';
Condition0%0/2
$self->get_format // "json"
l!l
00
MC/DC0%0/1
$self->get_format // "json"
$self->get_format
Truth table0%0/2
A
A= $self->get_format
Aresult
11
00
467  
468 0 ▶ if ( $format eq 'json' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($format eq 'json') { } 0 0 0
elsif ($format =~ /^ya?ml$/msx) { } 0 0 0
elsif ($format eq 'csv' and builtin::reftype($obj) eq 'HASH') { } 0 0 0
469 0 ▶ print {$fh} to_json(
Branch: 1 branch
BranchTrueFalseTotal
$self->get_pretty ? : 0 0 0
470 $obj,
471 { allow_blessed => $TRUE,
472 convert_blessed => $TRUE,
473 pretty => $self->get_pretty ? $TRUE : $FALSE,
474 },
475 );
476 }
477 elsif ( $format =~ /^ya?ml$/xsm ) {
478 0 print {$fh} Dump($obj);
479 }
480 ▶ elsif ( $format eq 'csv' && reftype($obj) eq 'HASH' ) {
Condition0%0/3
$format eq "csv" and builtin::reftype($obj) eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$format eq "csv" and builtin::reftype($obj) eq "HASH"
$format eq "csv" builtin::reftype($obj) eq "HASH"
Truth table0%0/3
A and B
A= $format eq "csv"B= builtin::reftype($obj) eq "HASH"
ABresult
0X0
100
111
481 0 ▶ my $sep_char = $self->get_separator // q{ = };
Condition0%0/2
$self->get_separator // " = "
l!l
00
MC/DC0%0/1
$self->get_separator // " = "
$self->get_separator
Truth table0%0/2
A
A= $self->get_separator
Aresult
11
00
482  
483 0 foreach ( keys %{$obj} ) {
484 0 ▶ next if ref $obj->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if ref $obj->{$_} 0 0 0
485 0 print {$fh} sprintf "%s%s%s\n", $_, $sep_char, $obj->{$_};
486 }
487 }
488 else {
489 0 croak "ERROR: unknown format %s\n", $format;
490 }
491 }
492 else {
493 0 print {$fh} $obj;
494 }
495  
496 0 close $fh;
497  
498 0 return;
499 }
500  
501 ########################################################################
502 5 ▶sub _build_plugin_config {
Subroutine _build_plugin_config: called CC=15 SCAR=27.3
503 ########################################################################
504 5 my ($self) = @_;
505  
506 # Layer 1: Load defaults from RC file
507 5 my $rc_file = $ENV{HOME} . '/.config-resolverrc';
508  
509 5 ▶ my $rc_config = -e $rc_file ? $self->fetch_file($rc_file) : {};
Branch: 1 branch
BranchTrueFalseTotal
-e $rc_file ? : 2 3 5
510 5 my %plugin_configs;
511  
512 5 foreach my $section ( keys %{$rc_config} ) {
513 2 ▶ if ( $section =~ /^plugin\s(.*)$/xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($section =~ /^plugin\s(.*)$/msx) 2 0 2
514 2 ▶ next if $rc_config->{$section}->{enabled} && $rc_config->{$section}->{enabled} eq 'false';
Branch: 1 branch
BranchTrueFalseTotal
if $rc_config->{$section}{"enabled"} and $rc_config->{$section}{"enabled"} eq "false" 0 2 2
Condition33%1/3
$rc_config->{$section}{"enabled"} and $rc_config->{$section}{"enabled"} eq "false"
!ll&&!rl&&r
200
MC/DC0%0/2
$rc_config->{$section}{"enabled"} and $rc_config->{$section}{"enabled"} eq "false"
$rc_config->{$section}{"enabled"} $rc_config->{$section}{"enabled"} eq "false"
Truth table33%1/3
A and B
A= $rc_config->{$section}{"enabled"}B= $rc_config->{$section}{"enabled"} eq "false"
ABresult
0X0
100
111
515 # default to true
516 2 $plugin_configs{$1} = $rc_config->{$section};
517 }
518 }
519  
520 # Layer 2: Parse CLI arguments
521 5 my $cli_config = {};
522 5 ▶ my $plugin_args = $self->get_plugin // [];
Condition50%1/2
$self->get_plugin // []
l!l
50
MC/DC0%0/1
$self->get_plugin // []
$self->get_plugin
Truth table50%1/2
A
A= $self->get_plugin
Aresult
11
00
523  
524 5 for my $arg ( @{$plugin_args} ) {
525 7 my ( $plugin_name, $key_value_pair ) = split /:/xsm, $arg, 2;
526 7 ▶ if ( !$key_value_pair ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($key_value_pair) 1 6 7
527 1 warn "WARNING: Ignoring malformed --plugin argument: $arg\n";
528 1 next;
529 }
530  
531 6 my ( $key, $value ) = split /=/xsm, $key_value_pair, 2;
532 6 ▶ if ( !defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 1 5 6
533 1 warn "WARNING: Ignoring malformed --plugin argument: $arg\n";
534 1 next;
535 }
536 5 $cli_config->{$plugin_name}{$key} = $value;
537 }
538  
539 # add auto plugins
540 5 ▶ my @plugins = split /\s*,\s*/xsm, $self->get_plugins // $EMPTY;
Condition33%1/3
$self->get_plugins // $Config::Resolver::CLI::EMPTY
l!l&&r!l&&!r
050
MC/DC0%0/2
$self->get_plugins // $Config::Resolver::CLI::EMPTY
$self->get_plugins $Config::Resolver::CLI::EMPTY
Truth table33%1/3
A // B
A= $self->get_pluginsB= $Config::Resolver::CLI::EMPTY
ABresult
1X1
011
000
541  
542 5 $self->set_plugins( join q{,}, @plugins, keys %plugin_configs );
543  
544 5 foreach my $plugin_name ( split /\s*,\s*/xsm, $self->get_plugins ) {
545 2 my $class = 'Config::Resolver::Plugin::' . $plugin_name;
546 2 load $class;
547  
548 2 my $protocol;
549  
550 2 my $stash_name = $class . q{::}; # e.g., 'Config::Resolver::Plugin::SSM::'
551  
552 {
553 17 ▶ no strict 'refs'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
554  
555 2 $protocol = ${ $stash_name . 'PROTOCOL' };
556  
557 2 ▶ croak "Plugin $class must define a package variable '\$PROTOCOL'."
Branch: 1 branch
BranchTrueFalseTotal
unless $protocol 0 2 2
558 if !$protocol;
559 }
560  
561 2 $plugin_configs{$protocol} = delete $plugin_configs{$plugin_name};
562 }
563  
564 # Layer 3: Deeply merge them (CLI wins)
565 5 my $final_plugin_config = \%plugin_configs;
566  
567 5 foreach my $plugin_name ( keys %{$cli_config} ) {
568 4 ▶ $final_plugin_config->{$plugin_name} = { %{ $plugin_configs{$plugin_name} // {} }, %{ $cli_config->{$plugin_name} } };
Condition100%2/2
$plugin_configs{$plugin_name} // {}
l!l
13
MC/DC100%1/1
$plugin_configs{$plugin_name} // {}
$plugin_configs{$plugin_name}
Truth table100%2/2
A
A= $plugin_configs{$plugin_name}
Aresult
11
00
569 }
570  
571 5 return $final_plugin_config;
572 }
573  
574 ########################################################################
575 0 ▶sub check_for_pipelining {
Subroutine check_for_pipelining: not called CC=7 SCAR=40.3
Pod undocumented
576 ########################################################################
577 0 my ($self) = @_;
578  
579 0 ▶ my $pipelining = !-t STDIN && !eof(STDIN); ## no critic
Condition0%0/3
-t STDIN || eof STDIN
l!l&&r!l&&!r
000
MC/DC0%0/2
-t STDIN || eof STDIN
-t STDIN eof STDIN
Truth table0%0/3
A || B
A= -t STDINB= eof STDIN
ABresult
1X1
011
000
580  
581 0 my $parameter_file = $self->get_parameter_file;
582  
583 0 my $template = $self->get_template;
584  
585 return
586 if !$pipelining
587 || ( $parameter_file && $template )
588 0 ▶ || any { $_ && $_ eq q{-} } ( $parameter_file, $template );
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 2 branches
BranchTrueFalseTotal
if not $pipelining or $parameter_file and $template or &any(sub { $_ and $_ eq "-"; } , $parameter_file, $template) 0 0 0
$_ and $_ eq "-" 0 0 0
Condition0%0/9
not $pipelining or $parameter_file and $template or &any(sub { $_ and $_ eq "-"; } , $parameter_file, $template)
l!l&&r!l&&!r
000
not $pipelining or $parameter_file and $template
l!l&&r!l&&!r
000
$parameter_file and $template
!ll&&!rl&&r
000
MC/DC0%0/4
not $pipelining or $parameter_file and $template or &any(sub { $_ and $_ eq "-"; } , $parameter_file, $template)
not $pipelining $parameter_file $template &any(sub { $_ and $_ eq "-"; } , $parameter_file, $template)
Truth table0%0/6
not(A) or B and C or D
A= not $pipeliningB= $parameter_fileC= $templateD= &any(sub { $_ and $_ eq "-"; } , $parameter_file, $template)
ABCDresult
1XXX1
011X1
00X11
01011
00X00
01000
589  
590 0 ▶ $self->set( $parameter_file ? 'template' : 'parameter_file', q{-} );
Branch: 1 branch
BranchTrueFalseTotal
$parameter_file ? : 0 0 0
591  
592 0 return;
593 }
594  
595 ########################################################################
596 0 ▶sub init {
Subroutine init: not called CC=9 SCAR=45.0
Pod documented
597 ########################################################################
598 0 my ($self) = @_;
599  
600 0 ▶ if ( $self->get_verbose ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_verbose) 0 0 0
601 0 $self->get_logger->level( $LOG_LEVELS{info} );
602 }
603  
604 0 ▶ if ( $self->get_debug ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_debug) 0 0 0
605 0 $self->get_logger->level( $LOG_LEVELS{debug} );
606 }
607  
608 0 ▶ if ( $self->get_env ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_env) 0 0 0
609 # create a parameter file from the environment (or add?)
610 0 my ( $fh, $env_file ) = tempfile( 'env-XXXXX', SUFFIX => '.json', UNLINK => $TRUE );
611  
612 0 my %parameters = ( env => \%ENV );
613  
614 0 ▶ if ( my $parameter_file = $self->get_parameter_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $parameter_file = $self->get_parameter_file) 0 0 0
615 0 %parameters = ( %parameters, %{ JSON->new_decode( slurp_file($parameter_file) ) } );
616 }
617  
618 0 print {$fh} JSON->new->encode( \%parameters );
619  
620 0 close $fh;
621  
622 0 $self->set_parameter_file($env_file);
623 }
624  
625 0 $self->check_for_pipelining;
626  
627 0 my $final_plugin_config = $self->_build_plugin_config();
628  
629 0 ▶ my $resolver = Config::Resolver->new(
Condition0%0/2
$self->get_plugins // ""
l!l
00
MC/DC0%0/1
$self->get_plugins // ""
$self->get_plugins
Truth table0%0/2
A
A= $self->get_plugins
Aresult
11
00
630 logger => $self->get_logger,
631 plugin_config => $final_plugin_config,
632 warning_level => $self->get_warning_level,
633 debug => $self->get_debug,
634 plugins => [ split /\s*,\s*/xsm, $self->get_plugins // q{} ],
635 );
636  
637 0 $self->set_resolver($resolver);
638  
639 0 $self->fetch_query_params;
640  
641 0 $self->fetch_parameters;
642  
643 # support legacy -r, -d options
644 0 ▶ if ( $self->get_resolve ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_resolve) 0 0 0
645 0 $self->command('resolve');
646 }
647  
648 0 ▶ if ( $self->get_dump ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_dump) 0 0 0
649 0 $self->command('dump');
650 }
651  
652 0 ▶ if ( $self->get_version ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_version) 0 0 0
653 0 $self->command('version');
654 }
655  
656 0 return;
657 }
658  
659 ########################################################################
660 0 ▶sub main {
Subroutine main: not called CC=1 SCAR=6.9
Pod documented
661 ########################################################################
662  
663 0 my @option_specs = qw(
664 debug|g
665 dump|d
666 env|e
667 format|f=s
668 help
669 key|k=s
670 manifest|m=s
671 outfile|o=s
672 output_dir|O=s
673 parameter-file|p=s
674 pretty|P
675 parameters|V=s
676 plugins=s
677 plugin=s@
678 resolve|r
679 separator|S=s
680 template=s
681 umask=s
682 warning-level|w=s
683 verbose|v
684 version
685 );
686  
687 0 my %commands = (
688 dump => \&cmd_dump,
689 resolve => \&cmd_resolve,
690 version => \&cmd_version,
691 );
692  
693 0 my %defaults = (
694 warning_level => 'warn',
695 format => 'json',
696 );
697  
698 0 my $cli = Config::Resolver::CLI->new(
699 commands => \%commands,
700 option_specs => \@option_specs,
701 extra_options => [qw(resolver parameters_hash)],
702 default_options => \%defaults
703 );
704  
705 0 return $cli->run();
706 }
707  
708 17 1;
709  
710 ## no critic
711  
712 __END__
↑ Summary Resolver.pm »