blib/lib/Limper/Engine/PSGI.pm

filter: Statementstmt 94.1% 48 / 51 Branchbran 31.2% 5 / 16 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 1 totaltotal 75.6% 59 / 78 SCAR 28.0
CC
14
Cov
77%
__ANON__
12.0
get_psgi
9.3
__ANON__
5.3
CRAP 16.4
↑ Summary
1 package Limper::Engine::PSGI;
2 2 $Limper::Engine::PSGI::VERSION = '0.001';
3 2 ▶use base 'Limper';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 package Limper;
9 2 $Limper::VERSION = '0.001';
10 sub get_psgi {
11 3 ▶ my ($env) = @_;
Subroutine get_psgi: called CC=9 SCAR=22.3
Pod undocumented
12  
13 3 delete response->{$_} for keys %{&response};
14 3 response->{headers} = [];
15  
16 3 delete request->{$_} for keys %{&request};
17 3 request->{method} = $env->{REQUEST_METHOD};
18 3 request->{uri} = $env->{REQUEST_URI};
19 3 request->{version} = $env->{SERVER_PROTOCOL};
20 3 request->{remote_host} = $env->{REMOTE_HOST};
21 3 request->{headers} = [];
22 3 request->{hheaders} = {};
23  
24 3 ▶ push @{request->{headers}}, 'content-length', $env->{CONTENT_LENGTH} if exists $env->{CONTENT_LENGTH};
Branch: 1 branch
BranchTrueFalseTotal
if exists $env->{"CONTENT_LENGTH"} 3 0 3
25 3 ▶ push @{request->{headers}}, 'content-type', $env->{CONTENT_TYPE} if exists $env->{CONTENT_TYPE};
Branch: 1 branch
BranchTrueFalseTotal
if exists $env->{"CONTENT_TYPE"} 0 3 3
26 3 for my $header (grep { /^HTTP_/ } keys %$env) {
27 3 my $name = lc $header;
28 3 $name =~ s/^http_//;
29 3 $name =~ s/_/-/g;
30 3 my @values = split /, /, $env->{$header};
31 3 push @{request->{headers}}, $name, $_ for @values;
32 3 ▶ request->{hheaders}{$name} = @values > 1 ? \@values : $values[0];
Branch: 1 branch
BranchTrueFalseTotal
@values > 1 ? : 0 3 3
33 }
34 # this covers both requests with Content-Length: <INT> and Tranfer-Encoding: chunked
35 3 ▶ $env->{'psgi.input'}->read(request->{body}, $env->{CONTENT_LENGTH}) if exists $env->{CONTENT_LENGTH};
Branch: 1 branch
BranchTrueFalseTotal
if exists $env->{"CONTENT_LENGTH"} 3 0 3
36 }
37  
38 hook request_handler => sub {
39 3 ▶ eval {
Subroutine __ANON__: called CC=4 SCAR=16.6
40 3 get_psgi @_;
41 3 $_ = handle_request;
42 };
43 3 ▶ return $_ unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 0 3 3
44 3 warning $@;
45 3 status 500;
46 3 ▶ response->{body} = options->{debug} // 0 ? $@ : 'Internal Server Error';
Branch: 1 branch
BranchTrueFalseTotal
options()->{'debug'} // 0 ? : 0 0 0
Condition0%0/2
options()->{"debug"} // 0
l!l
00
MC/DC0%0/1
options()->{"debug"} // 0
options()->{"debug"}
Truth table0%0/2
A
A= options()->{"debug"}
Aresult
11
00
47 0 send_response;
48 2 };
49  
50 hook response_handler => sub {
51 [
52 response->{status},
53 response->{headers},
54 0 ▶ defined response->{body} ? (ref response->{body} ? response->{body} : [response->{body}]) : [],
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 2 branches
BranchTrueFalseTotal
defined response()->{'body'} ? : 0 0 0
ref response()->{'body'} ? : 0 0 0
55 ];
56 2 };
57  
58 2 1;
59  
60 =for Pod::Coverage get_psgi
61  
62 =head1 NAME
63  
64 Limper::Engine::PSGI - PSGI engine for Limper
65  
66 =head1 VERSION
67  
68 version 0.001
69  
70 =head1 SYNOPSIS
71  
72 use Limper::Engine::PSGI; # all you need to do is add this line
73 use Limper; # this must come after all extensions
74  
75 # routes and whatnot
76  
77 limp;
78  
79 =head1 DESCRIPTION
80  
81 B<Limper::Engine::PSGI> extends L<Limper> to use L<PSGI> instead of the built-in web
82 server.
83  
84 All you need to do in order to use L<PSGI> is add C<use Limper::Engine::PSGI;>
85 somewhere before C<use Limper;> in your app.
86  
87 This package sets a B<request_handler> and B<response_handler> for
88 L<Limper>, as well as defining a non-exportable sub that turns a PSGI
89 request into one that B<Limper> understands.
90  
91 Note that unlike other hooks, only the first B<request_handler> and
92 B<response_handler> is used, so care should be taken to load this first and
93 not load something else that also expects to make use of these hooks.
94  
95 =head1 EXPORTS
96  
97 Nothing additional is exported.
98  
99 =head1 COPYRIGHT AND LICENSE
100  
101 Copyright (C) 2014 by Ashley Willis E<lt>ashley+perl@gitable.orgE<gt>
102  
103 This library is free software; you can redistribute it and/or modify
104 it under the same terms as Perl itself, either Perl version 5.12.4 or,
105 at your option, any later version of Perl 5 you may have available.
106  
107 =head1 SEE ALSO
108  
109 L<Limper>
110  
111 L<Limper::SendFile>
112  
113 L<Limper::SendJSON>
114  
115 L<PSGI>
116  
117 L<Plack>
118  
119 L<Starman>
120  
121 L<The uWSGI project|https://uwsgi-docs.readthedocs.org/en/latest/>
122  
123 =cut
↑ Summary