| 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
Condition66%2/3
defined $share_dir and length $share_dir
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
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 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
Condition42%3/7
($manifest->{"format"} // "") eq "convert-pheno-sqlite-bundle" and ($manifest->{"formatVersion"} // 0) == 1
$manifest->{"format"} // ""
$manifest->{"formatVersion"} // 0
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"}
| |||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||
| 42 | 1150 | ▶ | my $current = $manifest->{currentBundle} // q{}; | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$manifest->{"currentBundle"} // ""
MC/DC0%0/1
$manifest->{"currentBundle"} // ""
$manifest->{"currentBundle"}
Truth table50%1/2
A
A= $manifest->{"currentBundle"}
| |||||||||||||||||||||||||||||||||||||
| 43 | 1150 | ▶ | die "Database bundle manifest <$manifest_file> has no valid currentBundle\n" | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 44 | unless $current =~ /\A[A-Za-z0-9][A-Za-z0-9._-]*\z/; | ||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||
| 46 | 1149 | ▶ | if ( defined $manifest->{bundleVersion} | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $manifest->{"bundleVersion"} and $manifest->{"bundleVersion"} ne $current
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
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $ontology and $ontology =~ /\A[A-Za-z0-9_]+\z/
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/
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 83 | unless ref $entry eq 'HASH'; | ||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||
| 85 | 1144 | ▶ | my $filename = $entry->{file} // q{}; | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$entry->{"file"} // ""
MC/DC0%0/1
$entry->{"file"} // ""
$entry->{"file"}
Truth table50%1/2
A
A= $entry->{"file"}
| |||||||||||||||||||||||||||||||||||||
| 86 | 1144 | ▶ | die "Database <$ontology> has an invalid bundle filename\n" | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||||||