lib/Convert/Pheno/DB/Bundle.pm

filter: Statementstmt 100% 58 / 58 Branchbran 72.7% 16 / 22 Conditioncond 50.0% 10 / 20 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 3 totaltotal 78.4% 98 / 125 CC 20 SCAR 22.2
CC
20
Cov
84%
bundle_manifest
16.5
bundled_database_path
6.7
_current_bundle_dir
2.0
CRAP 9.2
« lib/Convert/Pheno/ClinicalCDM/Claims.pm ↑ Summary lib/Convert/Pheno/Source/CDISC/DatasetJSON.pm »
1 package Convert::Pheno::DB::Bundle;
2  
3 144 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 144 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 144 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 144 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 144 ▶use File::Spec::Functions qw(catdir catfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 144 ▶use JSON::XS qw(decode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 144 our @EXPORT_OK = qw(
12 bundle_manifest
13 bundled_database_path
14 current_bundle_dir
15 );
16  
17 144 ▶use constant BUNDLE_FORMAT => 'convert-pheno-sqlite-bundle';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 144 ▶use constant BUNDLE_FORMAT_VERSION => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1151 ▶sub bundle_manifest {
Subroutine bundle_manifest: called CC=14 SCAR=28.0
Pod undocumented
21 1151 my ($share_dir) = @_;
22 1151 ▶ die "Database bundle lookup requires the distribution share directory\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $share_dir and length $share_dir 1 1150 1151
Condition66%2/3
defined $share_dir and length $share_dir
!ll&&!rl&&r
011150
MC/DC50%1/2
defined $share_dir and length $share_dir
defined $share_dir length $share_dir
Truth table66%2/3
A and B
A= defined $share_dirB= length $share_dir
ABresult
0X0
100
111
23 unless defined $share_dir && length $share_dir;
24  
25 1150 my $manifest_file = catfile( $share_dir, 'db', 'manifest.json' );
26 1150 ▶ die "Database bundle manifest not found: $manifest_file\n"
Branch: 1 branch
BranchTrueFalseTotal
unless -f $manifest_file 0 1150 1150
27 unless -f $manifest_file;
28  
29 1150 open my $fh, '<:raw', $manifest_file;
30 1150 local $/;
31 1150 my $json = <$fh>;
32 1150 close $fh;
33  
34 1150 my $manifest = eval { decode_json($json) };
35 1150 ▶ die "Invalid database bundle manifest <$manifest_file>: $@"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $manifest eq "HASH" 0 1150 1150
36 unless ref $manifest eq 'HASH';
37  
38 die "Unsupported database bundle format in <$manifest_file>\n"
39 unless ( $manifest->{format} // q{} ) eq BUNDLE_FORMAT
40 1150 ▶ && ( $manifest->{formatVersion} // 0 ) == BUNDLE_FORMAT_VERSION;
Branch: 1 branch
BranchTrueFalseTotal
unless ($manifest->{"format"} // "") eq "convert-pheno-sqlite-bundle" and ($manifest->{"formatVersion"} // 0) == 1 0 1150 1150
Condition42%3/7
($manifest->{"format"} // "") eq "convert-pheno-sqlite-bundle" and ($manifest->{"formatVersion"} // 0) == 1
!ll&&!rl&&r
001150
$manifest->{"format"} // ""
l!l
11500
$manifest->{"formatVersion"} // 0
l!l
11500
MC/DC0%0/2
($manifest->{"format"} // "") eq "convert-pheno-sqlite-bundle" and ($manifest->{"formatVersion"} // 0) == 1
$manifest->{"format"} $manifest->{"formatVersion"}
Truth table33%1/3
A and B
A= $manifest->{"format"}B= $manifest->{"formatVersion"}
ABresult
0X0
100
111
41  
42 1150 ▶ my $current = $manifest->{currentBundle} // q{};
Condition50%1/2
$manifest->{"currentBundle"} // ""
l!l
11500
MC/DC0%0/1
$manifest->{"currentBundle"} // ""
$manifest->{"currentBundle"}
Truth table50%1/2
A
A= $manifest->{"currentBundle"}
Aresult
11
00
43 1150 ▶ die "Database bundle manifest <$manifest_file> has no valid currentBundle\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $current =~ /\A[A-Za-z0-9][A-Za-z0-9._-]*\z/ 1 1149 1150
44 unless $current =~ /\A[A-Za-z0-9][A-Za-z0-9._-]*\z/;
45  
46 1149 ▶ if ( defined $manifest->{bundleVersion}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $manifest->{"bundleVersion"} and $manifest->{"bundleVersion"} ne $current) 1 1148 1149
Condition66%2/3
defined $manifest->{"bundleVersion"} and $manifest->{"bundleVersion"} ne $current
!ll&&!rl&&r
011481
MC/DC50%1/2
defined $manifest->{"bundleVersion"} and $manifest->{"bundleVersion"} ne $current
defined $manifest->{"bundleVersion"} $manifest->{"bundleVersion"} ne $current
Truth table66%2/3
A and B
A= defined $manifest->{"bundleVersion"}B= $manifest->{"bundleVersion"} ne $current
ABresult
0X0
100
111
47 && $manifest->{bundleVersion} ne $current )
48 {
49 1 die "Database bundle manifest <$manifest_file> points to <$current> "
50 . "but describes <$manifest->{bundleVersion}>\n";
51 }
52  
53 die "Database bundle manifest <$manifest_file> has no databases object\n"
54 1148 ▶ unless ref $manifest->{databases} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $manifest->{"databases"} eq "HASH" 0 1148 1148
55  
56 1148 return $manifest;
57 }
58  
59 1146 ▶sub _current_bundle_dir {
Subroutine _current_bundle_dir: called CC=2 SCAR=6.9
60 1146 my ( $share_dir, $manifest ) = @_;
61 my $directory =
62 1146 catdir( $share_dir, 'db', $manifest->{currentBundle} );
63  
64 1146 ▶ die "Current database bundle directory not found: $directory\n"
Branch: 1 branch
BranchTrueFalseTotal
unless -d $directory 1 1145 1146
65 unless -d $directory;
66  
67 1145 return $directory;
68 }
69  
70 4 ▶sub current_bundle_dir {
Subroutine current_bundle_dir: called CC=1 SCAR=0.0
Pod undocumented
71 4 my ($share_dir) = @_;
72 4 return _current_bundle_dir( $share_dir, bundle_manifest($share_dir) );
73 }
74  
75 1146 ▶sub bundled_database_path {
Subroutine bundled_database_path: called CC=6 SCAR=19.0
Pod undocumented
76 1146 my ( $share_dir, $ontology ) = @_;
77 1146 ▶ die "Database bundle lookup requires an ontology name\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ontology and $ontology =~ /\A[A-Za-z0-9_]+\z/ 0 1146 1146
Condition33%1/3
defined $ontology and $ontology =~ /\A[A-Za-z0-9_]+\z/
!ll&&!rl&&r
001146
MC/DC0%0/2
defined $ontology and $ontology =~ /\A[A-Za-z0-9_]+\z/
defined $ontology $ontology =~ /\A[A-Za-z0-9_]+\z/
Truth table33%1/3
A and B
A= defined $ontologyB= $ontology =~ /\A[A-Za-z0-9_]+\z/
ABresult
0X0
100
111
78 unless defined $ontology && $ontology =~ /\A[A-Za-z0-9_]+\z/;
79  
80 1146 my $manifest = bundle_manifest($share_dir);
81 1145 my $entry = $manifest->{databases}{$ontology};
82 1145 ▶ die "Database <$ontology> is not declared in the current bundle\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $entry eq "HASH" 1 1144 1145
83 unless ref $entry eq 'HASH';
84  
85 1144 ▶ my $filename = $entry->{file} // q{};
Condition50%1/2
$entry->{"file"} // ""
l!l
11440
MC/DC0%0/1
$entry->{"file"} // ""
$entry->{"file"}
Truth table50%1/2
A
A= $entry->{"file"}
Aresult
11
00
86 1144 ▶ die "Database <$ontology> has an invalid bundle filename\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $filename =~ /\A[A-Za-z0-9][A-Za-z0-9._-]*\z/ 0 1144 1144
87 unless $filename =~ /\A[A-Za-z0-9][A-Za-z0-9._-]*\z/;
88  
89 1144 return catfile( _current_bundle_dir( $share_dir, $manifest ), $filename );
90 }
91  
92 144 1;
« lib/Convert/Pheno/ClinicalCDM/Claims.pm ↑ Summary lib/Convert/Pheno/Source/CDISC/DatasetJSON.pm »