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

Hi,

I'm using POE::Component::Server::HTTP and wish to add a stylesheet using CGI.pm but I'm having a spot of trouble.

What's happening is that when I add the css_link line to the headers, the script will appear to hang. If I kill the script (SIGINT) then the rest of the html code is magically sent to the web client. I don't think it has to do with buffering (see $|++ below). If I remove the css_link line, it runs fine. If I manually enter the css header line instead of calling a subroutine, it hangs.

I'm thinking it is something simple that I'm just overlooking. Any one see what I am not?

$|++; sub MainHandler { my ($request, $response) = @_; $response->code(RC_OK); $response->content( get_content($request) ); return RC_OK; } sub get_content { my $request = shift; my $my_content; $my_content = start_html( -title => $request->uri, -head => header_css() ); $my_content .= end_html(); return $my_content; } ########### ########### sub header_css { my @css_style_sheets = ("http://othermachine/css/standard.css", "h +ttp://othermachine/css/ssd.css"); ### in order to support multiple style sheets, ### we need to explicitly run CGI Link() ### we link only to those style sheets that ### actually exist my $css_link = ""; foreach (@css_style_sheets) { $css_link .= Link({ -rel => 'stylesheet', -type => 'text/css', -href => $_ }); } return $css_link; }

UPDATE: Looks like it was an issue of the remote css links and not the code itself. Argh. Certainly feels like monday

Thanks ikegami for the help as you made me see the light when I explained where the output was going! :)

Jason L. Froebe

Team Sybase member

No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

Replies are listed 'Best First'.
Re: POE::Component::Server::HTTP and CSS
by ikegami (Patriarch) on Jan 10, 2006 at 19:15 UTC
    I don't know if this will help, but the documention for CGI specifies a reference to an array should be passed to "head" when more than one element needs to be supplied.
    sub header_css { my @css_style_sheets = ( "http://othermachine/css/standard.css", "http://othermachine/css/ssd.css", ); my @head_links; foreach (@css_style_sheets) { push(@head_links, Link({ -rel => 'stylesheet', -type => 'text/css', -href => $_ })); } return \@head_links; }

      Thanks! :) You're correct about the reference to the array in the documentation. CGI.pm takes either a scalar or a reference to an array even with multiple items since the two css links are viewed as just text.

      Unfortunately, the hang remains. :( I'm suspecting the culprit to be the buffering even though $|++ is specified. I'll do some research to see if flushing is handled differently in POE (probably is ;-)

      Jason L. Froebe

      Team Sybase member

      No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

        How can bufferning be an issue? You don't write to anything.