Subject: | CGI::blockquote('foo') clobbers <STDIN> |
Hi!
CGI::blockquote('foo') calls CGI::self_or_default(...), which calls
CGI::new(), which clobbers STDIN. So if I do a `my $q=new CGI()'
afterwards, all my HTTP POST data is lost (since it has to arrive on STDIN).
There is no problem with CGI->blockquote('foo'), which calls
CGI::self_or_default(...), which doesn't call CGI::new().
I think this is a bug in CGI.pm, because CGI::blockquote('foo') and
CGI->blockquote('foo') should do the same thing (and leave Perl in the
same state).
One solution would be to never call CGI::new:
sub CGI::self_or_default {
return @_ if defined($_[0]) && (!ref($_[0])) &&($_[0] eq 'CGI');
my $Q=$_[0]; #### pts #### Dat: not permanent
unless (defined($Q) &&
(ref($Q) eq 'CGI' || UNIVERSAL::isa($Q,'CGI')) # slightly optimized
for common case
) {
#$Q = $CGI::DefaultClass->new unless defined($Q);
$Q=$CGI::DefaultClass; #### pts ####
unshift(@_,$Q);
}
return wantarray ? @_ : $Q;
}
Another solution would be to ignore STDIN in $Q:
sub CGI::self_or_default {
return @_ if defined($_[0]) && (!ref($_[0])) &&($_[0] eq 'CGI');
my $Q=$_[0]; #### pts #### Dat: not permanent
unless (defined($Q) &&
(ref($Q) eq 'CGI' || UNIVERSAL::isa($Q,'CGI')) # slightly optimized
for common case
) {
#$Q = $CGI::DefaultClass->new unless defined($Q);
$Q = $CGI::DefaultClass->new('') unless defined($Q); #### pts ####
unshift(@_,$Q);
}
return wantarray ? @_ : $Q;
}
Best regards,
Péter Szabó