line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PAB3::Output::CGI; |
2
|
|
|
|
|
|
|
# ============================================================================= |
3
|
|
|
|
|
|
|
# Perl Application Builder |
4
|
|
|
|
|
|
|
# Module: PAB3::Output::CGI |
5
|
|
|
|
|
|
|
# TIEHANDLE for CGI output |
6
|
|
|
|
|
|
|
# ============================================================================= |
7
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
73
|
|
8
|
2
|
|
|
2
|
|
7
|
no strict 'refs'; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
48
|
|
9
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
72
|
|
10
|
2
|
|
|
2
|
|
8
|
no warnings 'untie', 'uninitialized'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
81
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
15
|
use vars qw($VERSION); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
125
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
BEGIN { |
15
|
2
|
50
|
|
2
|
|
9
|
if( ! $PAB3::CGI::VERSION ) { |
16
|
0
|
|
|
|
|
0
|
die '>> Please do not use PAB3::Output::CGI directly, use PAB3::CGI instead <<'; |
17
|
|
|
|
|
|
|
} |
18
|
2
|
|
|
|
|
1857
|
$VERSION = $PAB3::CGI::VERSION; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
1; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub TIEHANDLE { |
24
|
0
|
|
|
0
|
|
|
my $class = shift; |
25
|
0
|
|
|
|
|
|
bless [ @_ ], $class; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub HEADER_MODPERL { |
29
|
0
|
|
|
0
|
0
|
|
my( $key, $val ) = @_; |
30
|
0
|
0
|
|
|
|
|
if( $key eq 'content-type' ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
$GLOBAL::MPREQ->content_type( $val ); |
32
|
0
|
|
|
|
|
|
return 0; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
elsif( $key eq 'content-length' ) { |
35
|
0
|
0
|
|
|
|
|
goto hm_plain if $GLOBAL::MODPERL == 1; |
36
|
0
|
|
|
|
|
|
$GLOBAL::MPREQ->set_content_length( $val ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
elsif( $key eq 'status' ) { |
39
|
0
|
0
|
|
|
|
|
if( $val =~ m!\s*(\d+)\s+(.+)! ) { |
40
|
0
|
|
|
|
|
|
$GLOBAL::MPREQ->status( $1 ); |
41
|
0
|
|
|
|
|
|
$GLOBAL::MPREQ->status_line( $1 . ' ' . $2 ); |
42
|
0
|
0
|
|
|
|
|
return $1 >= 300 ? 0 : 1; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { |
45
|
0
|
|
|
|
|
|
$GLOBAL::MPREQ->status( $val ); |
46
|
0
|
0
|
|
|
|
|
return int( $val ) >= 300 ? 0 : 1; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
elsif( $key eq 'intredir' ) { |
50
|
0
|
|
|
|
|
|
$GLOBAL::MPREQ->internal_redirect( $val ); |
51
|
0
|
|
|
|
|
|
return 0; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
elsif( $key eq 'location' ) { |
54
|
0
|
|
|
|
|
|
$GLOBAL::MPREQ->status( 302 ); |
55
|
0
|
|
|
|
|
|
$GLOBAL::MPREQ->headers_out->set( 'location', $val ); |
56
|
0
|
|
|
|
|
|
$GLOBAL::MPREQ->print( "" ); |
57
|
0
|
|
|
|
|
|
return 0; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
else { |
60
|
0
|
|
|
|
|
|
hm_plain: |
61
|
|
|
|
|
|
|
$GLOBAL::MPREQ->headers_out->set( $key, $val ); |
62
|
|
|
|
|
|
|
} |
63
|
0
|
|
|
|
|
|
return 1; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub SENDHEADER { |
67
|
0
|
|
|
0
|
0
|
|
my( $needct, $key, $val, $ret ); |
68
|
0
|
|
|
|
|
|
untie *STDOUT; |
69
|
0
|
|
|
|
|
|
binmode STDOUT; |
70
|
0
|
0
|
|
|
|
|
if( $GLOBAL::MODPERL == 2 ) { |
|
|
0
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
if( $GLOBAL::MPREQ->handler() eq 'modperl' ) { |
72
|
0
|
|
|
|
|
|
tie *STDOUT, $GLOBAL::MPREQ; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
elsif( $GLOBAL::MODPERL == 1 ) { |
76
|
0
|
|
|
|
|
|
tie *STDOUT, $GLOBAL::MPREQ; |
77
|
|
|
|
|
|
|
} |
78
|
0
|
|
|
|
|
|
$needct = 1; |
79
|
0
|
0
|
|
|
|
|
if( $GLOBAL::MODPERL ) { |
80
|
0
|
|
|
|
|
|
foreach $key( keys %PAB3::CGI::HEAD ) { |
81
|
0
|
0
|
0
|
|
|
|
$needct = 0 if $needct && ($key eq 'content-type' || $key eq 'location'); |
|
|
|
0
|
|
|
|
|
82
|
0
|
0
|
|
|
|
|
if( ref( $PAB3::CGI::HEAD{$key} ) ) { |
83
|
0
|
|
|
|
|
|
foreach $val( @{$PAB3::CGI::HEAD{$key}} ) { |
|
0
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
$ret = &HEADER_MODPERL( $key, $val ); |
85
|
0
|
0
|
|
|
|
|
$needct = $ret if $needct; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
else { |
89
|
0
|
|
|
|
|
|
$ret = &HEADER_MODPERL( $key, $PAB3::CGI::HEAD{$key} ); |
90
|
0
|
0
|
|
|
|
|
$needct = $ret if $needct; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
else { |
95
|
0
|
0
|
|
|
|
|
if( ( $val = $PAB3::CGI::HEAD{'status'} ) ) { |
96
|
0
|
|
|
|
|
|
print "Status: $val\015\012"; |
97
|
0
|
0
|
|
|
|
|
$val = $val->[-1] if ref( $val ); |
98
|
0
|
0
|
|
|
|
|
if( $val =~ m!\s*(\d+)\s+! ) { |
99
|
0
|
0
|
0
|
|
|
|
$needct = 0 if $needct && $1 >= 300; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
else { |
102
|
0
|
0
|
0
|
|
|
|
$needct = 0 if $needct && int( $val ) >= 300; |
103
|
|
|
|
|
|
|
} |
104
|
0
|
|
|
|
|
|
delete $PAB3::CGI::HEAD{'status'}; |
105
|
|
|
|
|
|
|
} |
106
|
0
|
|
|
|
|
|
foreach $key( keys %PAB3::CGI::HEAD ) { |
107
|
0
|
0
|
0
|
|
|
|
$needct = 0 if $needct && ($key eq 'content-type' || $key eq 'location'); |
|
|
|
0
|
|
|
|
|
108
|
0
|
0
|
|
|
|
|
if( ref( $PAB3::CGI::HEAD{$key} ) ) { |
109
|
0
|
|
|
|
|
|
foreach( @{$PAB3::CGI::HEAD{$key}} ) { |
|
0
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
print $key . ': ' . $_ . "\015\012"; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
else { |
114
|
0
|
|
|
|
|
|
print $key . ': ' . $PAB3::CGI::HEAD{$key} . "\015\012"; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
0
|
0
|
|
|
|
|
if( $needct ) { |
119
|
0
|
|
0
|
|
|
|
$val = |
120
|
|
|
|
|
|
|
'text/html; charset: ' |
121
|
|
|
|
|
|
|
. ( $ENV{'CHARSET'} || 'iso-8859-1' ) |
122
|
|
|
|
|
|
|
; |
123
|
0
|
0
|
|
|
|
|
if( $GLOBAL::MODPERL ) { |
124
|
0
|
|
|
|
|
|
$GLOBAL::MPREQ->content_type( $val ); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
else { |
127
|
0
|
|
|
|
|
|
print 'content-type: ', $val, "\015\012"; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
} |
130
|
0
|
0
|
|
|
|
|
if( ! $GLOBAL::MODPERL ) { |
131
|
0
|
|
|
|
|
|
print "\015\012\015\012"; |
132
|
|
|
|
|
|
|
} |
133
|
0
|
|
|
|
|
|
$PAB3::CGI::HeaderDone = [ caller(2) ]; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub PRINT { |
137
|
0
|
|
|
0
|
|
|
my $self = shift; |
138
|
0
|
|
|
|
|
|
&SENDHEADER(); |
139
|
0
|
|
|
|
|
|
print @_; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub PRINTF { |
143
|
0
|
|
|
0
|
|
|
my $self = shift; |
144
|
0
|
|
|
|
|
|
&SENDHEADER(); |
145
|
0
|
|
|
|
|
|
printf @_; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
0
|
|
|
sub BINMODE { |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
0
|
|
|
sub CLOSE { |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
0
|
|
|
sub FILENO { |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
0
|
|
|
0
|
|
|
sub GETC { |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
0
|
|
|
0
|
|
|
sub OPEN { |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
0
|
|
|
0
|
|
|
sub READ { |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub WRITE { |
168
|
0
|
|
|
0
|
|
|
my $self = shift; |
169
|
0
|
|
|
|
|
|
&SENDHEADER(); |
170
|
0
|
|
|
|
|
|
write @_; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
__END__ |