Permalink
Browse files

initial import

  • Loading branch information...
revmischa committed Oct 29, 2011
0 parents commit 821e6949eb6c79e22a4eb4e4a1684b7a256d0b0a
Showing with 684 additions and 0 deletions.
  1. +6 −0 .gitignore
  2. +2 −0 .shipit
  3. +23 −0 MANIFEST
  4. +14 −0 MANIFEST.SKIP
  5. +19 −0 Makefile.PL
  6. +53 −0 README
  7. +71 −0 eg/event_server.psgi
  8. +49 −0 eg/static/events.html
  9. +19 −0 eg/static/jquery-1.3.2.min.js
  10. +270 −0 eg/static/screen.css
  11. +154 −0 lib/Web/Hippie/ZeroMQ.pm
  12. +4 −0 t/00_compile.t
@@ -0,0 +1,6 @@
META.yml
Makefile
inc/
blib/
pm_to_blib
*~
@@ -0,0 +1,2 @@
steps = FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN
git.push_to = origin
@@ -0,0 +1,23 @@
.gitignore
eg/event_server.psgi
eg/static/events.html
eg/static/jquery-1.3.2.min.js
eg/static/screen.css
inc/Module/Install.pm
inc/Module/Install/Base.pm
inc/Module/Install/Can.pm
inc/Module/Install/Fetch.pm
inc/Module/Install/Include.pm
inc/Module/Install/Makefile.pm
inc/Module/Install/Metadata.pm
inc/Module/Install/ReadmeFromPod.pm
inc/Module/Install/Win32.pm
inc/Module/Install/WriteAll.pm
inc/Test/Builder/Module.pm
inc/Test/Requires.pm
lib/Web/Hippie/ZeroMQ.pm
Makefile.PL
MANIFEST This list of files
META.yml
README
t/00_compile.t
@@ -0,0 +1,14 @@
\bRCS\b
\bCVS\b
\.svn/
\.git/
^MANIFEST\.
^Makefile$
~$
\.old$
^blib/
^pm_to_blib
^MakeMaker-\d
\.gz$
\.cvsignore
\.shipit
@@ -0,0 +1,19 @@
sub author_tests { }
sub readme_from { }
sub auto_set_repository { }
use inc::Module::Install;
perl_version('5.008');
name 'Web-Hippie-ZeroMQ';
all_from 'lib/Web/Hippie/ZeroMQ.pm';
readme_from 'lib/Web/Hippie/ZeroMQ.pm';
build_requires 'Test::More';
test_requires 'Test::Requires';
requires 'Plack';
requires 'AnyMQ::ZeroMQ' => '0.03';
requires 'JSON';
requires 'Web::Hippie';
auto_include_deps;
auto_set_repository;
WriteAll;
53 README
@@ -0,0 +1,53 @@
NAME
Web::Hippie::ZeroMQ - Comet/Long-poll event server that can talk to a
ZeroMQ server
SYNOPSIS
use Plack::Builder;
use AnyMQ;
use AnyMQ::ZeroMQ;
my $bus = AnyMQ->new_with_traits(
traits => [ 'ZeroMQ' ],
subscribe_address => 'tcp://localhost:4001',
publish_address => 'tcp://localhost:4000',
);
# your plack application
my $app = sub { ... }
builder {
# mount hippie server
mount '/_hippie' => builder {
enable "+Web::Hippie::ZeroMQ", bus => $bus;
sub {
my $env = shift;
my $args = $env->{'hippie.args'};
my $handle = $env->{'hippie.handle'};
# Your handler based on PATH_INFO: /init, /error, /message
}
};
mount '/' => my $app;
};
DESCRIPTION
This module adds publish/subscribe capabilities to Web::Hippie using
AnyMQ::ZeroMQ.
SEE ALSO
Web::Hippie::Pipe, Web::Hippie::Pipe, AnyMQ::ZeroMQ, ZeroMQ::PubSub
AUTHOR
Mischa Spiegelmock <revmischa@cpan.org>
Based on work by:
Chia-liang Kao <clkao@clkao.org>
Jonathan Rockway <jrockway@cpan.org>
LICENSE
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
SEE ALSO
@@ -0,0 +1,71 @@
#!/usr/bin/env perl
use strict;
use warnings;
use AnyMQ;
use AnyMQ::ZeroMQ;
use Web::Hippie::App::JSFiles;
use Web::Hippie::ZeroMQ;
use Plack::Builder;
use Plack::Request;
use Carp qw/croak cluck/;
# run using Feersum::Runner or Plack::Handler::Feersum
# deployment: plackup -s Feersum --port 4000 -Ilib -E deployment event_server.psgi
# development: plackup -s Feersum --port 4000 -Ilib -E development -r event_server.psgi
my $mq_bus = AnyMQ->new_with_traits(
traits => [ 'ZeroMQ' ],
subscribe_address => 'tcp://localhost:4001',
publish_address => 'tcp://localhost:4000',
);
# print stack trace
sub fatal {
my ($err) = @_;
cluck "Fatal error when handling request: $err\n";
}
my $app = sub {
my $env = shift;
my $req = Plack::Request->new($env);
my $res = $req->new_response(200);
$res->content_type('text/html; charset=utf-8');
if ($req->path eq '/') {
# index
$res->redirect('/static/events.html');
} else {
# unknown path
$res->content("Unknown path " . $req->path);
$res->code(404);
}
$res->finalize;
};
builder {
# static files
mount '/static' =>
Plack::App::Cascade->new(
apps => [
Web::Hippie::App::JSFiles->new->to_app,
Plack::App::File->new( root => 'static' )->to_app,
],
);
# zeromq hippie server
mount '/_hippie' => builder {
enable "+Web::Hippie::ZeroMQ", bus => $mq_bus;
sub {
my ($env) = @_;
my $req = Plack::Request->new($env);
warn "path: " . $req->path;
};
};
mount '/' => $app;
};
@@ -0,0 +1,49 @@
<html>
<head>
<title>Hippie demo: timer</title>
<script src="/static/jquery-1.3.2.min.js"></script>
<script src="/static/jquery.ev.js"></script>
<script src="/static/DUI.js"></script>
<script src="/static/Stream.js"></script>
<script src="/static/hippie.js"></script>
<script src="/static/json2.js"></script>
<script>
var h;
function log_it(stuff) {
$("#log").append(stuff+'<br/>');
}
$(function() {
h = new Hippie( document.location.host, 'ping', function() {
log_it("connected");
},
function() {
log_it("disconnected");
},
function(e) {
log_it("got message: type = "+e.type+", time = "+e.time);
} );
$("#pingbtn").click(function () {
h.send({ type: "ping" });
});
});
</script>
<link rel="stylesheet" href="/static/screen.css" />
</head>
<body>
<div id="content">
<div><input type="button" value="Ping" id="pingbtn" /></div>
<div id="log">
</div>
</div>
</body>
</html>

Large diffs are not rendered by default.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 821e694

Please sign in to comment.