Ovid has asked for the wisdom of the Perl Monks concerning the following question:
To get around this, I try to read $ENV{'CONTENT_LENGTH'} amount of data from STDIN if the POST method is used. If read any data, I kill the program telling the user that they need to instantiate a new CGI object before they instantiate a debugging object. Here's the code:
My problem is that it seems like a very ugly hack. I'm really not testing to see if a CGI object already exists, I'm inferring its existence from the presense of data available in STDIN. Is there a clean way to determine if the user has already instantiated a CGI object (short of searching through the packages for one)?sub new { my $class = $_[0]; my $buffer; if ( $ENV{'REQUEST_METHOD'} eq 'POST' ) { read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } my $cgi = CGI->new(); if ( length $buffer ) { print $cgi->header( "text/plain" ) . "Data was read from STDIN while using the POST method.\n +" . "You must instantiate a new CGI::DebugVars object AFTER\ +n" . "instantiating a CGI object."; exit; } my $objref = { _active => 1, _border => 1, _continue => 0, _cgi => $cgi, _pretty_not_installed => 0 }; bless $objref, $class; return $objref; }
I'm also wondering if it's possible that other data may be available through STDIN in a CGI script? Since my routine reads that data, it will cause a problem for the end-user's code.
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just go the the link and check out our stats.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: CGI object already instantiated?
by Dominus (Parson) on Nov 13, 2000 at 00:36 UTC | |
by Ovid (Cardinal) on Nov 13, 2000 at 01:20 UTC | |
by Anonymous Monk on Nov 13, 2000 at 01:15 UTC | |
|
(tye)Re: CGI object already instantiated?
by tye (Sage) on Nov 13, 2000 at 00:32 UTC |