| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use FindBin qw($Bin); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use lib "$Bin/../../lib"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use JSON::XS; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use Convert::Pheno; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use Convert::Pheno::HTTP::Service qw(catalog execute health is_service_error); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use Convert::Pheno::Operations qw(is_public_conversion); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | binmode STDIN, ':raw'; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | binmode STDOUT, ':raw'; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | binmode STDERR, ':encoding(UTF-8)'; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 6 | my $raw = do { local $/; <STDIN> }; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 6 | my $json = JSON::XS->new->canonical; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub fail_service { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fail_service: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | my ( $message, $status, $code ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | chomp $message; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | print STDOUT $json->encode( | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/4
$status || 500
$code || 'infrastructure_error'
MC/DC0%0/1
$status || 500
$status
MC/DC0%0/1
$code || 'infrastructure_error'
$code
Truth table0%0/2
A
A= $status
Truth table0%0/2
A
A= $code
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | { | ||||||||||||||||||||||||||||||||||||||||||
| 24 | ok => JSON::XS::false, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | error => { | ||||||||||||||||||||||||||||||||||||||||||
| 26 | status => $status || 500, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | code => $code || 'infrastructure_error', | ||||||||||||||||||||||||||||||||||||||||||
| 28 | message => $message, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 4 | ▶ | sub fail_legacy { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fail_legacy: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 4 | my ($message) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 4 | chomp $message; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 4 | print STDERR $message, "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 4 | exit 1; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 6 | ▶ | fail_legacy('Expected JSON payload on STDIN') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $raw and $raw =~ /\S/
MC/DC0%0/2
defined $raw and $raw =~ /\S/
defined $raw
$raw =~ /\S/
Truth table33%1/3
A and B
A= defined $rawB= $raw =~ /\S/
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | unless defined $raw && $raw =~ /\S/; | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 6 | my $payload = eval { $json->decode($raw) }; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 6 | ▶ | fail_legacy("Invalid JSON payload: $@") if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 5 | ▶ | fail_legacy('JSON payload must decode to an object') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | unless ref $payload eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 5 | ▶ | my $action = $payload->{action} || q{}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$payload->{'action'} || ''
MC/DC0%0/1
$payload->{'action'} || ''
$payload->{'action'}
Truth table50%1/2
A
A= $payload->{'action'}
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 5 | ▶ | if ( !$action ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 5 | my $method = $payload->{method}; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 5 | ▶ | fail_legacy("Payload must include string field 'method'") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $method and not ref $method and length $method
defined $method and not ref $method
MC/DC33%1/3
defined $method and not ref $method and length $method
defined $method
not ref $method
length $method
Truth table50%2/4
A and not(B) and C
A= defined $methodB= not ref $methodC= length $method
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | unless defined $method && !ref($method) && length($method); | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 4 | ▶ | fail_legacy("Unsupported conversion <$method>") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | unless is_public_conversion($method); | ||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | my $result = eval { | |||||||||||||||||||||||||||||||||||||||||
| 58 | 2 | ▶ | return health() if $action eq 'health'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 2 | ▶ | return catalog() if $action eq 'catalog'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | return execute( $payload->{conversion}, $payload->{request} ) | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | ▶ | if $action eq 'execute'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | ▶ | if ( !$action && is_public_conversion( $payload->{method} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $action and is_public_conversion($payload->{"method"})
MC/DC0%0/2
not $action and is_public_conversion($payload->{"method"})
not $action
is_public_conversion($payload->{"method"})
Truth table33%1/3
not(A) and B
A= not $actionB= is_public_conversion($payload->{"method"})
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | my $method = $payload->{method}; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 2 | my $convert = Convert::Pheno->new($payload); | |||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | return $convert->$method(); | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | die "Unsupported bridge action <$action>"; | |||||||||||||||||||||||||||||||||||||||||
| 68 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | ▶ | if ( my $error = $@ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | fail_legacy($error) unless $action; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if ( is_service_error($error) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | fail_service( $error->message, $error->status, $error->code ); | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | fail_service( 'The Perl conversion service failed unexpectedly', 500, | |||||||||||||||||||||||||||||||||||||||||
| 76 | 'infrastructure_error' ); | ||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | print STDOUT $json->encode($result); | |||||||||||||||||||||||||||||||||||||||||