Loading ...
Sorry, an error occurred while loading the content.

PerlSetupEnv and CGI.pm

Expand Messages
  • Bill Moseley
    With PerlSetupEnv OFF $cgi- param( foo ) returns undef. I m sure this is suppose to work, so I m wondering what I m doing wrong. CGI.pm 3.04, mod_perl 1.29
    Message 1 of 3 , Jun 4, 2004
    • 0 Attachment
      With PerlSetupEnv OFF $cgi->param('foo') returns undef. I'm sure this
      is suppose to work, so I'm wondering what I'm doing wrong.

      CGI.pm 3.04, mod_perl 1.29

      Here's a test config with a small handler:


      ErrorLog error_log
      PidFile httpd.pid
      Listen *:5000
      #PerSetupEnv Off

      <perl>
      package test;
      use CGI;
      use Data::Dumper;
      sub handler {
      my $cgi = CGI->new;
      print $cgi->header('text/plain');
      print 'Param "foo" is [', $cgi->param('foo') || 'undefined', "]\n";
      print Dumper \%ENV;
      return Apache::Constants::OK();
      }
      </perl>

      NameVirtualHost *:5000
      <VirtualHost *:5000>
      DocumentRoot /home/moseley/apache
      ServerName localhost

      <Location />
      SetHandler perl-script
      PerlHandler test
      </Location>

      </VirtualHost>

      Now, this works:

      $ /usr/sbin/apache-perl -d $(pwd) -f $(pwd)/testcgi.conf -X &

      $ GET http://localhost:5000/?foo=bar
      Param "foo" is [bar]
      $VAR1 = {
      'SCRIPT_NAME' => '',
      'SERVER_NAME' => 'localhost',
      'SERVER_ADMIN' => '[no address given]',
      'PATH_INFO' => '/',
      'HTTP_CONNECTION' => 'TE, close',
      'REQUEST_METHOD' => 'GET',
      'SCRIPT_FILENAME' => '/home/moseley/apache',
      'SERVER_SOFTWARE' => 'Apache/1.3.31 (Debian GNU/Linux) PHP/4.3.4 mod_perl/1.29',
      'HTTP_TE' => 'deflate,gzip;q=0.3',
      'QUERY_STRING' => 'foo=bar',
      'REMOTE_PORT' => '34770',
      'HTTP_USER_AGENT' => 'lwp-request/2.06',
      'SERVER_SIGNATURE' => '',
      'SERVER_PORT' => '5000',
      'REMOTE_ADDR' => '127.0.0.1',
      'SERVER_PROTOCOL' => 'HTTP/1.1',
      'PATH' => '/home/moseley/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games',
      'REQUEST_URI' => '/?foo=bar',
      'GATEWAY_INTERFACE' => 'CGI-Perl/1.1',
      'SERVER_ADDR' => '127.0.0.1',
      'DOCUMENT_ROOT' => '/home/moseley/apache',
      'PATH_TRANSLATED' => '/home/moseley/apache/',
      'HTTP_HOST' => 'localhost:5000',
      'UNIQUE_ID' => 'QMDDXMCoAQIAAE8dAak',
      'MOD_PERL' => 'mod_perl/1.29'
      };

      Now with PerlSetupEnv Off the parameter doesn't make it.


      moseley@bumby:~/apache$ GET http://localhost:5000/?foo=bar
      Param "foo" is [undefined]
      $VAR1 = {
      'PATH' => '/home/moseley/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games',
      'GATEWAY_INTERFACE' => 'CGI-Perl/1.1',
      'MOD_PERL' => 'mod_perl/1.29'
      };










      --
      Bill Moseley
      moseley@...


      --
      Report problems: http://perl.apache.org/bugs/
      Mail list info: http://perl.apache.org/maillist/modperl.html
      List etiquette: http://perl.apache.org/maillist/email-etiquette.html
    • Perrin Harkins
      ... Scripts using the CGI.pm module require PerlSetupEnv On because that module relies on a properly populated CGI environment table.
      Message 2 of 3 , Jun 4, 2004
      • 0 Attachment
        On Fri, 2004-06-04 at 14:49, Bill Moseley wrote:
        > With PerlSetupEnv OFF $cgi->param('foo') returns undef. I'm sure this
        > is suppose to work

        "Scripts using the CGI.pm module require PerlSetupEnv On because that
        module relies on a properly populated CGI environment table."

        http://perl.apache.org/docs/1.0/guide/performance.html#PerlSetupEnv_Off

        It doesn't use it very much, but it does use it. If you wanted to, you
        could probably change a few lines in CGI.pm and get it to work without
        %ENV populated.

        - Perrin


        --
        Report problems: http://perl.apache.org/bugs/
        Mail list info: http://perl.apache.org/maillist/modperl.html
        List etiquette: http://perl.apache.org/maillist/email-etiquette.html
      • Bill Moseley
        ... I read right past that! I thought I d used it before without problems and a quick look at CGI.pm showed: if ($meth=~/^(GET|HEAD)$/) { if ($MOD_PERL) {
        Message 3 of 3 , Jun 4, 2004
        • 0 Attachment
          On Fri, Jun 04, 2004 at 03:05:36PM -0400, Perrin Harkins wrote:
          > On Fri, 2004-06-04 at 14:49, Bill Moseley wrote:
          > > With PerlSetupEnv OFF $cgi->param('foo') returns undef. I'm sure this
          > > is suppose to work
          >
          > "Scripts using the CGI.pm module require PerlSetupEnv On because that
          > module relies on a properly populated CGI environment table."

          I read right past that! I thought I'd used it before without problems
          and a quick look at CGI.pm showed:

          if ($meth=~/^(GET|HEAD)$/) {
          if ($MOD_PERL) {
          $query_string = $self->r->args;

          so I expected it would work to get the args.

          > It doesn't use it very much, but it does use it. If you wanted to, you
          > could probably change a few lines in CGI.pm and get it to work without
          > %ENV populated.

          It's for an example script that can be run as a mod_perl handler or as a CGI
          script, so it's handy to use CGI.pm. I'll just note that PerlSetupEnv
          must be on in the docs.




          >
          > - Perrin
          >
          >

          --
          Bill Moseley
          moseley@...


          --
          Report problems: http://perl.apache.org/bugs/
          Mail list info: http://perl.apache.org/maillist/modperl.html
          List etiquette: http://perl.apache.org/maillist/email-etiquette.html
        Your message has been successfully submitted and would be delivered to recipients shortly.