I'm running into a little problem with SpeedyCGI that's stumping me. In general, I really like Speedy - I switched some CGI::Simple scripts that had severe performance issues to it, and was amazed at the improvement. The problem is, all those CGIs were just processing GET requests. I'm now trying to write the first one that will accept POSTs, and I can't get it to work. The code itself is very simple:
#!/usr/bin/speedy -wT use strict; use CGI::Simple; use MyApp::Theme; + + use vars qw/$q/; + + $q = new CGI::Simple; + + warn $q->Dump; + + if ($q->param('theme') =~ m#([\w\-:(){} /]+)#) { my $theme = $1; + + my @themes = map {$_->theme} MyApp::Theme->search_like(theme => $the +me."%"); my %matches; + + foreach (@themes) { my $nextslash = index($_, " / ", length $theme); if ($nextslash == -1) { # not found - it's a leaf $matches{$_} = $_; } elsif (not exists $matches{$_}) { substr($_, $nextslash) = ""; $matches{$_} = "$_ / "; } } + + print $q->header; print "<ul>"; foreach (sort keys %matches) { print "<li>$_</li>"; } unless (exists $matches{$theme}) { print "<li>$theme</li>"; } print "</ul>"; }
It accepts a single parameter (theme), and returns an unordered list of similar themes (used in an AJAX autocomplete setup). When I run it under normal perl, everything works great:
$VAR1 = bless( { '.parameters' => [ 'theme', '_' ], '.globals' => { 'DEBUG' => '0', 'NO_UNDEF_PARAMS' => '0', 'NO_NULL' => 1, 'FATAL' => -1, 'USE_PARAM_SEMICOLONS' => '0', 'DISABLE_UPLOADS' => 1, 'USE_CGI_PM_DEFAULTS' => '0', 'NPH' => '0', 'POST_MAX' => 102400, 'HEADERS_ONCE' => '0' }, '.fieldnames' => { '_' => 1, 'theme' => 1 }, '_' => [ '' ], 'theme' => [ 'Some value' ] }, 'CGI::Simple' ); at /var/www/cgi-bin/ac_theme line 16.
When I switch to speedy, I get this:
$VAR1 = bless( { '.globals' => { 'DEBUG' => '0', 'NO_UNDEF_PARAMS' => '0', 'NO_NULL' => 1, 'FATAL' => -1, 'USE_PARAM_SEMICOLONS' => '0', 'DISABLE_UPLOADS' => 1, 'USE_CGI_PM_DEFAULTS' => '0', 'NPH' => '0', 'POST_MAX' => 102400, 'HEADERS_ONCE' => '0' }, '.cgi_error' => '500 Bad read on POST! wanted 48, go +t 0' }, 'CGI::Simple' ); at /var/www/cgi-bin/ac_theme line 16.
What gives? Update: Just occured to me to switch to the regular CGI, and sure enough, everything works again, even under speedy. I guess CGI::Simple isn't doing something right?

-- zigdon


In reply to SpeedyCGI and POSTs using CGI::Simple by zigdon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.