line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Emulate::PSGI; |
2
|
5
|
|
|
5
|
|
100590
|
use strict; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
146
|
|
3
|
5
|
|
|
5
|
|
21
|
use warnings; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
149
|
|
4
|
5
|
|
|
5
|
|
1910
|
use CGI::Parse::PSGI; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
264
|
|
5
|
5
|
|
|
5
|
|
2338
|
use POSIX 'SEEK_SET'; |
|
5
|
|
|
|
|
21748
|
|
|
5
|
|
|
|
|
28
|
|
6
|
5
|
|
|
5
|
|
4055
|
use IO::File (); |
|
5
|
|
|
|
|
33
|
|
|
5
|
|
|
|
|
82
|
|
7
|
5
|
|
|
5
|
|
15
|
use SelectSaver; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
82
|
|
8
|
5
|
|
|
5
|
|
15
|
use Carp qw(croak); |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
204
|
|
9
|
5
|
|
|
5
|
|
86
|
use 5.008001; |
|
5
|
|
|
|
|
10
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.22'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub handler { |
14
|
4
|
|
|
4
|
1
|
86
|
my ($class, $code, ) = @_; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
return sub { |
17
|
5
|
|
|
5
|
|
3773
|
my $env = shift; |
18
|
|
|
|
|
|
|
|
19
|
5
|
|
|
|
|
911
|
my $stdout = IO::File->new_tmpfile; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
{ |
22
|
5
|
|
|
|
|
9
|
my $saver = SelectSaver->new("::STDOUT"); |
|
5
|
|
|
|
|
35
|
|
23
|
|
|
|
|
|
|
{ |
24
|
5
|
|
|
|
|
102
|
local %ENV = (%ENV, $class->emulate_environment($env)); |
|
5
|
|
|
|
|
51
|
|
25
|
|
|
|
|
|
|
|
26
|
5
|
|
|
|
|
36
|
local *STDIN = $env->{'psgi.input'}; |
27
|
5
|
|
|
|
|
11
|
local *STDOUT = $stdout; |
28
|
5
|
|
|
|
|
68
|
local *STDERR = $env->{'psgi.errors'}; |
29
|
|
|
|
|
|
|
|
30
|
5
|
|
|
|
|
14
|
$code->(); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
5
|
50
|
|
|
|
3239
|
seek( $stdout, 0, SEEK_SET ) |
35
|
|
|
|
|
|
|
or croak("Can't seek stdout handle: $!"); |
36
|
|
|
|
|
|
|
|
37
|
5
|
|
|
|
|
25
|
return CGI::Parse::PSGI::parse_cgi_output($stdout); |
38
|
4
|
|
|
|
|
29
|
}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub emulate_environment { |
42
|
5
|
|
|
5
|
1
|
8
|
my($class, $env) = @_; |
43
|
|
|
|
|
|
|
|
44
|
5
|
|
|
5
|
|
20
|
no warnings; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
646
|
|
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
|
|
|
|
127
|
( map { $_ => $env->{$_} } grep { !/^psgix?\./ && $_ ne "HTTP_PROXY" } keys %$env ) |
|
11
|
100
|
|
|
|
42
|
|
|
22
|
|
|
|
|
113
|
|
54
|
|
|
|
|
|
|
}; |
55
|
|
|
|
|
|
|
|
56
|
5
|
50
|
|
|
|
271
|
return wantarray ? %$environment : $environment; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
__END__ |