Datastar-SSE

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN


 headers

            ->headers();

    Returns an Array Ref of the recommended headers to sent for Datastar
    SSE responses.

            Content-Type: text/event-stream
            Cache-Control: no-cache
            Connection: keep-alive
            Keep-Alive: timeout=300, max=100000

EVENTS

    Each Datastar SSE event is implements as a class method on
    Datastar::SSE. Each method accepts, but does not require, an options
    hashref as the last parameter, the options are documented per event,
    additionally all options from HTTP::ServerEvent are supported.

      * id

eg/index.cgi  view on Meta::CPAN

	</head>
	<body data-signals='}.JSON->new->encode($signals).q{'>
	<div>Counter: <span data-text="$counter"></span></div>
	<div><button data-on-click='@post("index.cgi?action=plus")'>increment</button>
	<button data-on-click='@post("index.cgi?action=minus")'>decrement</button></div>
	</body></html>});
} else {
	print $q->header(
    	-type => 'text/event-stream',
    	-cache_control => 'no-cache',
    	-connection => 'keep-alive',
    	-keep_alive => 'timeout=300, max=100000'
	);
	my $action = $q->url_param('action');
	my $signals = JSON->new->decode(scalar $q->param('POSTDATA'));
	$signals->{counter} = $action eq 'plus' ? $signals->{counter} + 1 : $signals->{counter} - 1;
	$q->print( Datastar::SSE->merge_signals( $signals ) );
}


lib/Datastar/SSE.pm  view on Meta::CPAN

=head1 METHODS

=head2 headers

	->headers();

Returns an Array Ref of the recommended headers to sent for Datastar SSE responses.

	Content-Type: text/event-stream
	Cache-Control: no-cache
	Connection: keep-alive
	Keep-Alive: timeout=300, max=100000

=cut

my $headers;
sub headers {
	$headers ||= +[
		'Content-Type', 'text/event-stream',
		'Cache-Control', 'no-cache',
		'Connection', 'keep-alive',
		'Keep-Alive', 'timeout=300, max=100000'
	]
}

=head1 EVENTS

Each Datastar SSE event is implements as a class method on L<Datastar::SSE>.  Each method accepts, but does not require,  
an options hashref as the last parameter, the options are documented per event, additionally all options from 
L<HTTP::ServerEvent> are supported.



( run in 1.797 second using v1.01-cache-2.11-cpan-39bf76dae61 )