summaryrefslogtreecommitdiff
path: root/lib/XXV/OUTPUT/HTML/PUSH.pm
blob: 7c7d7dfad89ab7a5c34f8182e3beb0e3670818a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package XXV::OUTPUT::HTML::PUSH;

use strict;

use Tools;

$| = 1;

=head1 NAME

XXV::OUTPUT::HTML::PUSH - A Push for http system

=head1 SYNOPSIS

    use XXV::OUTPUT::HTML::PUSH;

    my $pusher =  XXV::OUTPUT::HTML::PUSH->new(
        -cgi => $obj->{cgi},        # The CGI Object from Lincoln Stein
        -handle => $obj->{handle},  # The handle to printout the http Stuff
    );

    $pusher->start();       # Start the Push Process

    while($c > 10) {
        $pusher->print($c++);  # Print out the message
    }

    $pusher->stop();        # Stop the Push


=cut

# ------------------
sub new {
# ------------------
	my($class, %attr) = @_;
	my $self = {};
	bless($self, $class);

    $self->{handle} = $attr{'-handle'}
        || return error('No handle defined!');

    $self->{cgi} = $attr{'-cgi'}
        || return error('No CGI Object defined!');

	return $self;
}

# ------------------
sub start {
# ------------------
    my $obj = shift  || return error ('No Object!' );
    my $out = shift ||  0;
    $obj->{handle}->print($obj->{cgi}->multipart_init(-boundary=>'----here we go!'));
    $obj->print($out) if($out);
}

# ------------------
sub print {
# ------------------
    my $obj = shift  || return error ('No Object!' );
    my $msg = shift  || return;
    my $type = shift || 'text/html';

    $obj->{handle}->print($obj->{cgi}->multipart_start(-type=>$type));
    $obj->{handle}->print($msg."\n");
    $obj->{handle}->print($obj->{cgi}->multipart_end);
}

# ------------------
sub follow_print {
# ------------------
    my $obj = shift  || return error ('No Object!' );
    my $msg = shift  || return;
    my $type = shift || 'text/html';

    unless($obj->{header}) {
        $obj->{handle}->print($obj->{cgi}->multipart_start(-type=>$type));
        $obj->{header} = 1;
    }
    $obj->{handle}->print($msg."\n");
}

# ------------------
sub stop {
# ------------------
    my $obj = shift  || return error ('No Object!' );
    $obj->{handle}->print($obj->{cgi}->multipart_end);
    $obj->{handle}->print($obj->{cgi}->header(
        -type   =>  'text/html',
        -status  => "200 OK",
    ));
}

1;