blib/lib/Qiime2/Artifact.pm

filter: Statementstmt 81.5% 208 / 255 Branchbran 59.0% 64 / 110 (1 uncoverable) Conditioncond 60.0% 18 / 30 MC/DCmcdc 38.8% 7 / 18 Subroutinesub 92.3% 24 / 26 Podpod 100% 4 / 4 totaltotal 73.5% 325 / 443 (1 uncoverable) CC 77 SCAR 27.6
CC
77
Cov
74%
extract_file
56.0
_check_unzip
36.3
_read_artifact
19.9
CRAP 15.8
↑ Summary
1 package Qiime2::Artifact;
2 #ABSTRACT: A parser for Qiime2 artifact files
3  
4 11 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use Cwd qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use Term::ANSIColor qw(:constants);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use YAML::PP;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use Capture::Tiny ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 11 $Qiime2::Artifact::VERSION = '0.14.0';
16  
17 11 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
18 11 VALID_PARAMETERS => {
19 'filename' => 'Path to the artifact',
20 'unzip' => 'Path to the unzip program (default: search in PATH)',
21 'debug' => 'Enable debug mode (not implemented)',
22 'verbose' => 'Enable verbose mode (not implemented)'
23 }
24 11 };
25  
26 sub _crash($ $);
27  
28 15 ▶sub new {
Subroutine new: called CC=8 SCAR=20.8
Pod documented
29 15 my ($class, $args) = @_;
30  
31 # Check for misspelled parameters
32 15 for my $parameter (keys %{ $args }) {
33 _crash(undef, "Parameter <$parameter> is not a valid Qiime2::Artifact->new() attribute.\nValid options: " .
34 19 ▶ join(', ', sort keys %{+VALID_PARAMETERS})) unless VALID_PARAMETERS->{$parameter};
Branch: 1 branch
BranchTrueFalseTotal
unless {"debug" => "Enable debug mode (not implemented)","filename" => "Path to the artifact","unzip" => "Path to the unzip program (default: search in PATH)","verbose" => "Enable verbose mode (not implemented)"}->{$parameter} 1 18 19
35 }
36  
37  
38 14 my $abs_path = Cwd::abs_path($args->{filename});
39 14 ▶ my $unzip_path = $args->{unzip} // 'unzip';
Condition100%2/2
$args->{"unzip"} // "unzip"
l!l
212
MC/DC100%1/1
$args->{"unzip"} // "unzip"
$args->{"unzip"}
Truth table100%2/2
A
A= $args->{"unzip"}
Aresult
11
00
40 14 chomp($unzip_path);
41  
42 # Check supplied filename (abs_path uses the filesystem and return undef if file not found)
43 14 ▶ _crash undef, "Filename not found: $args->{filename}" unless defined $abs_path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $abs_path 1 13 14
44 # Check unzip
45 13 ▶ _crash undef, "UnZip not found as <$unzip_path>.\n" unless _check_unzip($unzip_path);
Branch: 1 branch
BranchTrueFalseTotal
unless _check_unzip($unzip_path) 0 12 12
46  
47 my $self = {
48  
49 filename_arg => $args->{filename},
50 debug => $args->{debug} // 0,
51 12 ▶ verbose => $args->{verbose} // 0,
Condition100%4/4
$args->{"debug"} // 0
l!l
111
$args->{"verbose"} // 0
l!l
111
MC/DC100%1/1
$args->{"debug"} // 0
$args->{"debug"}
MC/DC100%1/1
$args->{"verbose"} // 0
$args->{"verbose"}
Truth table100%2/2
A
A= $args->{"debug"}
Aresult
11
00
Truth table100%2/2
A
A= $args->{"verbose"}
Aresult
11
00
52 filename => $abs_path,
53 unzip_path => $unzip_path,
54 };
55  
56  
57 12 my $object = bless $self, $class;
58  
59 12 _verbose($self, "Loading $args->{filename}");
60 12 _debug($self, "Debug: $self->{debug}; Verbose: $self->{verbose}", $args);
61  
62 12 _read_artifact($object);
63 9 _debug($self, "$args->{filename} loaded");
64  
65 9 return $object;
66 }
67  
68  
69 12 ▶sub _read_artifact {
Subroutine _read_artifact: called CC=19 SCAR=29.9
70 12 my ($self) = @_;
71  
72 # Initialize attributes
73 12 $self->{visualization} = 0 ;
74  
75 12 ▶ if (not defined $self->{filename}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"filename"}) 0 12 12
76 0 _crash $self, "_read_artifact: filename not defined $self";
77 }
78 12 ▶ if (not defined $self->{unzip_path}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"unzip_path"}) 0 12 12
79 0 _crash $self, "_read_artifact: <unzip> path not defined $self";
80 } # Read files content in the artifact
81 12 my $artifact_raw = _run( [$self->{unzip_path}, '-t', $self->{filename}] );
82  
83 12 ▶ if ($artifact_raw->{status} != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($artifact_raw->{"status"} != 0) 1 11 12
84 # Unzip -t failed: not a zip file
85 1 _crash $self, "$self->{filename} is not a ZIP file";
86 }
87  
88 11 my $artifact_id;
89 my @artifact_data;
90 11 my %artifact_parents;
91 11 my %artifact_files;
92  
93 # Read all files
94 11 for my $line ( @{$artifact_raw->{'lines'}} ) {
95 187 chomp($line);
96 187 ▶ if ($line=~/testing:\s+(.+?)\s+OK/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /testing:\s+(.+?)\s+OK/u) 167 20 187
97 167 my ($id, $root, @path) = split /\//, $1;
98  
99 167 ▶ _crash $self, "$self->{filename} is not a valid artifact:\n \"{id}/directory/data\" structure expected, found:\n \"$1\"" unless (defined $root);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $root 2 165 167
100 165 my $stripped_path = $root;
101 165 ▶ $stripped_path.= '/' . join('/', @path) if ($path[0]);
Branch: 1 branch
BranchTrueFalseTotal
if $path[0] 143 22 165
102 165 $artifact_files{$stripped_path} = $1;
103  
104 165 ▶ if (! defined $artifact_id) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $artifact_id) { } 9 156 165
elsif ($artifact_id ne $id) { } 0 156 156
105 9 $artifact_id = $id;
106 } elsif ($artifact_id ne $id) {
107 0 _crash $self, "Artifact format error: Artifact $self->{filename} has multiple roots ($artifact_id but also $id).\n";
108 }
109 165 ▶ if ($root eq 'data') {
Branch: 2 branches
BranchTrueFalseTotal
if ($root eq 'data') { } 59 106 165
elsif ($root eq 'provenance') { } 84 22 106
110 59 ▶ if (basename($stripped_path) eq 'index.html') {
Branch: 1 branch
BranchTrueFalseTotal
if (basename($stripped_path) eq "index.html") 2 57 59
111 2 $self->{visualization} = 1;
112 }
113 59 push(@artifact_data, basename($stripped_path));
114  
115  
116 } elsif ($root eq 'provenance') {
117 84 ▶ if ($path[0] eq 'artifacts') {
Branch: 1 branch
BranchTrueFalseTotal
if ($path[0] eq "artifacts") 48 36 84
118 48 $artifact_parents{$path[1]}++;
119 }
120  
121 }
122  
123 }
124 }
125  
126 9 $self->{data} = \@artifact_data;
127  
128 9 ▶ if (not defined $self->{data}[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"data"}[0]) 0 9 9
129 0 _crash($self, "No data found in artifact $self->{filename}");
130 }
131 9 $self->{id} = $artifact_id;
132 9 my $auto = _YAMLLoad( $self->_getArtifactText($self->{id} .'/provenance/action/action.yaml') , $self->{id} .'/provenance/action/action.yaml' );
133 9 $self->{parents}->{self} = $auto->{action};
134  
135 9 ▶ _crash($self, "No self parent") if (not defined $self->{parents}->{self});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"parents"}{"self"} 0 9 9
136  
137 9 for my $key (keys %artifact_parents) { # key=fa0cb712-1940-4971-9e7c-a08581e948ed
138 12 my $parent = $self->_get_parent($key);
139 12 $self->{parents}->{$key} = $parent;
140 }
141  
142  
143 9 $self->{ancestry} = _getAncestry($self);
144 9 $self->{version} = 'Unknown';
145 9 $self->{version} = 'archive';
146  
147 9 my $root_version = _getArtifactText($self, $self->{id}.'/VERSION');
148 9 ▶ $self->{version} = $1 if ($root_version=~/framework:\s*\"?(.+)\"?/);
Branch: 1 branch
BranchTrueFalseTotal
if $root_version =~ /framework:\s*\"?(.+)\"?/u 9 0 9
149 9 ▶ $self->{archive} = $1 if ($root_version=~/archive:\s*\"?(.+)\"?/);
Branch: 1 branch
BranchTrueFalseTotal
if $root_version =~ /archive:\s*\"?(.+)\"?/u 9 0 9
150 9 $self->{loaded} = 1;
151 9 $self->{parents_number} = scalar( keys %{ $self->{parents} } ) - 1 ;
152  
153 }
154  
155  
156 9 ▶sub _getAncestry {
Subroutine _getAncestry: called CC=15 SCAR=27.6
157 9 my ($self) = @_;
158 9 my @output;
159 9 my %found = ();
160  
161 # Direct parents
162 #$output->{objects}[0] = [ $self->{id} ];
163 9 $output[0] = [ $self->{id} ];
164  
165 9 $self->{imported} = 0;
166 9 ▶ if ($self->{parents}->{self}->{type} eq 'import' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"parents"}{"self"}{"type"} eq "import") 1 8 9
167 1 $self->{imported} = 1;
168  
169 }
170  
171  
172 # Hack for taxonomy.qzv
173 9 ▶ if ($self->{parents}->{self}->{type} eq 'visualizer') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"parents"}{"self"}{"type"} eq "visualizer") 2 7 9
174 2 for my $hash (@{ $self->{parents}->{self}->{parameters} }) {
175 2 ▶ if (defined $hash->{input} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{"input"}) 0 2 2
176 0 my ($id) = split /:/, $hash->{input};
177 0 ▶ push @{$output[1]}, $id if (defined $id);
Branch: 1 branch
BranchTrueFalseTotal
if defined $id 0 0 0
178 }
179 }
180 }
181  
182 9 for my $input (@{$self->{parents}->{self}->{inputs}}) {
183  
184 8 for my $key (sort keys %{ $input }) {
185 8 ▶ push @{ $output[1] }, $$input{ $key } if (defined $$input{ $key });
Branch: 1 branch
BranchTrueFalseTotal
if defined $input->{$key} 8 0 8
186 }
187 }
188  
189 # Loop
190 9 my $parents = 1;
191  
192 9 ▶ while ($parents) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parents) 11 9 20
193 11 $parents = 0;
194 11 my $last_index = $#output;
195 11 for my $item ( @{ $output[$last_index] } ) {
196  
197  
198 11 ▶ if ( defined $self->{parents}->{$item}->{from} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'parents'}{$item}{'from'}) { } 2 9 11
199 2 $parents++;
200 2 foreach my $child ( @{ $self->{parents}->{$item}->{from} } ) {
201 2 ▶ if (defined $child) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $child) 2 0 2
202 2 ▶ push( @{ $output[$last_index + 1 ] }, $child) if ($found{$child});
Branch: 1 branch
BranchTrueFalseTotal
if $found{$child} 1 1 2
203 2 $found{$child}++;
204 }
205 }
206 } else {
207 9 $parents = 0;
208 }
209 }
210 }
211 9 return \@output;
212 }
213  
214 13 ▶sub _check_unzip {
Subroutine _check_unzip: called CC=10 SCAR=35.9
215 13 my $unzip_path = shift;
216 13 my $cmd_list = [$unzip_path];
217 13 my $pattern = 'UnZip 6.00';
218
219 # Return codes:
220 # 1 = pattern found in STDOUT
221 # 2 = pattern found in STDERR
222 # 3 = file exists but pattern not tested (Windows)
223 # 10 = binary present but version not tested (non-Linux/macOS)
224 # 0 = pattern not found
225  
226 # uncoverable branch false
227 13 ▶ if ($^O eq 'linux' or $^O eq 'darwin') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "linux" or $^O eq "darwin") 13 0 13
Condition33%1/3
$^O eq "linux" or $^O eq "darwin"
l!l&&r!l&&!r
1300
MC/DC0%0/2
$^O eq "linux" or $^O eq "darwin"
$^O eq "linux" $^O eq "darwin"
Truth table33%1/3
A or B
A= $^O eq "linux"B= $^O eq "darwin"
ABresult
1X1
011
000
228 # Check if command produces output containing version string
229 13 my $output = _run($cmd_list);
230  
231 13 ▶ if ($output->{status} != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($output->{"status"} != 0) 1 12 13
232 1 _crash(undef, "Unable to test <$unzip_path>, execution returned $output->{status}.\n".
233 "Under Linux and macOS $unzip_path is expected to print its help when invoked.\n");
234 }
235  
236 12 ▶ return 1 if $output->{stdout} =~ /$pattern/; # Found in STDOUT
Branch: 1 branch
BranchTrueFalseTotal
if $output->{"stdout"} =~ /$pattern/u 12 0 12
237 0 ▶ return 2 if $output->{stderr} =~ /$pattern/; # Found in STDERR
Branch: 1 branch
BranchTrueFalseTotal
if $output->{"stderr"} =~ /$pattern/u 0 0 0
238 0 return 0; # Not found
239 }
240
241 # Non-Linux/macOS systems
242 0 ▶ if (-e $unzip_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $unzip_path) 0 0 0
243 0 return 3; # File exists, don't test further on Windows
244 }
245
246 # Try generic detection for other systems
247 0 $pattern = 'unzip';
248 0 my $output = _run($cmd_list);
249 0 ▶ return 1 if $output->{stdout} =~ /$pattern/i;
Branch: 1 branch
BranchTrueFalseTotal
if $output->{"stdout"} =~ /$pattern/iu 0 0 0
250 0 ▶ return 2 if $output->{stderr} =~ /$pattern/i;
Branch: 1 branch
BranchTrueFalseTotal
if $output->{"stderr"} =~ /$pattern/iu 0 0 0
251  
252 # Last resort: check if binary is in PATH
253 0 system(['which', $unzip_path]);
254 0 ▶ if ($?) {
Branch: 1 branch
BranchTrueFalseTotal
if ($?) 0 0 0
255 0 _crash(undef, "Trying under non Linux/MacOS: <which $unzip_path> returned $?.\n".
256 "#Debug: $output->{stdout}\n#Debug: $output->{stderr}\n");
257 }
258
259 # Binary is present, but version not tested
260 0 return 10;
261 }
262  
263 12 ▶sub _get_parent {
Subroutine _get_parent: called CC=3 SCAR=11.0
264 12 my ($self, $key) = @_;
265 12 my $parent;
266  
267 my $metadata;
268 12 my $action;
269 # metadata= [id]/provenance/artifacts/[key]/metadata.yaml
270 12 my $metadata_file = $self->{id} . "/provenance/artifacts/" . $key . '/metadata.yaml';
271 12 $metadata = _YAMLLoad( $self->_getArtifactText($metadata_file), $metadata_file );
272  
273 # action = [id]/provenance/artifacts/[key]/action/action.yaml
274 12 my $action_file = $self->{id} . "/provenance/artifacts/" . $key . '/action/action.yaml';
275 12 $action = _YAMLLoad( $self->_getArtifactText($action_file), $action_file );
276  
277 12 $parent->{metadata} = $metadata;
278  
279 12 $parent->{action} = $action->{action};
280  
281  
282 12 for my $input (@{$action->{action}->{inputs}}) {
283 4 for my $key (sort keys %{ $input }) {
284 4 push @{ $parent->{from} }, $$input{ $key };
285 }
286 }
287  
288 12 return $parent;
289 }
290  
291 43 ▶sub _getArtifactText {
Subroutine _getArtifactText: called CC=1 SCAR=0.0
292 43 my ($self, $file) = @_;
293 43 my @command_list = ($self->{unzip_path}, '-p', $self->{filename}, $file);
294  
295 43 my $out = _run(\@command_list);
296  
297  
298 43 return $out->{stdout};
299 }
300  
301 68 ▶sub _run {
Subroutine _run: called CC=2 SCAR=6.9
302 68 my ($command_list, $opt) = @_;
303  
304 68 ▶ return 0 unless defined ${ $command_list }[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined do { $command_list }->[0] 0 68 68
305  
306 # Prepare output data
307 68 my $out = {};
308  
309 68 ▶ my ($STDOUT, $STDERR, $OK) = capture {
Subroutine __ANON__: called CC=1 SCAR=0.0
310 68 system(@{ $command_list });
311 68 };
312  
313 68 $out->{cmd} = join(' ', @{ $command_list });
314 68 $out->{status} = $OK;
315 68 $out->{stdout} = $STDOUT;
316 68 $out->{stderr} = $STDERR;
317 68 my @output = split /\n/, $STDOUT;
318 68 $out->{lines} = \@output;
319  
320 68 return $out;
321 }
322  
323  
324 0 ▶sub get {
Subroutine get: not called CC=3 SCAR=24.8
Pod documented
325 0 my ($self, $key) = @_;
326
327 # Check if key exists in object
328 0 ▶ return $self->{$key} if defined $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{$key} 0 0 0
329
330 # Key doesn't exist, throw error with available keys for guidance
331 0 ▶ my @available_keys = grep { $_ !~ /^_/ && defined $self->{$_} } keys %$self;
Condition0%0/3
!($_ =~ /^_/u) && defined $self->{$_}
!ll&&!rl&&r
000
MC/DC0%0/2
!($_ =~ /^_/u) && defined $self->{$_}
!($_ =~ /^_/u) defined $self->{$_}
Truth table0%0/3
not(A) && B
A= !($_ =~ /^_/u)B= defined $self->{$_}
ABresult
0X0
100
111
332 0 my $available = join(', ', sort @available_keys);
333
334 0 _crash($self, "<$key> is not an attribute of this Artifact. Available keys: $available");
335 }
336  
337 0 ▶sub extract_file {
Subroutine extract_file: not called CC=7 SCAR=40.3
Pod documented
338 0 my ($self, $data_file, $target_path) = @_;
339
340 # Check if the artifact is properly loaded
341 0 ▶ _crash($self, "Artifact not loaded") unless defined $self->{loaded};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"loaded"} 0 0 0
342
343 # Validate parameters
344 0 ▶ _crash($self, "Missing data_file parameter") unless defined $data_file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data_file 0 0 0
345 0 ▶ _crash($self, "Missing target_path parameter") unless defined $target_path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $target_path 0 0 0
346
347 # Construct the internal path within the artifact
348 0 my $internal_path = "$self->{id}/data/$data_file";
349
350 # Debug output
351 0 _verbose($self, "Extracting $internal_path to $target_path");
352
353 # Run unzip command to extract the file
354 0 my @command = ($self->{unzip_path}, '-p', $self->{filename}, $internal_path);
355 0 my $result = _run(\@command);
356
357 0 ▶ if ($result->{status} != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->{"status"} != 0) 0 0 0
358 0 _crash($self, "Failed to extract file: $data_file\nCommand: $result->{cmd}\nError: $result->{stderr}");
359 }
360
361 # Write extracted content to the target file
362 0 ▶ open my $fh, '>', $target_path or _crash($self, "Cannot open $target_path for writing: $!");
Branch: 1 branch
BranchTrueFalseTotal
&Qiime2::Artifact::open(my $fh, ">", $target_path) or &_crash($self, "Cannot open $target_path for writing: $!") 0 0 0
363 0 binmode $fh;
364 0 print $fh $result->{stdout};
365 0 close $fh;
366
367 # Debug output if successful
368 0 ▶ _debug($self, "Successfully extracted $data_file to $target_path") if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
369
370 0 return 1; # Return success
371 }
372  
373 1 ▶sub get_bib {
Subroutine get_bib: called CC=6 SCAR=20.9
Pod documented
374 1 my ($self) = @_;
375
376 # Check if the artifact is properly loaded
377 1 ▶ _crash($self, "Artifact not loaded") unless defined $self->{loaded};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"loaded"} 0 1 1
378
379 # Initialize variables
380 1 my $citations_file = $self->{id} . '/provenance/citations.bib';
381 1 my $bib_content;
382
383 # Try to get bibliography content
384 1 eval {
385 # Get the content of citations.bib from the zip file
386 1 $bib_content = $self->_getArtifactText($citations_file);
387 };
388
389 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
390 # Handle error if file extraction fails
391 0 _verbose($self, "Error extracting bibliography: $@");
392 0 return undef;
393 }
394
395 # Check if we got any content
396 1 ▶ if (!defined $bib_content || length($bib_content) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $bib_content or length $bib_content == 0) 0 1 1
Condition33%1/3
not defined $bib_content or length $bib_content == 0
l!l&&r!l&&!r
001
MC/DC0%0/2
not defined $bib_content or length $bib_content == 0
not defined $bib_content length $bib_content == 0
Truth table33%1/3
not(A) or B
A= not defined $bib_contentB= length $bib_content == 0
ABresult
1X1
011
000
397 0 _verbose($self, "No bibliography found in $citations_file");
398 0 return undef;
399 }
400
401 # Debug output if enabled
402 1 ▶ _debug($self, "Bibliography extracted from $citations_file", $bib_content) if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 1 1
403
404 # Store bibliography in object for future reference
405 1 $self->{bibliography} = $bib_content;
406
407 1 return $bib_content;
408 }
409  
410  
411 21 ▶sub _debug {
Subroutine _debug: called CC=4 SCAR=13.9
412 21 my ($self, $msg, $data, $opt) = @_;
413 21 ▶ return 0 unless defined $self->{debug} && $self->{debug} != 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"debug"} and $self->{"debug"} != 0 19 2 21
Condition66%2/3
defined $self->{"debug"} and $self->{"debug"} != 0
!ll&&!rl&&r
0192
MC/DC50%1/2
defined $self->{"debug"} and $self->{"debug"} != 0
defined $self->{"debug"} $self->{"debug"} != 0
Truth table66%2/3
A and B
A= defined $self->{"debug"}B= $self->{"debug"} != 0
ABresult
0X0
100
111
414
415 2 say STDERR GREEN, BOLD, '> ', $self->{debug}, ' ', RESET, $msg;
416 2 ▶ say STDERR Dumper $data if defined $data;
Branch: 1 branch
BranchTrueFalseTotal
if defined $data 1 1 2
417
418 2 return 1;
419 }
420  
421 12 ▶sub _verbose {
Subroutine _verbose: called CC=3 SCAR=11.0
422 12 my ($self, $msg, $opt) = @_;
423 12 ▶ return 0 unless $self->{verbose} || $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"verbose"} or $self->{"debug"} 10 2 12
Condition100%3/3
$self->{"verbose"} or $self->{"debug"}
l!l&&r!l&&!r
1110
MC/DC100%2/2
$self->{"verbose"} or $self->{"debug"}
$self->{"verbose"} $self->{"debug"}
Truth table100%3/3
A or B
A= $self->{"verbose"}B= $self->{"debug"}
ABresult
1X1
011
000
424
425 2 say STDERR '# Qiime2::Artifact # ', RESET, $msg;
426
427 2 return 1;
428 }
429  
430  
431  
432 33 ▶sub _YAMLLoad {
Subroutine _YAMLLoad: called CC=4 SCAR=15.8
433 33 my ($string, $info) = @_;
434
435 33 ▶ unless (defined $string && length($string)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $string and length $string) 0 33 33
Condition33%1/3
defined $string and length $string
!ll&&!rl&&r
0033
MC/DC0%0/2
defined $string and length $string
defined $string length $string
Truth table33%1/3
A and B
A= defined $stringB= length $string
ABresult
0X0
100
111
436 0 _crash undef, "YAML string empty or undefined: unexpected error";
437 }
438
439 33 my $ypp = YAML::PP->new;
440 33 my $result = eval { $ypp->load_string($string) };
441
442 33 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 33 33
443 0 _crash undef, "YAMLLoad failed on string $info:\n" .
444 "-" x 48 . "\n$string\n" .
445 "Error: $@";
446 }
447
448 33 return $result;
449 }
450  
451  
452 6 ▶sub _crash($ $) {
Subroutine _crash: called CC=5 SCAR=16.2
453 6 my ($self, $msg) = @_;
454
455 6 chomp($msg);
456 6 $msg =~ s/\n/\n /g;
457
458 6 ▶ my $error_header = defined $self ? '[Qiime2::Artifact ERROR]' : '[Qiime2::Reader ERROR]';
Branch: 1 branch
BranchTrueFalseTotal
defined $self ? : 3 3 6
459
460 6 ▶ if (!defined $self || $self->{verbose} || $self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self or $self->{'verbose'} or $self->{'debug'}) { } 3 3 6
Condition66%4/6
not defined $self or $self->{"verbose"} or $self->{"debug"}
l!l&&r!l&&!r
303
not defined $self or $self->{"verbose"}
l!l&&r!l&&!r
303
MC/DC33%1/3
not defined $self or $self->{"verbose"} or $self->{"debug"}
not defined $self $self->{"verbose"} $self->{"debug"}
Truth table50%2/4
not(A) or B or C
A= not defined $selfB= $self->{"verbose"}C= $self->{"debug"}
ABCresult
1XX1
01X1
0011
0000
461 3 print STDERR BOLD RED " $error_header", RESET, "\n";
462 3 print STDERR RED " $msg\n ", '-' x 64, "\n", RESET;
463 3 confess();
464 } else {
465 3 confess("$error_header $msg\n");
466 }
467 }
468  
469 11 1;
470  
471 __END__
↑ Summary