Emulate/PSGI.pm

filter: Statementstmt 100% 47 / 47 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 100% 2 / 2 totaltotal 95.6% 66 / 69 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.22';
12  
13 sub handler {
14 4 ▶ my ($class, $code, ) = @_;
Subroutine handler: called CC=1 SCAR=0.0
Pod documented
15  
16 return sub {
17 5 ▶ my $env = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
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: $!") 0 5 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 sub emulate_environment {
42 5 ▶ my($class, $env) = @_;
Subroutine emulate_environment: called CC=4 SCAR=14.0
Pod documented
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: 2 branches
BranchTrueFalseTotal
$env->{'psgi.url_scheme'} eq 'https' ? : 0 5 5
not /^psgix?\./ and $_ ne "HTTP_PROXY" 12 10 22
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