I'm stuck with getting the STDOUT buffer to flush for a web app i'm writing. here's the issue:
i have a script that instantiates display objects, then prints out the results. let's call it index.cgi
index.cgi basically does this:
my $page = DisplayModule->new();
my $html = $page->build_page;
print $page;
not much processing there.
the display module makes some decisions about what page to build, then build them, collecting all of the HTML ( to be later printed by index.cgi )
one of the methods in DisplayModule ( that gets called by the build_page routine ) needs to print some 'status messages' out to the screen before the HTML is rendered.
but the print statements live in another module, let's call it Debugger.pm
so in DisplayModule->build_page, an new Debugger is created. something like this:
sub build_page {
my $self = shift;
#### the usual arg processing, etc
my $debug = Debugger->new();
$debug->debug_it();
### gather up more info, stick it into the $html var
return $html;
}
-
I've tried setting $| = 1; ( and tried the shorthand $|++ )
-
I've tried syswrite( STDOUT, $message, length($message) );
-
I've set $| in all the associated objects. . .( in this case, index.cgi, DisplayModule.pm, and Debugger.pm ) but i still have the page hang, wait for object instantiation, wait until the browser has received the entire page, and then i get 'rendering' -- even though the debug messages are just plaintext, and shouldn't be rendered.
-
I've tried writing a function ( force_print ) which takes a message from Debugger.pm and turns it into a call to syswrite.
but none of these give me the desired behavior -- status messages on STDOUT ( the client browser ) while the html is being gathered by the rest of the program.
is there something i'm overlooking?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.