#!/usr/local/bin/perl
#Displays a clock and updates every 5 seconds. Uses CGI.

use CGI;
$query = new CGI;
&print_push_header($query);

# very important to unbuffer output for server push!
while (1) {
    $time = `/bin/date`;
    $document=join("\n",
		   $query->start_html("Tick Tock"),
		   "<CENTER>",
		   "<H3>$time</H3>",
		   $query->end_html);
    &update_page($document,'text/html');
    sleep(5);
}

sub print_push_header {
    my($query) = @_;
    # Very important to unbuffer output
    # for server push!
    $|=1;
    # This is a global
    $BOUNDARY = "---------ready-or-not-here-it-comes!";
    print $query->header(-status=>"200 OK",
			 -server=>"$ENV{SERVER_SOFTWARE} / Lincoln's Script",
			 -type=>"multipart/x-mixed-replace; boundary=$BOUNDARY");
}

sub update_page {
    my($page,$type) = @_;
    print <<END;
$BOUNDARY
Content-type: $type

$page
END
    ;
}
