AWSLambda/Response.pm

filter: Statementstmt 92.3% 36 / 39 Branchbran 50.0% 1 / 2 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 1 totaltotal 82.4% 47 / 57 CC 5 SCAR 10.1
CC
5
Cov
87%
output
5.3
__ANON__
2.0
BEGIN
1.0
CRAP 2.7
« AWSLambda/Request.pm ↑ Summary
1 package Mojo::Server::AWSLambda::Response;
2  
3 2 ▶use Mojo::Base 'Mojo::Message::Response';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Mojo::JSON qw(decode_json encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use JSON::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶sub output {
Subroutine output: called CC=5 SCAR=16.7
Pod undocumented
12 1 my $self = shift;
13  
14 1 ▶ my $status = $self->code || 404;
Condition50%1/2
$self->code || 404
l!l
10
MC/DC0%0/1
$self->code || 404
$self->code
Truth table50%1/2
A
A= $self->code
Aresult
11
00
15 1 my $headers = $self->headers->to_hash;
16 1 my $body = $self->body;
17  
18 1 my $singleValueHeaders = {};
19 1 my $multiValueHeaders = {};
20 1 foreach my $header (keys %{$headers}) {
21 1 $singleValueHeaders->{lc $header} = $headers->{$header};
22 1 ▶ push @{$multiValueHeaders->{lc $header} //= []}, $headers->{$header};
Condition50%1/2
$$multiValueHeaders{lc $header} //= []
l!l
01
MC/DC0%0/1
$$multiValueHeaders{lc $header} //= []
$$multiValueHeaders{lc $header}
Truth table50%1/2
A
A= $$multiValueHeaders{lc $header}
Aresult
11
00
23 }
24  
25 1 my $type = $singleValueHeaders->{'content-type'};
26 1 my $isBase64Encoded = $type !~ m(^text/.*|application/(:?json|javascript|xml))i;
27 1 ▶ if ($isBase64Encoded) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isBase64Encoded) { } 0 1 1
28 0 $body = encode_base64 $body, '';
29 }
30 else {
31 1 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
32 1 decode_utf8($body, Encode::FB_CROAK | Encode::LEAVE_SRC);
33 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
34 0 $isBase64Encoded = 1;
35 0 $body = encode_base64 $body, '';
36 1 };
37 }
38  
39 return +{
40 1 isBase64Encoded => bool $isBase64Encoded,
41 headers => $singleValueHeaders,
42 multiValueHeaders => $multiValueHeaders,
43 statusCode => number $status,
44 body => string $body,
45 }
46 }
47  
48 2 1;
« AWSLambda/Request.pm ↑ Summary