[libmessage-passing-zeromq-perl] 05/78: Start on output

Jonas Smedegaard js at alioth.debian.org
Mon Sep 30 09:28:16 UTC 2013


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository libmessage-passing-zeromq-perl.

commit 1f9c9e87388a160121f354402fdc5a0f90f6d084
Author: Tomas Doran <bobtfish at bobtfish.net>
Date:   Sat Feb 25 11:14:00 2012 +0000

    Start on output
---
 lib/Log/Stash/Output/ZeroMQ.pm |   40 +++++++++++++++++++++++++++++++++++++++-
 t/output.t                     |   21 +++++++++++++++++++++
 2 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/lib/Log/Stash/Output/ZeroMQ.pm b/lib/Log/Stash/Output/ZeroMQ.pm
index fc6fce7..877e72f 100644
--- a/lib/Log/Stash/Output/ZeroMQ.pm
+++ b/lib/Log/Stash/Output/ZeroMQ.pm
@@ -1,8 +1,46 @@
 package Log::Stash::Output::ZeroMQ;
 use Moose;
-use ZeroMQ;
+use ZeroMQ ':all';
 use namespace::autoclean;
 
+has _ctx => (
+    is => 'ro',
+    isa => 'ZeroMQ::Context',
+    lazy => 1,
+    default => sub { ZeroMQ::Context->new() },
+    clearer => '_clear_ctx',
+);
+
+has connect => (
+    isa => 'Str',
+    is => 'ro',
+    default => sub { 'tcp://127.0.0.1:5558' },
+);
+
+has _socket => (
+    is => 'ro',
+    isa => 'ZeroMQ::Socket',
+    lazy => 1,
+    default => sub {
+        my $self = shift;
+        my $socket = $self->_ctx->socket(ZMQ_PUB);
+        $socket->setsockopt(ZMQ_HWM, 1000);
+        $socket->connect($self->connect);
+        return $socket;
+    },
+    predicate => '_has_socket',
+    clearer => '_clear_socket',
+    handles => {
+        '_zmq_send' => 'send',
+    },
+);
+
+sub consume {
+    my $self = shift;
+    my $data = shift;
+    $self->_zmq_send($self->encode($data));
+}
+
 with 'Log::Stash::Mixin::Output';
 
 1;
diff --git a/t/output.t b/t/output.t
new file mode 100644
index 0000000..9d73c39
--- /dev/null
+++ b/t/output.t
@@ -0,0 +1,21 @@
+use strict;
+use warnings;
+use Test::More;
+
+use AnyEvent;
+use Log::Stash::Input::ZeroMQ;
+use Log::Stash::Output::Test;
+use Log::Stash::Output::ZeroMQ;
+
+use ZeroMQ qw/:all/;
+
+my $ctx = ZeroMQ::Context->new();
+my $socket = $ctx->socket(ZMQ_SUB);
+$socket->bind('tcp://127.0.0.1:5558');
+
+my $output = Log::Stash::Output::ZeroMQ->new();
+
+$output->consume({foo => 'bar'});
+
+done_testing;
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmessage-passing-zeromq-perl.git



More information about the Pkg-perl-cvs-commits mailing list