voyager has asked for the wisdom of the Perl Monks concerning the following question:

(win32/NT)

The following script properly displays params (POST and GET) when run under as a normal cgi script. It also works when the "use XML::Simple" is commented out.

But when the "use XML::Simple" line is there (just the "use" ... not even calling any of its methods), POSTed parms don't show, and it sometimes takes two clicks on the "Link" for the that param to show.

Any idea what XML::Simple is doing to cause CGI to lose track of posted params?

#! /perl/bin/perl -w use strict; use CGI; use XML::Simple; use Data::Dumper; my $q = CGI->new; print $q->header, $q->start_html; print $q->a({href => $q->script_name . "?parm=value"}, "Link"); print $q->start_form , $q->textfield(-name => "field_name") , $q->submit(-name => 'button_name' ) , $q->end_form ; my @parms = $q->param; print $q->pre(Dumper \@parms); print $q->end_html;

Replies are listed 'Best First'.
Re: XML::Simple breaks CGI under mod_perl
by LukeyBoy (Friar) on Feb 03, 2002 at 22:31 UTC
    What version of Apache are you running? I know in the releases below 1.3.22 (I think) there were a lot of issues regarding conflicts between the system Expat library and the one included with Apache. This caused me problems similiar to this.
      I'm at 1.3.17 ... perhaps time to upgrade.
        This node might be of help as well:

        (jeffa) Re: troubles writing mod_soap clients

        jeffa

        L-LL-L--L-LL-L--L-LL-L--
        -R--R-RR-R--R-RR-R--R-RR
        B--B--B--B--B--B--B--B--
        H---H---H---H---H---H---
        (the triplet paradiddle with high-hat)
        
Re: XML::Simple breaks CGI under mod_perl
by mirod (Canon) on Feb 04, 2002 at 06:04 UTC

    LukeyBoy is right, old versions of apache include a version of expat which conflicts with the one used by XML::Parser (and thus by XML::Simple).

    The best explanation I have found on how to solve the problem is the one in the AxKit FAQ:

    First of all, to find out if this is your problem, execute the command: strings /path/to/apache/bin/httpd | grep -i XML. If there are any results at all then you are going to see these segfaults until you recompile Apache (and probably mod_perl too)

    To compile Apache without expat, simply supply the option:
    RULE_EXPAT=NO

    to ./configure when you build Apache. Alternatively if you build Apache with mod_perl (with mod_perl's DO_HTTPD option) it will supply this option automatically for you.
Re: XML::Simple breaks CGI under mod_perl
by Matts (Deacon) on Feb 05, 2002 at 10:55 UTC
    Along with the other replies, if you don't want to have to recompile Apache/mod_perl, then you can also use XML::SAX::Simple in conjunction with XML::SAX::PurePerl, which will be slower, but won't segfault:
    use XML::SAX::Simple; local $XML::SAX::ParserPackage = "XML::SAX::PurePerl"; my $hash = XMLin($xml); ...