| 1 | package Convert::Pheno::HTTP::Projects; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Path::Tiny qw(path); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use JSON::XS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Convert::Pheno::IO::Atomic qw(write_atomically); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | my $json = JSON::XS->new->utf8->canonical->pretty; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 12 | ▶ | sub _settings { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_settings: called CC=10 SCAR=31.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 12 | my ($data) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | die "Invalid project settings\n" unless ref($data) eq 'HASH' && defined($data->{conversion}) && !ref($data->{conversion}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 12 | ▶ | && ref($data->{options}) eq 'HASH' && ref($data->{output}) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%4/12
ref $data eq "HASH" and defined $data->{"conversion"} and not ref $data->{"conversion"} and ref $data->{"options"} eq "HASH" and ref $data->{"output"} eq "HASH"
ref $data eq "HASH" and defined $data->{"conversion"} and not ref $data->{"conversion"} and ref $data->{"options"} eq "HASH"
ref $data eq "HASH" and defined $data->{"conversion"} and not ref $data->{"conversion"}
ref $data eq "HASH" and defined $data->{"conversion"}
MC/DC0%0/5
ref $data eq "HASH" and defined $data->{"conversion"} and not ref $data->{"conversion"} and ref $data->{"options"} eq "HASH" and ref $data->{"output"} eq "HASH"
ref $data eq "HASH"
defined $data->{"conversion"}
not ref $data->{"conversion"}
ref $data->{"options"} eq "HASH"
ref $data->{"output"} eq "HASH"
Truth table16%1/6
A and B and not(C) and D and E
A= ref $data eq "HASH"B= defined $data->{"conversion"}C= not ref $data->{"conversion"}D= ref $data->{"options"} eq "HASH"E= ref $data->{"output"} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 12 | ▶ | if (exists $data->{output}{entities}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | die "Invalid project entities\n" unless ref($data->{output}{entities}) eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 12 | ▶ | && !grep { !defined($_) || ref($_) } @{$data->{output}{entities}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
ref $data->{"output"}{"entities"} eq "ARRAY" and not grep({not defined $_ or ref $_;} @{$$data{"output"}{"entities"};})
!defined($_) || ref $_
MC/DC0%0/2
ref $data->{"output"}{"entities"} eq "ARRAY" and not grep({not defined $_ or ref $_;} @{$$data{"output"}{"entities"};})
ref $data->{"output"}{"entities"} eq "ARRAY"
not grep({not defined $_ or ref $_;} @{$$data{"output"}{"entities"};})
MC/DC0%0/2
!defined($_) || ref $_
!defined($_)
ref $_
Truth table33%1/3
A and not(B)
A= ref $data->{"output"}{"entities"} eq "ARRAY"B= not grep({not defined $_ or ref $_;} @{$$data{"output"}{"entities"};})
Truth table33%1/3
not(A) || B
A= !defined($_)B= ref $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | ▶ | sub _write { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | my ($file, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | ▶ | write_atomically($file, sub { path($_[0])->spew_raw($json->encode($value)) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 8 | ▶ | sub _read { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read: called CC=15 SCAR=37.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 8 | my ($file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 8 | ▶ | die "Select a project smaller than 4 MiB\n" unless -f $file && !-l $file && -s $file <= 4194304; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
-f $file and not -l $file and -s $file <= 4194304
-f $file and not -l $file
MC/DC0%0/3
-f $file and not -l $file and -s $file <= 4194304
-f $file
not -l $file
-s $file <= 4194304
Truth table25%1/4
A and not(B) and C
A= -f $fileB= not -l $fileC= -s $file <= 4194304
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 8 | my $data = $json->decode(path($file)->slurp_raw); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | die "Unsupported Convert-Pheno project\n" unless ref($data) eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | && ($data->{format} || '') eq 'convert-pheno-project' && ($data->{version} || 0) == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 7 | ▶ | && ref($data->{settings}) eq 'HASH' && ref($data->{sources}) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition37%6/16
ref $data eq "HASH" and ($data->{"format"} || "") eq "convert-pheno-project" and ($data->{"version"} || 0) == 1 and ref $data->{"settings"} eq "HASH" and ref $data->{"sources"} eq "HASH"
ref $data eq "HASH" and ($data->{"format"} || "") eq "convert-pheno-project" and ($data->{"version"} || 0) == 1 and ref $data->{"settings"} eq "HASH"
ref $data eq "HASH" and ($data->{"format"} || "") eq "convert-pheno-project" and ($data->{"version"} || 0) == 1
ref $data eq "HASH" and ($data->{"format"} || "") eq "convert-pheno-project"
$data->{'format'} || ''
$data->{'version'} || 0
MC/DC0%0/5
ref $data eq "HASH" and ($data->{"format"} || "") eq "convert-pheno-project" and ($data->{"version"} || 0) == 1 and ref $data->{"settings"} eq "HASH" and ref $data->{"sources"} eq "HASH"
ref $data eq "HASH"
$data->{'format'}
$data->{'version'}
ref $data->{"settings"} eq "HASH"
ref $data->{"sources"} eq "HASH"
Truth table16%1/6
A and B and C and D and E
A= ref $data eq "HASH"B= $data->{'format'}C= $data->{'version'}D= ref $data->{"settings"} eq "HASH"E= ref $data->{"sources"} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 7 | _settings($data->{settings}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 7 | ▶ | die "Invalid project run references\n" if exists($data->{runs}) && (ref($data->{runs}) ne 'ARRAY' || grep {ref($_) || !defined($_)} @{$data->{runs}}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
exists $data->{"runs"} and ref $data->{"runs"} ne "ARRAY" || grep({ref $_ or not defined $_;} @{$$data{"runs"};})
ref $data->{"runs"} ne "ARRAY" or grep {ref $_ or not defined $_;} @{$$data{"runs"};}
ref $_ || !defined($_)
MC/DC0%0/3
exists $data->{"runs"} and ref $data->{"runs"} ne "ARRAY" || grep({ref $_ or not defined $_;} @{$$data{"runs"};})
exists $data->{"runs"}
ref $data->{"runs"} ne "ARRAY"
grep {ref $_ or not defined $_;} @{$$data{"runs"};}
MC/DC0%0/2
ref $_ || !defined($_)
ref $_
!defined($_)
Truth table25%1/4
A and B or C
A= exists $data->{"runs"}B= ref $data->{"runs"} ne "ARRAY"C= grep {ref $_ or not defined $_;} @{$$data{"runs"};}
Truth table33%1/3
A || not(B)
A= ref $_B= !defined($_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 7 | return $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # These operations are available only behind native authorization. A project | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # manifest must never grant arbitrary filesystem access to an HTTP client. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 5 | ▶ | sub save { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save: called CC=37 SCAR=41.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 5 | my ($jobs, $file, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 5 | ▶ | die "Invalid project contents\n" unless ref($data) eq 'HASH' && ref($data->{settings}) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $data eq "HASH" and ref $data->{"settings"} eq "HASH"
MC/DC0%0/2
ref $data eq "HASH" and ref $data->{"settings"} eq "HASH"
ref $data eq "HASH"
ref $data->{"settings"} eq "HASH"
Truth table33%1/3
A and B
A= ref $data eq "HASH"B= ref $data->{"settings"} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 5 | _settings($data->{settings}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 5 | ▶ | die "Invalid project files\n" unless ref($data->{files} || {}) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$data->{'files'} || {}
MC/DC0%0/1
$data->{'files'} || {}
$data->{'files'}
Truth table50%1/2
A
A= $data->{'files'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 5 | ▶ | die "Use a .cpheno project filename\n" unless defined($file) && !ref($file) && $file =~ /\.cpheno\z/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $file and not ref $file and $file =~ /\.cpheno\z/i
defined $file and not ref $file
MC/DC0%0/3
defined $file and not ref $file and $file =~ /\.cpheno\z/i
defined $file
not ref $file
$file =~ /\.cpheno\z/i
Truth table25%1/4
A and not(B) and C
A= defined $fileB= not ref $fileC= $file =~ /\.cpheno\z/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 5 | ▶ | die "Project location is unavailable\n" unless -d path($file)->parent && !-l $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-d path($file)->parent and not -l $file
MC/DC0%0/2
-d path($file)->parent and not -l $file
-d path($file)->parent
not -l $file
Truth table33%1/3
A and not(B)
A= -d path($file)->parentB= not -l $file
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 5 | ▶ | _read($file) if -e $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # Grants use canonical paths. Resolve the project directory too, otherwise | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # macOS /var -> /private/var (or another directory symlink) breaks references. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 4 | my $parent = path($file)->parent->realpath; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 4 | $file = "@{[$parent->child(path($file)->basename)]}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 4 | my $assets = path("$file.data"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 4 | ▶ | die "Project data folder must not be a symbolic link\n" if -l $assets; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # Use a new snapshot so a failed save cannot invalidate the previous manifest. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 4 | $assets->mkpath({mode => 0700}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 4 | my $snapshot = Path::Tiny->tempdir('save-XXXXXXXX', DIR => "$assets", CLEANUP => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 4 | ▶ | my $reference = sub { File::Spec->abs2rel("$_[0]", "$parent") }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 4 | my %sources; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 4 | ▶ | for my $role (keys %{$data->{files} || {}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$data->{'files'} || {}
MC/DC0%0/1
$data->{'files'} || {}
$data->{'files'}
Truth table50%1/2
A
A= $data->{'files'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 6 | ▶ | next if $role eq 'mapping' && length($data->{mapping} || ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
$role eq "mapping" and length($data->{"mapping"} || "")
$data->{'mapping'} || ''
MC/DC0%0/2
$role eq "mapping" and length($data->{"mapping"} || "")
$role eq "mapping"
$data->{'mapping'}
Truth table33%1/3
A and B
A= $role eq "mapping"B= $data->{'mapping'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 6 | ▶ | die "Invalid input role\n" unless $role =~ /\A[a-zA-Z0-9_-]+\z/ && ref($data->{files}{$role}) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$role =~ /\A[a-zA-Z0-9_-]+\z/ and ref $data->{"files"}{$role} eq "ARRAY"
MC/DC0%0/2
$role =~ /\A[a-zA-Z0-9_-]+\z/ and ref $data->{"files"}{$role} eq "ARRAY"
$role =~ /\A[a-zA-Z0-9_-]+\z/
ref $data->{"files"}{$role} eq "ARRAY"
Truth table33%1/3
A and B
A= $role =~ /\A[a-zA-Z0-9_-]+\z/B= ref $data->{"files"}{$role} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 6 | for my $id (@{$data->{files}{$role}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 6 | my $source = $jobs->resolve_grant($id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 5 | my $relative = File::Spec->abs2rel($source, $jobs->{root}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 5 | ▶ | if ($jobs->{project_owned}{$id} || ($relative !~ /^\.\.(?:[\\\/]|$)/ && !File::Spec->file_name_is_absolute($relative))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$jobs->{"project_owned"}{$id} or not $relative =~ m[^\.\.(?:[\\/]|$)] || "File::Spec"->file_name_is_absolute($relative)
$relative =~ m[^\.\.(?:[\\/]|$)] || 'File::Spec'->file_name_is_absolute($relative)
MC/DC66%2/3
$jobs->{"project_owned"}{$id} or not $relative =~ m[^\.\.(?:[\\/]|$)] || "File::Spec"->file_name_is_absolute($relative)
$jobs->{"project_owned"}{$id}
$relative =~ m[^\.\.(?:[\\/]|$)]
'File::Spec'->file_name_is_absolute($relative)
Truth table75%3/4
A or not(B || C)
A= $jobs->{"project_owned"}{$id}B= $relative =~ m[^\.\.(?:[\\/]|$)]C= 'File::Spec'->file_name_is_absolute($relative)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 3 | ▶ | die "Managed input must be a file\n" unless -f $source; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 3 | ▶ | my $copy = $snapshot->child($role . '-' . scalar(@{$sources{$role} || []}) . '-' . path($source)->basename); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$sources{$role} || []
MC/DC0%0/1
$sources{$role} || []
$sources{$role}
Truth table50%1/2
A
A= $sources{$role}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 3 | path($source)->copy($copy); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 3 | $copy->chmod(0600); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 3 | $source = "$copy"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 5 | ▶ | push @{$sources{$role}}, {path => $reference->($source), directory => -d $source ? JSON::XS::true : JSON::XS::false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | owned => "$source" =~ /^\Q$snapshot\E/ ? JSON::XS::true : JSON::XS::false}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | my %saved = (format => 'convert-pheno-project', version => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | settings => $data->{settings}, sources => \%sources, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 3 | ▶ | runs => $data->{runs} || [], mappingDirty => $data->{mappingDirty} ? JSON::XS::true : JSON::XS::false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$data->{'runs'} || []
MC/DC100%1/1
$data->{'runs'} || []
$data->{'runs'}
Truth table100%2/2
A
A= $data->{'runs'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 3 | for my $part (qw(jsonInput mapping)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 6 | ▶ | next unless defined($data->{$part}) && length($data->{$part}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $data->{$part} and length $data->{$part}
MC/DC0%0/2
defined $data->{$part} and length $data->{$part}
defined $data->{$part}
length $data->{$part}
Truth table33%1/3
A and B
A= defined $data->{$part}B= length $data->{$part}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 6 | ▶ | die "Invalid project text\n" if ref($data->{$part}) || length($data->{$part}) > 104857600; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $data->{$part} or length $data->{$part} > 104857600
MC/DC0%0/2
ref $data->{$part} or length $data->{$part} > 104857600
ref $data->{$part}
length $data->{$part} > 104857600
Truth table33%1/3
A or B
A= ref $data->{$part}B= length $data->{$part} > 104857600
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 6 | ▶ | my $target = $snapshot->child($part eq 'mapping' ? 'mapping.yaml' : 'input.json'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 6 | $target->spew_utf8($data->{$part}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 6 | $target->chmod(0600); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 6 | $saved{$part} = $reference->($target); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # Reopen with the exact editor snapshot, not a potentially changed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # original mapping. Unfinished edits still require validation in the UI. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 6 | ▶ | $sources{mapping} = [{path => $saved{$part}, directory => JSON::XS::false, owned => JSON::XS::true}] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | if $part eq 'mapping'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 3 | ▶ | $saved{destination} = $reference->($jobs->resolve_grant($data->{destination})) if $data->{destination}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 3 | _write($file, \%saved); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 3 | my $handle = $jobs->register_file($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 3 | $handle->{displayPath} = $jobs->resolve_grant($handle->{id}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 3 | return {file => $handle}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 6 | ▶ | sub open { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
open: called CC=21 SCAR=32.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 6 | my ($jobs, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 6 | my $saved = _read($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 6 | my $parent = path($file)->parent->realpath; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 33 | ▶ | my $resolve = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=17.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 33 | my ($value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 33 | ▶ | die "Invalid path in project\n" if !defined($value) || ref($value) || $value =~ /\0/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not defined $value or ref $value or $value =~ /\0/
not defined $value or ref $value
MC/DC0%0/3
not defined $value or ref $value or $value =~ /\0/
not defined $value
ref $value
$value =~ /\0/
Truth table25%1/4
not(A) or B or C
A= not defined $valueB= ref $valueC= $value =~ /\0/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 33 | return File::Spec->rel2abs($value, "$parent"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 6 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 6 | my (%files, @missing); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 6 | for my $role (sort keys %{$saved->{sources}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 17 | ▶ | die "Invalid project sources\n" unless $role =~ /\A[a-zA-Z0-9_-]+\z/ && ref($saved->{sources}{$role}) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$role =~ /\A[a-zA-Z0-9_-]+\z/ and ref $saved->{"sources"}{$role} eq "ARRAY"
MC/DC0%0/2
$role =~ /\A[a-zA-Z0-9_-]+\z/ and ref $saved->{"sources"}{$role} eq "ARRAY"
$role =~ /\A[a-zA-Z0-9_-]+\z/
ref $saved->{"sources"}{$role} eq "ARRAY"
Truth table33%1/3
A and B
A= $role =~ /\A[a-zA-Z0-9_-]+\z/B= ref $saved->{"sources"}{$role} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 17 | for my $index (0 .. $#{$saved->{sources}{$role}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 17 | my $entry = $saved->{sources}{$role}[$index]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 17 | ▶ | die "Invalid project source\n" unless ref($entry) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 17 | my $source = $resolve->($entry->{path}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 17 | my $handle = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 17 | ▶ | die "Input type changed\n" if $entry->{directory} ? !-d $source : !-f $source; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 15 | $jobs->register_file($source); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 17 | ▶ | if ($handle) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 15 | $handle->{displayPath} = $jobs->resolve_grant($handle->{id}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 15 | ▶ | $jobs->{project_owned}{$handle->{id}} = 1 if $entry->{owned}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 15 | push @{$files{$role}}, $handle; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 2 | ▶ | else { push @missing, {role => $role, index => $index, path => $entry->{path}, directory => $entry->{directory} || JSON::XS::false} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$entry->{'directory'} || &JSON::XS::false()
MC/DC0%0/2
$entry->{'directory'} || &JSON::XS::false()
$entry->{'directory'}
&JSON::XS::false()
Truth table33%1/3
A || B
A= $entry->{'directory'}B= &JSON::XS::false()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | my %result = (file => $jobs->register_file($file), settings => $saved->{settings}, files => \%files, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 6 | ▶ | missing => \@missing, runs => $saved->{runs} || [], mappingDirty => $saved->{mappingDirty} || JSON::XS::false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition60%3/5
$saved->{'runs'} || []
$saved->{'mappingDirty'} || &JSON::XS::false()
MC/DC0%0/1
$saved->{'runs'} || []
$saved->{'runs'}
MC/DC0%0/2
$saved->{'mappingDirty'} || &JSON::XS::false()
$saved->{'mappingDirty'}
&JSON::XS::false()
Truth table50%1/2
A
A= $saved->{'runs'}
Truth table66%2/3
A || B
A= $saved->{'mappingDirty'}B= &JSON::XS::false()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 6 | $result{file}{displayPath} = $jobs->resolve_grant($result{file}{id}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 6 | for my $part (qw(jsonInput mapping)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 11 | ▶ | next unless $saved->{$part}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 11 | my $source = $resolve->($saved->{$part}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # Project-owned text is required: silently dropping it would lose work. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 11 | ▶ | die "Missing project data: $saved->{$part}. Restore the companion .cpheno.data folder.\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
-f $source and not -l $source and -s $source <= 104857600
-f $source and not -l $source
MC/DC33%1/3
-f $source and not -l $source and -s $source <= 104857600
-f $source
not -l $source
-s $source <= 104857600
Truth table50%2/4
A and not(B) and C
A= -f $sourceB= not -l $sourceC= -s $source <= 104857600
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | unless -f $source && !-l $source && -s $source <= 104857600; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 10 | $result{$part} = path($source)->slurp_utf8; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 5 | ▶ | if ($saved->{destination}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 5 | $result{destination} = eval {$jobs->register_file($resolve->($saved->{destination}))}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 5 | ▶ | $result{destination}{displayPath} = $jobs->resolve_grant($result{destination}{id}) if $result{destination}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 5 | ▶ | push @missing, {role => 'destination', path => $saved->{destination}, directory => JSON::XS::true} unless $result{destination}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 5 | return \%result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||