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

I'm building an application which relies on CGI::FormBuilder to provide an online tool to manage the making of phone calls to a list.

The form loads fine. But when I submit my form using the 'Proceed to Next Household' button, when I'm hoping to be presented with the next household to call, I get instead an endless stream of debug output (mostly Data::Dumper's full of hashes being passed from one subroutine to the next, with occassional debug statements showing me progress through the script) filling my /var/log partition, which can only be halted by restarting the apache server. Simply killing the www-data owned perl process for the script does not do it.

My cgi script, invoked from the browser includes:

my $html = $dashboard->_process_list_of_households(); print STDERR "We made it back to cgi script.\n"; if(defined($html)){ print STDERR "canvas_hh_screen.cgi says that \$html is: $html \n"; print $html; } else { print STDERR "\$html remains undefined for some reason.\n"; }
My $dashboard->_process_list_of_households() method taps the database and properly processes through that list and then invokes another internal method to render the form, which includes the following code:

$html = $self->_render_online_household_form(\%hh_values); if(defined($html)){ return $html; # print $html; } else { die "\$html remains undefined after ->_render_online_household +_form().\n"; }
The method which is called from the snippet above includes the following dispatch logic.
if($form->submitted && $form->validate){ my $field = $form->fields; if($form->submitted eq 'Proceed to Next Household'){ $self->_record_call_results($field); $www_hh_form = $form->render(header => 1); # $www_hh_form = $form->confirm(header => 1); # $www_hh_form .= "<pre>" . Dumper(\$field) . "</pre>"; return $www_hh_form; } elsif($form->submitted eq 'Save Results') { $self->_record_call_results($field); # $www_hh_form = $form->confirm(header => 1); $www_hh_form = $self->_render_dashboard(); $www_hh_form .= "<pre>" . Dumper(\$field) . "</pre>"; return $www_hh_form; } elsif($form->submitted eq 'Reset this Household') { my $record_count = $self->_reset_hh_call_results($field); $www_hh_form = $form->render(header => 1); return $www_hh_form; } else { print STDERR "Form invoked with illegal submit button from IP: \ +n"; die "Form invoked with illegal submit button from IP: \n"; } } else { print STDERR "OK, we'll render form for first time for this househ +old.\n"; $www_hh_form = $form->render(header => 1); return $www_hh_form; }
Again, this works fine the first time through. But when I attempt to 'Proceed to Next Household' I'm getting an endless stream filling my logs and nothing new in the browser, until it eventually times out and returns an error message. What is it I'm missing here? How can I get this to work as I hope and intend, please?

-- Hugh

UPDATE: I added a comment to answer the question below about my 'endless stream' of what?

UPDATE #2: I think I may have identified my issue. I had a two table join in the mix which when it encountered a household record with no phone number would return over two thousand residents for that household who also lacked a phone number. The 'endless stream of debug output' was the Data::Dumper of the hashes for each of those household residents. Apache would time out before processing the 2200+ records, but fill my logs in so doing. I've now added an additional WHERE clause to restrict that query (and another upstream of it) to results where the length(phone) > 6, so I stand a better chance of dealing with valid phone numbers and folks who are legitimately members of that household. My issue it seems was in a poorly constructed database query, not in the logic of my dispatch (which all looked fine to me, even though I've been blaming that dispatch code for two days while I scratched my head on this one in between other projects). Thank you shmem for pointing me back to the debug output I was already accumulating (in droves). It held the key, but was so voluminous as to be intimidating to examine closely. I continue to test but suspect I may be on the way here now.

if( $lal && $lol ) { $life++; }

Replies are listed 'Best First'.
Re: Twisted Logic Filling My Logs, w/o Rendering Form
by shmem (Chancellor) on May 08, 2008 at 06:31 UTC
    I get instead an endless stream of debug output

    Well, that's something to work with. Being endless, there must be repeating elements in it. Locate the first repetition, locate the place in your code where it comes from. Provide that snippet with a counter, increment it at each pass, and if it gets to two, invoke a Carp::confess. That should cut things down a bit and provide you with a stack trace you can examine.

    From the snippets you provide I can't tell where you are looping, i.e. where your logic is twisted. Can we see the opus in full?

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: Twisted Logic Filling My Logs, w/o Rendering Form
by TOD (Friar) on May 08, 2008 at 02:59 UTC
    it's hard to tell. does your script
    use warnings;
    and
    use CGI::Carp qw/fatalsToBrowser/;
    ? maybe they will give you a hint.
    --------------------------------
    masses are the opiate for religion.
      Yes, the cgi script itself starts off:

      #!/usr/bin/perl -T use strict; use warnings; use Data::Dumper;
      and liberally sprinkles in print STDERR debug statements. My issue is apparently not a fatal crash, but an endless loop. Its processing each household without rendering the webform for it, after the first one, of course.

      My $self->_render_online_household_form() method is set to return the html for the form, to the $dashboard->_process_list_of_households() method, which also returns the html form to the cgi script which called it. The cgi script is supposed to print that $html if its defined.

      My two modules written to drive this application are also begun with:

      use strict; use warnings;
      Its an old habit by now.

      -- Hugh

      if( $lal && $lol ) { $life++; }
Re: Twisted Logic Filling My Logs, w/o Rendering Form
by Anonymous Monk on May 08, 2008 at 04:19 UTC
    Endless stream of ?