api/perl/json_bridge.pl

filter: Statementstmt 85.9% 55 / 64 Branchbran 53.8% 14 / 26 Conditioncond 38.8% 7 / 18 MC/DCmcdc 10.0% 1 / 10 Subroutinesub 90.0% 9 / 10 Podpod n/a totaltotal 67.1% 86 / 128 CC 3 SCAR 13.2
CC
3
Cov
70%
fail_service
12.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.8
« lib/Convert/Pheno/CDISC/ODM/V1.pm ↑ Summary lib/Convert/Pheno/Sink/FileSet.pm »
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
l!l
00
$code || 'infrastructure_error'
l!l
00
MC/DC0%0/1
$status || 500
$status
MC/DC0%0/1
$code || 'infrastructure_error'
$code
Truth table0%0/2
A
A= $status
Aresult
11
00
Truth table0%0/2
A
A= $code
Aresult
11
00
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
BranchTrueFalseTotal
unless defined $raw and $raw =~ /\S/ 0 6 6
Condition33%1/3
defined $raw and $raw =~ /\S/
!ll&&!rl&&r
006
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/
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if $@ 1 5 6
46 5 ▶fail_legacy('JSON payload must decode to an object')
Branch: 1 branch
BranchTrueFalseTotal
unless ref $payload eq "HASH" 0 5 5
47 unless ref $payload eq 'HASH';
48  
49 5 ▶my $action = $payload->{action} || q{};
Condition50%1/2
$payload->{'action'} || ''
l!l
05
MC/DC0%0/1
$payload->{'action'} || ''
$payload->{'action'}
Truth table50%1/2
A
A= $payload->{'action'}
Aresult
11
00
50 5 ▶if ( !$action ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($action) 5 0 5
51 5 my $method = $payload->{method};
52 5 ▶ fail_legacy("Payload must include string field 'method'")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $method and not ref $method and length $method 1 4 5
Condition66%4/6
defined $method and not ref $method and length $method
!ll&&!rl&&r
104
defined $method and not ref $method
!ll&&!rl&&r
104
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
ABCresult
0XX0
10X0
1100
1111
53 unless defined $method && !ref($method) && length($method);
54 4 ▶ fail_legacy("Unsupported conversion <$method>")
Branch: 1 branch
BranchTrueFalseTotal
unless is_public_conversion($method) 2 2 4
55 unless is_public_conversion($method);
56 }
57 2 my $result = eval {
58 2 ▶ return health() if $action eq 'health';
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "health" 0 2 2
59 2 ▶ return catalog() if $action eq 'catalog';
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "catalog" 0 2 2
60 return execute( $payload->{conversion}, $payload->{request} )
61 2 ▶ if $action eq 'execute';
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "execute" 0 2 2
62 2 ▶ if ( !$action && is_public_conversion( $payload->{method} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $action and is_public_conversion($payload->{"method"})) 2 0 2
Condition33%1/3
not $action and is_public_conversion($payload->{"method"})
!ll&&!rl&&r
002
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"})
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (my $error = $@) 0 2 2
71 0 ▶ fail_legacy($error) unless $action;
Branch: 1 branch
BranchTrueFalseTotal
unless $action 0 0 0
72 0 ▶ if ( is_service_error($error) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_service_error($error)) 0 0 0
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);
« lib/Convert/Pheno/CDISC/ODM/V1.pm ↑ Summary lib/Convert/Pheno/Sink/FileSet.pm »