Emulate/PSGI.pm

filter: Statementstmt 100% 47 / 47 Branchbran 50.0% 3 / 6 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 12 / 12 Podpod 100% 2 / 2 totaltotal 95.8% 69 / 72 CC 5 SCAR 6.3
CC
5
Cov
95%
emulate_environment
4.0
__ANON__
2.0
handler
1.0
CRAP 1.9
« Parse/PSGI.pm ↑ Summary
1 package CGI::Emulate::PSGI;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use CGI::Parse::PSGI;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use POSIX 'SEEK_SET';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use IO::File ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use SelectSaver;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 our $VERSION = '0.23';
12  
13 4 ▶sub handler {
Subroutine handler: called CC=1 SCAR=0.0
Pod documented
14 4 my ($class, $code, ) = @_;
15  
16 5 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
17 5 my $env = shift;
18  
19 5 my $stdout = IO::File->new_tmpfile;
20  
21 {
22 5 my $saver = SelectSaver->new("::STDOUT");
23 {
24 5 local %ENV = (%ENV, $class->emulate_environment($env));
25  
26 5 local *STDIN = $env->{'psgi.input'};
27 5 local *STDOUT = $stdout;
28 5 local *STDERR = $env->{'psgi.errors'};
29  
30 5 $code->();
31 }
32 }
33  
34 5 ▶ seek( $stdout, 0, SEEK_SET )
Branch: 1 branch
BranchTrueFalseTotal
seek $stdout, 0, 0 or croak("Can't seek stdout handle: $!") 5 0 5
35 or croak("Can't seek stdout handle: $!");
36  
37 5 return CGI::Parse::PSGI::parse_cgi_output($stdout);
38 4 };
39 }
40  
41 5 ▶sub emulate_environment {
Subroutine emulate_environment: called CC=4 SCAR=14.0
Pod documented
42 5 my($class, $env) = @_;
43  
44 5 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 my $environment = {
46 GATEWAY_INTERFACE => 'CGI/1.1',
47 HTTPS => ( ( $env->{'psgi.url_scheme'} eq 'https' ) ? 'ON' : 'OFF' ),
48 SERVER_SOFTWARE => "CGI-Emulate-PSGI",
49 REMOTE_ADDR => '127.0.0.1',
50 REMOTE_HOST => 'localhost',
51 REMOTE_PORT => int( rand(64000) + 1000 ), # not in RFC 3875
52 # REQUEST_URI => $uri->path_query, # not in RFC 3875
53 5 ▶ ( map { $_ => $env->{$_} } grep { !/^psgix?\./ && $_ ne "HTTP_PROXY" } keys %$env )
Branch: 1 branch
BranchTrueFalseTotal
$env->{'psgi.url_scheme'} eq 'https' ? : 0 5 5
Condition100%3/3
!/^psgix?\./ && $_ ne 'HTTP_PROXY'
!ll&&!rl&&r
10111
MC/DC100%2/2
!/^psgix?\./ && $_ ne 'HTTP_PROXY'
!/^psgix?\./ $_ ne 'HTTP_PROXY'
Truth table100%3/3
not(A) && B
A= !/^psgix?\./B= $_ ne 'HTTP_PROXY'
ABresult
0X0
100
111
54 };
55  
56 5 ▶ return wantarray ? %$environment : $environment;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 5 0 5
57 }
58  
59 5 1;
60 __END__
« Parse/PSGI.pm ↑ Summary