line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Emulate::PSGI; |
2
|
3
|
|
|
3
|
|
100495
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
101
|
|
3
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
2
|
|
|
3
|
|
|
|
|
104
|
|
4
|
3
|
|
|
3
|
|
1552
|
use CGI::Parse::PSGI; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
179
|
|
5
|
3
|
|
|
3
|
|
1792
|
use POSIX 'SEEK_SET'; |
|
3
|
|
|
|
|
15796
|
|
|
3
|
|
|
|
|
16
|
|
6
|
3
|
|
|
3
|
|
3327
|
use IO::File (); |
|
3
|
|
|
|
|
26
|
|
|
3
|
|
|
|
|
50
|
|
7
|
3
|
|
|
3
|
|
16
|
use SelectSaver; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
65
|
|
8
|
3
|
|
|
3
|
|
10
|
use Carp qw(croak); |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
120
|
|
9
|
3
|
|
|
3
|
|
66
|
use 5.008001; |
|
3
|
|
|
|
|
8
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.21'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub handler { |
14
|
2
|
|
|
2
|
1
|
42
|
my ($class, $code, ) = @_; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
return sub { |
17
|
2
|
|
|
2
|
|
956
|
my $env = shift; |
18
|
|
|
|
|
|
|
|
19
|
2
|
|
|
|
|
470
|
my $stdout = IO::File->new_tmpfile; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
{ |
22
|
2
|
|
|
|
|
4
|
my $saver = SelectSaver->new("::STDOUT"); |
|
2
|
|
|
|
|
14
|
|
23
|
|
|
|
|
|
|
{ |
24
|
2
|
|
|
|
|
41
|
local %ENV = (%ENV, $class->emulate_environment($env)); |
|
2
|
|
|
|
|
23
|
|
25
|
|
|
|
|
|
|
|
26
|
2
|
|
|
|
|
13
|
local *STDIN = $env->{'psgi.input'}; |
27
|
2
|
|
|
|
|
4
|
local *STDOUT = $stdout; |
28
|
2
|
|
|
|
|
4
|
local *STDERR = $env->{'psgi.errors'}; |
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
|
|
41
|
$code->(); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
2
|
50
|
|
|
|
2408
|
seek( $stdout, 0, SEEK_SET ) |
35
|
|
|
|
|
|
|
or croak("Can't seek stdout handle: $!"); |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
10
|
return CGI::Parse::PSGI::parse_cgi_output($stdout); |
38
|
2
|
|
|
|
|
16
|
}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub emulate_environment { |
42
|
2
|
|
|
2
|
1
|
4
|
my($class, $env) = @_; |
43
|
|
|
|
|
|
|
|
44
|
3
|
|
|
3
|
|
13
|
no warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
416
|
|
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
|
2
|
50
|
|
|
|
71
|
( map { $_ => $env->{$_} } grep !/^psgix?\./, keys %$env ) |
|
5
|
|
|
|
|
26
|
|
54
|
|
|
|
|
|
|
}; |
55
|
|
|
|
|
|
|
|
56
|
2
|
50
|
|
|
|
112
|
return wantarray ? %$environment : $environment; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
__END__ |