Mojolicious::Plugin::EventSource - A plugin to make it eazy to use EventSource with Mojolicious
Version 0.3
use Mojolicious::Lite; 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>
If you are using Mojolicious::Lite it exports the shortcut event_source to your main.
Emits a event.
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.
Fernando Correa de Oliveira, <fco at cpan.org>
<fco at cpan.org>
Thanks to Gabriel Vieira and #mojo (irc.perl.org) for the help.
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.
bug-mojolicious-plugin-eventsource at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Mojolicious::Plugin::EventSource
You can also look for information at:
GitHub: GitHug Repo
https://github.com/FCO/Mojolicious-Plugin-EventSource
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Mojolicious-Plugin-EventSource
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Mojolicious-Plugin-EventSource
CPAN Ratings
http://cpanratings.perl.org/d/Mojolicious-Plugin-EventSource
Search CPAN
http://search.cpan.org/dist/Mojolicious-Plugin-EventSource/
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.
To install Mojolicious::Plugin::EventSource, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::EventSource
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::EventSource
For more information on module installation, please visit the detailed CPAN module installation guide.