NAME

Mojolicious::Plugin::EventSource - A plugin to make it eazy to use EventSource with Mojolicious

VERSION

Version 0.3

SYNOPSIS

BEGIN{ plugin 'Mojolicious::Plugin::EventSource', timeout => 300 }
get '/' => 'index';
event_source '/event' => sub {
my $self = shift;
my $id = Mojo::IOLoop->recurring(1 => sub {
my $pips = int(rand 6) + 1;
$self->emit("dice", $pips);
});
$self->on(finish => sub { Mojo::IOLoop->drop($id) });
} => "event";
app->start;
__DATA__
@@ index.html.ep
<!doctype html><html>
<head><title>Roll The Dice</title></head>
<body>
<script>
var events = new EventSource('<%= url_for 'event' %>');
// Subscribe to "dice" event
events.addEventListener('dice', function(event) {
document.body.innerHTML += event.data + '<br/>';
}, false);
</script>
</body>
</html>

EXPORT

If you are using Mojolicious::Lite it exports the shortcut event_source to your main.

HELPERS

emit

Emits a event.

METHODS

Mojolicious::Plugin::EventSource inherits all methods from Mojolicious::Plugin and implements the following new one.

register

$plugin->register;

Register plugin helper and shortcut in Mojolicious application.

AUTHOR

Fernando Correa de Oliveira, <fco at cpan.org>

Thanks to Gabriel Vieira and #mojo (irc.perl.org) for the help.

BUGS

Please report any bugs or feature requests to bug-mojolicious-plugin-eventsource at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Mojolicious-Plugin-EventSource. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Mojolicious::Plugin::EventSource

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2012 Fernando Correa de Oliveira.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.