line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Emulate::PSGI; |
2
|
5
|
|
|
5
|
|
104259
|
use strict; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
143
|
|
3
|
5
|
|
|
5
|
|
24
|
use warnings; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
135
|
|
4
|
5
|
|
|
5
|
|
1490
|
use CGI::Parse::PSGI; |
|
5
|
|
|
|
|
21
|
|
|
5
|
|
|
|
|
312
|
|
5
|
5
|
|
|
5
|
|
2562
|
use POSIX 'SEEK_SET'; |
|
5
|
|
|
|
|
26605
|
|
|
5
|
|
|
|
|
35
|
|
6
|
5
|
|
|
5
|
|
6838
|
use IO::File (); |
|
5
|
|
|
|
|
23
|
|
|
5
|
|
|
|
|
96
|
|
7
|
5
|
|
|
5
|
|
22
|
use SelectSaver; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
112
|
|
8
|
5
|
|
|
5
|
|
22
|
use Carp qw(croak); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
192
|
|
9
|
5
|
|
|
5
|
|
108
|
use 5.008001; |
|
5
|
|
|
|
|
19
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.23'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub handler { |
14
|
4
|
|
|
4
|
1
|
121
|
my ($class, $code, ) = @_; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
return sub { |
17
|
5
|
|
|
5
|
|
4191
|
my $env = shift; |
18
|
|
|
|
|
|
|
|
19
|
5
|
|
|
|
|
1038
|
my $stdout = IO::File->new_tmpfile; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
{ |
22
|
5
|
|
|
|
|
21
|
my $saver = SelectSaver->new("::STDOUT"); |
|
5
|
|
|
|
|
48
|
|
23
|
|
|
|
|
|
|
{ |
24
|
5
|
|
|
|
|
153
|
local %ENV = (%ENV, $class->emulate_environment($env)); |
|
5
|
|
|
|
|
66
|
|
25
|
|
|
|
|
|
|
|
26
|
5
|
|
|
|
|
31
|
local *STDIN = $env->{'psgi.input'}; |
27
|
5
|
|
|
|
|
67
|
local *STDOUT = $stdout; |
28
|
5
|
|
|
|
|
15
|
local *STDERR = $env->{'psgi.errors'}; |
29
|
|
|
|
|
|
|
|
30
|
5
|
|
|
|
|
19
|
$code->(); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
5
|
50
|
|
|
|
5324
|
seek( $stdout, 0, SEEK_SET ) |
35
|
|
|
|
|
|
|
or croak("Can't seek stdout handle: $!"); |
36
|
|
|
|
|
|
|
|
37
|
5
|
|
|
|
|
36
|
return CGI::Parse::PSGI::parse_cgi_output($stdout); |
38
|
4
|
|
|
|
|
24
|
}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub emulate_environment { |
42
|
5
|
|
|
5
|
1
|
16
|
my($class, $env) = @_; |
43
|
|
|
|
|
|
|
|
44
|
5
|
|
|
5
|
|
31
|
no warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
744
|
|
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
|
50
|
|
|
|
142
|
( map { $_ => $env->{$_} } grep { !/^psgix?\./ && $_ ne "HTTP_PROXY" } keys %$env ) |
|
11
|
100
|
|
|
|
64
|
|
|
22
|
|
|
|
|
153
|
|
54
|
|
|
|
|
|
|
}; |
55
|
|
|
|
|
|
|
|
56
|
5
|
50
|
|
|
|
285
|
return wantarray ? %$environment : $environment; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
__END__ |