K
kj
Here's the problem. I'm trying to test some code that uses CGI.pm,
running on Linux. I want to do this "locally", without involving
an HTTP server (Apache, etc.).
Each of the intended tests will result in the execution of the
following code from CGI.pm:
read(\*STDIN, $$buff, $len, $offset);
I want the input that is read by this line to come from a scalar
variable (a different one for each test). But I can't get CGI to
read different inputs each time.
The following snippet illustrates the problem:
use CGI ();
sub test {
my $in = shift;
$ENV{ REQUEST_METHOD } = 'POST';
$ENV{ CONTENT_TYPE } = 'text/plain';
$ENV{ CONTENT_LENGTH } = length $in;
close STDIN;
open STDIN, '<', \$in or die $!;
print CGI->new->param( 'POSTDATA' ), "\n";
}
test( 'foo' );
test( 'bar' );
__END__
foo
foo
As you can see, the first call to test() produces the required
output, but the second one doesn't. In fact all calls to test()
will produce the same output as the first one does.
Can anyone suggest a way in which I could, within the execution of
a single script, give CGI different inputs via STDIN?
TIA!
Kynn Jones
running on Linux. I want to do this "locally", without involving
an HTTP server (Apache, etc.).
Each of the intended tests will result in the execution of the
following code from CGI.pm:
read(\*STDIN, $$buff, $len, $offset);
I want the input that is read by this line to come from a scalar
variable (a different one for each test). But I can't get CGI to
read different inputs each time.
The following snippet illustrates the problem:
use CGI ();
sub test {
my $in = shift;
$ENV{ REQUEST_METHOD } = 'POST';
$ENV{ CONTENT_TYPE } = 'text/plain';
$ENV{ CONTENT_LENGTH } = length $in;
close STDIN;
open STDIN, '<', \$in or die $!;
print CGI->new->param( 'POSTDATA' ), "\n";
}
test( 'foo' );
test( 'bar' );
__END__
foo
foo
As you can see, the first call to test() produces the required
output, but the second one doesn't. In fact all calls to test()
will produce the same output as the first one does.
Can anyone suggest a way in which I could, within the execution of
a single script, give CGI different inputs via STDIN?
TIA!
Kynn Jones