lib/Convert/Pheno/Runner.pm

filter: Statementstmt 94.2% 196 / 208 Branchbran 82.2% 74 / 90 Conditioncond 62.0% 36 / 58 MC/DCmcdc 30.5% 11 / 36 Subroutinesub 100% 49 / 49 Podpod 0.0% 0 / 2 totaltotal 82.6% 366 / 443 CC 68 SCAR 24.2
CC
68
Cov
86%
run_operation
27.1
_process_operation_items
20.4
_throw_run_failure
11.2
CRAP 11.2
« lib/Convert/Pheno/CDISC/SDTM/ToBFF.pm ↑ Summary lib/Convert/Pheno/Mapping/Compiler.pm »
1 package Convert::Pheno::Runner;
2  
3 136 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 136 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 136 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 136 ▶use feature qw(say);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 136 ▶use JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 136 ▶use Convert::Pheno::BFF::DerivedEntities qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
10 execution_entities
11 synthesize_bundle_entities
12 136 );
13 136 ▶use Convert::Pheno::CBioPortal::ToBFF ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 136 ▶use Convert::Pheno::Context;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 136 ▶use Convert::Pheno::ConversionRequest;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 136 ▶use Convert::Pheno::CDISC::SDTM::ToBFF ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 136 ▶use Convert::Pheno::ClinicalCDM::ToBFF ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 136 ▶use Convert::Pheno::ExecutionContext;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 136 ▶use Convert::Pheno::FHIR::ToBFF ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20 136 ▶use Convert::Pheno::Model::Bundle;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 136 ▶use Convert::Pheno::OMOP::ToBFF ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 136 ▶use Convert::Pheno::OpenEHR::ToBFF ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 136 ▶use Convert::Pheno::Operations qw(conversion_spec);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 136 ▶use Convert::Pheno::PXF::ToBFF ();
Subroutine BEGIN: called CC=1 SCAR=0.0
25 136 ▶use Convert::Pheno::Tabular::ToBFF ();
Subroutine BEGIN: called CC=1 SCAR=0.0
26 136 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 136 our @EXPORT_OK = qw(resolve_operation run_operation);
29  
30 136 my %DIRECT_OPERATIONS = (
31 bff2pxf => \&Convert::Pheno::do_bff2pxf,
32 bff2csv => \&Convert::Pheno::do_bff2csv,
33 bff2jsonf => \&Convert::Pheno::do_bff2csv,
34 bff2jsonld => \&Convert::Pheno::do_bff2jsonld,
35 bff2omop => \&Convert::Pheno::do_bff2omop,
36 pxf2csv => \&Convert::Pheno::do_pxf2csv,
37 pxf2jsonf => \&Convert::Pheno::do_pxf2csv,
38 pxf2jsonld => \&Convert::Pheno::do_pxf2jsonld,
39 );
40  
41 my %BUNDLE_SOURCE_HANDLERS = (
42 100 ▶ cbioportal => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
43 100 return Convert::Pheno::CBioPortal::ToBFF::run_cbioportal_to_bundle(@_);
44 },
45 181 ▶ 'cdisc-odm' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
46 181 return Convert::Pheno::Tabular::ToBFF::run_tabular_to_bundle(@_);
47 },
48 242 ▶ csv => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
49 242 return Convert::Pheno::Tabular::ToBFF::run_tabular_to_bundle(@_);
50 },
51 31 ▶ 'dataset-json' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
52 31 return Convert::Pheno::CDISC::SDTM::ToBFF::run_sdtm_to_bundle(@_);
53 },
54 22 ▶ 'dataset-xml' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
55 22 return Convert::Pheno::CDISC::SDTM::ToBFF::run_sdtm_to_bundle(@_);
56 },
57 18 ▶ fhir => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
58 18 return Convert::Pheno::FHIR::ToBFF::run_fhir_to_bundle(@_);
59 },
60 14 ▶ i2b2 => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
61 14 return Convert::Pheno::ClinicalCDM::ToBFF::run_clinical_cdm_to_bundle(@_);
62 },
63 12915 ▶ omop => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
64 12915 return Convert::Pheno::OMOP::ToBFF::run_omop_to_bundle(@_);
65 },
66 20 ▶ openehr => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
67 20 return Convert::Pheno::OpenEHR::ToBFF::run_openehr_to_bundle(@_);
68 },
69 12 ▶ pcornet => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
70 12 return Convert::Pheno::ClinicalCDM::ToBFF::run_clinical_cdm_to_bundle(@_);
71 },
72 341 ▶ pxf => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
73 341 return Convert::Pheno::PXF::ToBFF::run_pxf_to_bundle(@_);
74 },
75 180 ▶ redcap => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
76 180 return Convert::Pheno::Tabular::ToBFF::run_tabular_to_bundle(@_);
77 },
78 10 ▶ sentinel => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
79 10 return Convert::Pheno::ClinicalCDM::ToBFF::run_clinical_cdm_to_bundle(@_);
80 },
81 136 );
82  
83 265 ▶sub resolve_operation {
Subroutine resolve_operation: called CC=5 SCAR=16.4
Pod undocumented
84 265 my ($self) = @_;
85 my $spec = conversion_spec( $self->{method} )
86 265 ▶ or die "Unsupported method <$self->{method}> in runner\n";
Branch: 1 branch
BranchTrueFalseTotal
my $spec = conversion_spec($self->{"method"}) or die qq[Unsupported method <$self->{"method"}> in runner\n] 264 1 265
87  
88 264 ▶ if ( $spec->{operation} eq 'bundle' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{"operation"} eq "bundle") 189 75 264
89 my $handler = $BUNDLE_SOURCE_HANDLERS{ $spec->{source} }
90 189 ▶ or die "No bundle handler is registered for source <$spec->{source}>\n";
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $BUNDLE_SOURCE_HANDLERS{$spec->{"source"}} or die qq[No bundle handler is registered for source <$spec->{"source"}>\n] 189 0 189
91 189 return _bundle_operation( spec => $spec, run => $handler );
92 }
93  
94 return _direct_operation(
95 spec => $spec,
96 1035 ▶ run => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
97 1035 my ( $convert, $input ) = @_;
98 1035 return $DIRECT_OPERATIONS{ $convert->{method} }->( $convert, $input );
99 },
100 75 ▶ ) if exists $DIRECT_OPERATIONS{ $self->{method} };
Branch: 1 branch
BranchTrueFalseTotal
if exists $DIRECT_OPERATIONS{$self->{"method"}} 75 0 75
101  
102 0 die "Unsupported method <$self->{method}> in runner\n";
103 }
104  
105 264 ▶sub run_operation {
Subroutine run_operation: called CC=25 SCAR=33.0
Pod undocumented
106 264 my ( $self, $input, %arg ) = @_;
107  
108 264 ▶ my $operation = $arg{operation} || resolve_operation($self);
Condition100%3/3
$arg{'operation'} || resolve_operation($self)
l!l&&r!l&&!r
22611
MC/DC0%0/2
$arg{'operation'} || resolve_operation($self)
$arg{'operation'} resolve_operation($self)
Truth table66%2/3
A || B
A= $arg{'operation'}B= resolve_operation($self)
ABresult
1X1
011
000
109 263 ▶ my $view = $arg{view} || 'primary';
Condition100%2/2
$arg{'view'} || 'primary'
l!l
2621
MC/DC100%1/1
$arg{'view'} || 'primary'
$arg{'view'}
Truth table100%2/2
A
A= $arg{'view'}
Aresult
11
00
110 263 ▶ my $operation_name = $operation->{name} || $self->{method};
Condition66%2/3
$operation->{'name'} || $self->{'method'}
l!l&&r!l&&!r
26210
MC/DC0%0/2
$operation->{'name'} || $self->{'method'}
$operation->{'name'} $self->{'method'}
Truth table66%2/3
A || B
A= $operation->{'name'}B= $self->{'method'}
ABresult
1X1
011
000
111 my $request = $arg{request}
112 263 ▶ || Convert::Pheno::ConversionRequest->from_converter($self);
Condition33%1/3
$arg{'request'} || 'Convert::Pheno::ConversionRequest'->from_converter($self)
l!l&&r!l&&!r
02630
MC/DC0%0/2
$arg{'request'} || 'Convert::Pheno::ConversionRequest'->from_converter($self)
$arg{'request'} 'Convert::Pheno::ConversionRequest'->from_converter($self)
Truth table33%1/3
A || B
A= $arg{'request'}B= 'Convert::Pheno::ConversionRequest'->from_converter($self)
ABresult
1X1
011
000
113 my $execution = $arg{execution_context}
114 263 ▶ || Convert::Pheno::ExecutionContext->new(
Condition33%1/3
$arg{'execution_context'} || 'Convert::Pheno::ExecutionContext'->new({'request', $request, 'stages', [$operation_name]})
l!l&&r!l&&!r
02630
MC/DC0%0/2
$arg{'execution_context'} || 'Convert::Pheno::ExecutionContext'->new({'request', $request, 'stages', [$operation_name]})
$arg{'execution_context'} 'Convert::Pheno::ExecutionContext'->new({'request', $request, 'stages', [$operation_name]})
Truth table33%1/3
A || B
A= $arg{'execution_context'}B= 'Convert::Pheno::ExecutionContext'->new({'request', $request, 'stages', [$operation_name]})
ABresult
1X1
011
000
115 {
116 request => $request,
117 stages => [$operation_name],
118 }
119 );
120 263 my ($execution_stage) = $execution->begin_next_stage;
121 263 ▶ die "Execution stage <$execution_stage> does not match operation <$operation_name>\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $execution_stage eq $operation_name 0 263 263
122 unless $execution_stage eq $operation_name;
123  
124 263 ▶ die "Unsupported runner view <$view>\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $view eq "primary" or $view eq "bundle" 0 263 263
Condition66%2/3
$view eq "primary" or $view eq "bundle"
l!l&&r!l&&!r
201620
MC/DC0%0/2
$view eq "primary" or $view eq "bundle"
$view eq "primary" $view eq "bundle"
Truth table66%2/3
A or B
A= $view eq "primary"B= $view eq "bundle"
ABresult
1X1
011
000
125 unless $view eq 'primary' || $view eq 'bundle';
126  
127 263 ▶ if ( $view eq 'bundle' && $operation->{type} ne 'bundle' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($view eq "bundle" and $operation->{"type"} ne "bundle") 0 263 263
Condition66%2/3
$view eq "bundle" and $operation->{"type"} ne "bundle"
!ll&&!rl&&r
201620
MC/DC0%0/2
$view eq "bundle" and $operation->{"type"} ne "bundle"
$view eq "bundle" $operation->{"type"} ne "bundle"
Truth table66%2/3
A and B
A= $view eq "bundle"B= $operation->{"type"} ne "bundle"
ABresult
0X0
100
111
128 0 die "Method <$self->{method}> does not support bundle dispatch\n";
129 }
130  
131 263 my $context = _resolve_context( $self, $operation );
132 263 ▶ my $stream = $view eq 'primary'
Branch: 1 branch
BranchTrueFalseTotal
$view eq 'primary' ? : 201 62 263
133 ? Convert::Pheno::_dispatcher_open_stream_out($self)
134 : undef;
135 263 ▶ my $json = $stream ? JSON::XS->new->canonical->pretty : undef;
Branch: 1 branch
BranchTrueFalseTotal
$stream ? : 13 250 263
136  
137 263 ▶ my $out_data =
Branch: 1 branch
BranchTrueFalseTotal
$view eq 'bundle' ? : 62 201 263
138 $view eq 'bundle'
139 ? Convert::Pheno::Model::Bundle->new(
140 {
141 context => $context,
142 entities => $context->entities,
143 }
144 )
145 : undef;
146  
147 263 my $connections_open = 0;
148 263 my ( $ok, $error );
149  
150 263 $ok = eval {
151 263 ▶ if ( $operation->{requires_sqlite} || $self->{terminology_lookup_required} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($operation->{"requires_sqlite"} or $self->{"terminology_lookup_required"}) 132 131 263
Condition100%3/3
$operation->{"requires_sqlite"} or $self->{"terminology_lookup_required"}
l!l&&r!l&&!r
1266131
MC/DC100%2/2
$operation->{"requires_sqlite"} or $self->{"terminology_lookup_required"}
$operation->{"requires_sqlite"} $self->{"terminology_lookup_required"}
Truth table100%3/3
A or B
A= $operation->{"requires_sqlite"}B= $self->{"terminology_lookup_required"}
ABresult
1X1
011
000
152 132 Convert::Pheno::open_connections_SQLite($self);
153 132 $connections_open = 1;
154 132 $execution->set_resource( sqlite_open => 1 );
155 }
156  
157 263 $out_data = _process_operation_items(
158 $self,
159 $input,
160 $operation,
161 $context,
162 $view,
163 $stream,
164 $json,
165 $out_data,
166 $execution,
167 );
168 261 1;
169 };
170 263 ▶ $error = $@ unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 2 261 263
171  
172 263 my @cleanup_errors;
173 _run_cleanup(
174 \@cleanup_errors,
175 'closing SQLite connections',
176 132 ▶ sub { Convert::Pheno::close_connections_SQLite($self) },
Subroutine __ANON__: called CC=1 SCAR=0.0
177 )
178 263 ▶ if $connections_open;
Branch: 1 branch
BranchTrueFalseTotal
if $connections_open 132 131 263
179 263 ▶ $execution->set_resource( sqlite_open => 0 ) if $connections_open;
Branch: 1 branch
BranchTrueFalseTotal
if $connections_open 132 131 263
180 _run_cleanup(
181 \@cleanup_errors,
182 'closing the terminology audit',
183 263 ▶ sub { Convert::Pheno::finalize_term_audit($self) },
Subroutine __ANON__: called CC=1 SCAR=0.0
184 263 );
185 263 delete $self->{current_row};
186 263 $execution->clear_current_row;
187  
188 263 ▶ if ($stream) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream) 13 250 263
189 13 ▶ if ( $ok && !@cleanup_errors ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok and not @cleanup_errors) { } 12 1 13
Condition66%2/3
$ok and not @cleanup_errors
!ll&&!rl&&r
1012
MC/DC50%1/2
$ok and not @cleanup_errors
$ok not @cleanup_errors
Truth table66%2/3
A and not(B)
A= $okB= not @cleanup_errors
ABresult
0X0
100
111
190 _run_cleanup(
191 \@cleanup_errors,
192 'finalizing streamed output',
193 12 ▶ sub { Convert::Pheno::finalize_stream_out($stream) },
Subroutine __ANON__: called CC=1 SCAR=0.0
194 12 );
195 }
196 else {
197 _run_cleanup(
198 \@cleanup_errors,
199 'closing failed streamed output',
200 1 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=13.1
201 close $stream->{fh}
202 1 ▶ if $stream->{fh} && defined fileno( $stream->{fh} );
Branch: 1 branch
BranchTrueFalseTotal
if $stream->{"fh"} and defined fileno $stream->{"fh"} 1 0 1
Condition33%1/3
$stream->{"fh"} and defined fileno $stream->{"fh"}
!ll&&!rl&&r
001
MC/DC0%0/2
$stream->{"fh"} and defined fileno $stream->{"fh"}
$stream->{"fh"} defined fileno $stream->{"fh"}
Truth table33%1/3
A and B
A= $stream->{"fh"}B= defined fileno $stream->{"fh"}
ABresult
0X0
100
111
203 1 return 1;
204 },
205 1 );
206 }
207 }
208  
209 263 ▶ _throw_run_failure( $error, \@cleanup_errors )
Branch: 1 branch
BranchTrueFalseTotal
if not $ok or @cleanup_errors 2 261 263
Condition66%2/3
not $ok or @cleanup_errors
l!l&&r!l&&!r
20261
MC/DC50%1/2
not $ok or @cleanup_errors
not $ok @cleanup_errors
Truth table66%2/3
not(A) or B
A= not $okB= @cleanup_errors
ABresult
1X1
011
000
210 if !$ok || @cleanup_errors;
211  
212 261 ▶ my $result = $stream ? 1 : $out_data;
Branch: 1 branch
BranchTrueFalseTotal
$stream ? : 12 249 261
213 261 $execution->complete_stage($result);
214 261 return $result;
215 }
216  
217 263 ▶sub _process_operation_items {
Subroutine _process_operation_items: called CC=20 SCAR=30.2
218 my (
219 263 $self, $input, $operation, $context,
220 $view, $stream, $json, $out_data, $execution,
221 ) = @_;
222  
223 263 my $is_array = ref($input) eq 'ARRAY';
224 263 ▶ my $item_count = $is_array ? scalar @{$input} : 1;
Branch: 1 branch
BranchTrueFalseTotal
$is_array ? : 236 27 263
225  
226 263 ▶ if ( $view eq 'primary' && $is_array ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($view eq "primary" and $is_array) 175 88 263
Condition100%3/3
$view eq "primary" and $is_array
!ll&&!rl&&r
6226175
MC/DC100%2/2
$view eq "primary" and $is_array
$view eq "primary" $is_array
Truth table100%3/3
A and B
A= $view eq "primary"B= $is_array
ABresult
0X0
100
111
227 175 $out_data = [];
228 }
229  
230 263 my $total = 0;
231 263 ▶ for ( my $i = 0; $i < $item_count; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $item_count) 15122 247 15369
232 15122 my $count = $i + 1;
233 15122 ▶ my $item = $is_array ? $input->[$i] : $input;
Branch: 1 branch
BranchTrueFalseTotal
$is_array ? : 15095 27 15122
234  
235 15122 $self->{current_row} = $count;
236 15122 $execution->set_current_row($count);
237  
238 15122 my $raw = _execute_operation_raw( $self, $operation, $item, $context );
239 15120 ▶ next unless defined $raw;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $raw 0 15120 15120
240  
241 15120 ▶ if ( $view eq 'bundle' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($view eq "bundle") 5827 9293 15120
242 5827 _merge_bundle(
243 $out_data,
244 $raw,
245 $context->entities,
246 );
247 5827 next;
248 }
249  
250 9293 my $result = _primary_result( $operation, $raw );
251 9293 ▶ next unless defined $result;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result 518 8775 9293
252  
253 8775 $total++;
254  
255 8775 ▶ if ($stream) {
Branch: 2 branches
BranchTrueFalseTotal
if ($stream) { } 6000 2775 8775
elsif ($is_array) { } 2750 25 2775
256 6000 ▶ print { $stream->{fh} } ",\n" unless $stream->{first};
Branch: 1 branch
BranchTrueFalseTotal
unless $stream->{"first"} 5988 12 6000
257 Convert::Pheno::_transform_item(
258 $self,
259 $result,
260 $stream->{fh},
261 6000 1,
262 $json
263 );
264 6000 $stream->{first} = 0;
265 }
266 elsif ($is_array) {
267 2750 push @{$out_data}, $result;
268 }
269 else {
270 25 $out_data = $result;
271 }
272  
273 last if ( $self->{method} eq 'omop2bff'
274 && $self->{max_lines_sql}
275 8775 ▶ && $total >= $self->{max_lines_sql} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"method"} eq "omop2bff" and $self->{"max_lines_sql"} and $total >= $self->{"max_lines_sql"} 14 8761 8775
Condition83%5/6
$self->{"method"} eq "omop2bff" and $self->{"max_lines_sql"} and $total >= $self->{"max_lines_sql"}
!ll&&!rl&&r
1770699114
$self->{"method"} eq "omop2bff" and $self->{"max_lines_sql"}
!ll&&!rl&&r
177007005
MC/DC66%2/3
$self->{"method"} eq "omop2bff" and $self->{"max_lines_sql"} and $total >= $self->{"max_lines_sql"}
$self->{"method"} eq "omop2bff" $self->{"max_lines_sql"} $total >= $self->{"max_lines_sql"}
Truth table75%3/4
A and B and C
A= $self->{"method"} eq "omop2bff"B= $self->{"max_lines_sql"}C= $total >= $self->{"max_lines_sql"}
ABCresult
0XX0
10X0
1100
1111
276 }
277  
278 261 ▶ if ($is_array) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_array) 235 26 261
279 235 ▶ if ( $self->{verbose} && $self->{method} eq 'omop2bff' && $view eq 'primary' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"} and $self->{"method"} eq "omop2bff" and $view eq "primary") 0 235 235
Condition33%2/6
$self->{"verbose"} and $self->{"method"} eq "omop2bff" and $view eq "primary"
!ll&&!rl&&r
23500
$self->{"verbose"} and $self->{"method"} eq "omop2bff"
!ll&&!rl&&r
23500
MC/DC0%0/3
$self->{"verbose"} and $self->{"method"} eq "omop2bff" and $view eq "primary"
$self->{"verbose"} $self->{"method"} eq "omop2bff" $view eq "primary"
Truth table25%1/4
A and B and C
A= $self->{"verbose"}B= $self->{"method"} eq "omop2bff"C= $view eq "primary"
ABCresult
0XX0
10X0
1100
1111
280 0 say "==============\nIndividuals total: $total\n";
281 }
282 }
283  
284 261 ▶ synthesize_bundle_entities( $self, $out_data, $context )
Branch: 1 branch
BranchTrueFalseTotal
if $view eq "bundle" 62 199 261
285 if $view eq 'bundle';
286  
287 261 return $out_data;
288 }
289  
290 408 ▶sub _run_cleanup {
Subroutine _run_cleanup: called CC=3 SCAR=15.4
291 408 my ( $errors, $label, $code ) = @_;
292 408 my $ok = eval {
293 408 $code->();
294 408 1;
295 };
296 408 ▶ return 1 if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 408 0 408
297  
298 0 ▶ my $error = $@ || 'unknown cleanup error';
Condition0%0/2
$@ || 'unknown cleanup error'
l!l
00
MC/DC0%0/1
$@ || 'unknown cleanup error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
299 0 chomp $error;
300 0 push @{$errors}, "$label: $error";
301 0 return;
302 }
303  
304 2 ▶sub _throw_run_failure {
Subroutine _throw_run_failure: called CC=6 SCAR=24.1
305 2 my ( $error, $cleanup_errors ) = @_;
306 2 ▶ my $message = defined $error ? $error : q{};
Branch: 1 branch
BranchTrueFalseTotal
defined $error ? : 2 0 2
307 2 ▶ $message .= "\n" if length($message) && $message !~ /\n\z/;
Branch: 1 branch
BranchTrueFalseTotal
if length $message and not $message =~ /\n\z/ 0 2 2
Condition33%1/3
length $message and not $message =~ /\n\z/
!ll&&!rl&&r
020
MC/DC0%0/2
length $message and not $message =~ /\n\z/
length $message not $message =~ /\n\z/
Truth table33%1/3
A and not(B)
A= length $messageB= not $message =~ /\n\z/
ABresult
0X0
100
111
308  
309 2 ▶ if ( @{$cleanup_errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$cleanup_errors;}) 0 2 2
310 0 ▶ $message .= "Conversion cleanup failed:\n" unless length $message;
Branch: 1 branch
BranchTrueFalseTotal
unless length $message 0 0 0
311 0 $message .= join q{}, map { " $_\n" } @{$cleanup_errors};
312 }
313  
314 2 die $message;
315 }
316  
317 263 ▶sub _resolve_context {
Subroutine _resolve_context: called CC=5 SCAR=16.2
318 263 my ( $self, $operation ) = @_;
319  
320 return $self->{conversion_context}
321 if $operation->{type} eq 'bundle'
322 263 ▶ && $self->{conversion_context};
Branch: 1 branch
BranchTrueFalseTotal
if $operation->{"type"} eq "bundle" and $self->{"conversion_context"} 125 138 263
Condition100%3/3
$operation->{"type"} eq "bundle" and $self->{"conversion_context"}
!ll&&!rl&&r
7563125
MC/DC100%2/2
$operation->{"type"} eq "bundle" and $self->{"conversion_context"}
$operation->{"type"} eq "bundle" $self->{"conversion_context"}
Truth table100%3/3
A and B
A= $operation->{"type"} eq "bundle"B= $self->{"conversion_context"}
ABresult
0X0
100
111
323  
324 return Convert::Pheno::Context->from_self(
325 $self,
326 {
327 source_format => $operation->{source_format},
328 target_format => $operation->{target_format},
329 entities => execution_entities(
330 $self->{entities} || $operation->{default_entities}
331 ),
332 }
333 138 ▶ ) if $operation->{type} eq 'bundle';
Branch: 1 branch
BranchTrueFalseTotal
if $operation->{"type"} eq "bundle" 63 75 138
Condition33%1/3
$self->{'entities'} || $operation->{'default_entities'}
l!l&&r!l&&!r
6300
MC/DC0%0/2
$self->{'entities'} || $operation->{'default_entities'}
$self->{'entities'} $operation->{'default_entities'}
Truth table33%1/3
A || B
A= $self->{'entities'}B= $operation->{'default_entities'}
ABresult
1X1
011
000
334  
335 75 return undef;
336 }
337  
338 15122 ▶sub _execute_operation_raw {
Subroutine _execute_operation_raw: called CC=1 SCAR=0.0
339 15122 my ( $self, $operation, $input, $context ) = @_;
340 15122 return $operation->{run}->( $self, $input, $context );
341 }
342  
343 9293 ▶sub _primary_result {
Subroutine _primary_result: called CC=2 SCAR=6.9
344 9293 my ( $operation, $result ) = @_;
345 9293 ▶ return $result unless $operation->{type} eq 'bundle';
Branch: 1 branch
BranchTrueFalseTotal
unless $operation->{"type"} eq "bundle" 1035 8258 9293
346 8258 return $result->primary_entity( $operation->{primary_entity} );
347 }
348  
349 5827 ▶sub _merge_bundle {
Subroutine _merge_bundle: called CC=3 SCAR=11.0
350 5827 my ( $aggregate, $item_bundle, $entities ) = @_;
351 5827 for my $entity ( @{$entities} ) {
352 8500 for my $entry ( @{ $item_bundle->entities($entity) } ) {
353 4943 $aggregate->add_entity( $entity => $entry );
354 }
355 }
356 5827 return 1;
357 }
358  
359 189 ▶sub _bundle_operation {
Subroutine _bundle_operation: called CC=3 SCAR=11.0
360 189 my (%arg) = @_;
361 189 my $spec = $arg{spec};
362 die "Conversion <$spec->{name}> is not a bundle operation\n"
363 189 ▶ unless $spec->{operation} eq 'bundle';
Branch: 1 branch
BranchTrueFalseTotal
unless $spec->{"operation"} eq "bundle" 0 189 189
364  
365 return {
366 type => 'bundle',
367 name => $spec->{name},
368 source_format => $spec->{source},
369 target_format => $spec->{target},
370 requires_sqlite => $spec->{resources}{sqlite} ? 1 : 0,
371 default_entities => $spec->{entities}{default},
372 primary_entity => $spec->{entities}{primary},
373 run => $arg{run},
374 189 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$spec->{'resources'}{'sqlite'} ? : 109 80 189
375 }
376  
377 75 ▶sub _direct_operation {
Subroutine _direct_operation: called CC=3 SCAR=11.0
378 75 my (%arg) = @_;
379 75 my $spec = $arg{spec};
380 die "Conversion <$spec->{name}> is not a direct operation\n"
381 75 ▶ unless $spec->{operation} eq 'direct';
Branch: 1 branch
BranchTrueFalseTotal
unless $spec->{"operation"} eq "direct" 0 75 75
382  
383 return {
384 type => 'direct',
385 name => $spec->{name},
386 requires_sqlite => $spec->{resources}{sqlite} ? 1 : 0,
387 run => $arg{run},
388 75 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$spec->{'resources'}{'sqlite'} ? : 17 58 75
389 }
390  
391 136 1;
« lib/Convert/Pheno/CDISC/SDTM/ToBFF.pm ↑ Summary lib/Convert/Pheno/Mapping/Compiler.pm »