[Pdx-pm] testing simulated CGI input

Randall Hansen randall at sonofhans.net
Sun Sep 12 19:56:41 CDT 2004

On Sep 12, 2004, at 11:17 AM, <publiustemp-pdxpm at yahoo.com> wrote:

> why not just call the script directly and have the query string 
> embedded in the script?

ok, i finally got this to work.  the solution was interesting to me so 
i thought i'd share it with the list.  those already in-the-know, 
forgive me.

ovid's suggestion* worked fine served by apache, but not at all from 
the command line.  that's a problem, since this code is for a suite of 
automated tests.  i poked around in CGI.pm a bit and saw that it 
doesn't parse $ENV{ QUERY_STRING } at all unless $ENV{ REQUEST_METHOD } 
is 'GET' or 'HEAD'.

here's the working test code.  if you remove the line setting $ENV{ 
REQUEST_METHOD } it gives no output.

     use warnings;
     use strict;

     use CGI;

     $ENV{ QUERY_STRING } = 'number=3172';

     my $cgi = CGI->new;
     print $cgi->param( 'number' );


*no criticism of ovid's advice is intended.  i wrote my question late 
at night and pry could have been clearer.  and anyway, it made me open 
up CGI.pm, which was cool.

More information about the Pdx-pm-list mailing list