[libmessage-passing-zeromq-perl] 56/78: Port to Moo
Jonas Smedegaard
js at alioth.debian.org
Mon Sep 30 09:28:27 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 0a6c70745722f92361616c3ab03922cc6d7f58d5
Author: Tomas Doran <bobtfish at bobtfish.net>
Date: Sun Jul 15 12:05:44 2012 +0100
Port to Moo
---
Makefile.PL | 6 ++---
lib/Message/Passing/Input/ZeroMQ.pm | 8 +++----
lib/Message/Passing/Output/ZeroMQ.pm | 11 +++++-----
lib/Message/Passing/ZeroMQ.pm | 5 +++--
lib/Message/Passing/ZeroMQ/Role/HasAContext.pm | 6 ++---
lib/Message/Passing/ZeroMQ/Role/HasASocket.pm | 28 ++++++++++++++----------
t/pushpull.t | 1 -
7 files changed, 36 insertions(+), 29 deletions(-)
diff --git a/Makefile.PL b/Makefile.PL
index 5a08155..63d1bb1 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -13,13 +13,13 @@ resources(
repository => "git://github.com/suretec/Message-Passing-ZeroMQ.git",
);
-requires 'Moose';
-requires 'namespace::autoclean';
+requires 'Moo' => '0.091011';
+requires 'namespace::clean';
requires 'AnyEvent';
requires 'ZeroMQ' => '0.21';
requires 'Try::Tiny';
requires 'Task::Weaken';
-requires 'Message::Passing' => '0.008';
+requires 'Message::Passing' => '0.011';
requires 'POSIX::AtFork' => '0.02';
requires 'Sub::Name';
diff --git a/lib/Message/Passing/Input/ZeroMQ.pm b/lib/Message/Passing/Input/ZeroMQ.pm
index e6c5561..5b70c83 100644
--- a/lib/Message/Passing/Input/ZeroMQ.pm
+++ b/lib/Message/Passing/Input/ZeroMQ.pm
@@ -1,11 +1,11 @@
package Message::Passing::Input::ZeroMQ;
-use Moose;
+use Moo;
use ZeroMQ qw/:all/;
use AnyEvent;
use Scalar::Util qw/ weaken /;
use Try::Tiny qw/ try catch /;
use Message::Passing::Types qw/ ArrayOfStr /;
-use namespace::autoclean;
+use namespace::clean -except => 'meta';
with qw/
Message::Passing::ZeroMQ::Role::HasASocket
@@ -23,9 +23,9 @@ sub _socket_type { 'SUB' }
sub _build_socket_hwm { 100000 }
has subscribe => (
- isa => ArrayOfStr,
+ isa => sub { ref($_[0]) eq 'ARRAY' },
is => 'ro',
- coerce => 1,
+ lazy => 1,
default => sub { [ '' ] }, # Subscribe to everything!
);
diff --git a/lib/Message/Passing/Output/ZeroMQ.pm b/lib/Message/Passing/Output/ZeroMQ.pm
index d5d1a1b..84dab39 100644
--- a/lib/Message/Passing/Output/ZeroMQ.pm
+++ b/lib/Message/Passing/Output/ZeroMQ.pm
@@ -1,9 +1,12 @@
package Message::Passing::Output::ZeroMQ;
-use Moose;
+use Moo;
use ZeroMQ ':all';
-use namespace::autoclean;
+use namespace::clean -except => 'meta';
-with 'Message::Passing::ZeroMQ::Role::HasASocket';
+with qw/
+ Message::Passing::ZeroMQ::Role::HasASocket
+ Message::Passing::Role::Output
+/;
has '+_socket' => (
handles => {
@@ -21,8 +24,6 @@ sub consume {
$self->_zmq_send($data);
}
-with 'Message::Passing::Role::Output';
-
1;
=head1 NAME
diff --git a/lib/Message/Passing/ZeroMQ.pm b/lib/Message/Passing/ZeroMQ.pm
index ae90518..f87f926 100644
--- a/lib/Message/Passing/ZeroMQ.pm
+++ b/lib/Message/Passing/ZeroMQ.pm
@@ -1,9 +1,10 @@
package Message::Passing::ZeroMQ;
-use Moose ();
+use strict;
+use warnings;
use ZeroMQ qw/ :all /;
use POSIX::AtFork ();
use Sub::Name;
-use namespace::autoclean;
+use namespace::clean -except => 'meta';
our $VERSION = "0.005";
$VERSION = eval $VERSION;
diff --git a/lib/Message/Passing/ZeroMQ/Role/HasAContext.pm b/lib/Message/Passing/ZeroMQ/Role/HasAContext.pm
index 828e543..5c645cc 100644
--- a/lib/Message/Passing/ZeroMQ/Role/HasAContext.pm
+++ b/lib/Message/Passing/ZeroMQ/Role/HasAContext.pm
@@ -1,15 +1,15 @@
package Message::Passing::ZeroMQ::Role::HasAContext;
-use Moose::Role;
+use Moo::Role;
use Message::Passing::ZeroMQ ();
use ZeroMQ ':all';
use Scalar::Util qw/ weaken /;
-use namespace::autoclean;
+use namespace::clean -except => 'meta';
## TODO - Support (default to?) shared contexts
has _ctx => (
is => 'ro',
- isa => 'ZeroMQ::Context',
+# isa => 'ZeroMQ::Context',
lazy => 1,
default => sub {
my $self = shift;
diff --git a/lib/Message/Passing/ZeroMQ/Role/HasASocket.pm b/lib/Message/Passing/ZeroMQ/Role/HasASocket.pm
index 63cd1d4..722eecf 100644
--- a/lib/Message/Passing/ZeroMQ/Role/HasASocket.pm
+++ b/lib/Message/Passing/ZeroMQ/Role/HasASocket.pm
@@ -1,14 +1,14 @@
package Message::Passing::ZeroMQ::Role::HasASocket;
-use Moose::Role;
+use Moo::Role;
use ZeroMQ ':all';
-use Moose::Util::TypeConstraints;
-use namespace::autoclean;
+use MooX::Types::MooseLike::Base qw/ :all /;
+use namespace::clean -except => 'meta';
with 'Message::Passing::ZeroMQ::Role::HasAContext';
has _socket => (
is => 'ro',
- isa => 'ZeroMQ::Socket',
+# isa => 'ZeroMQ::Socket',
lazy => 1,
builder => '_build_socket',
predicate => '_has_socket',
@@ -28,8 +28,8 @@ requires '_socket_type';
has linger => (
is => 'ro',
- isa => 'Bool',
- default => 0,
+ isa => Bool,
+ default => sub { 0 },
);
sub _build_socket {
@@ -46,34 +46,40 @@ sub _build_socket {
if ($self->_should_bind) {
$socket->bind($self->socket_bind);
}
+ if (!$self->_should_connect && !$self->_should_bind) {
+ use Data::Dumper;
+ die "Neither asked to connect or bind, invalid" . Dumper($self);
+ }
$socket;
}
has socket_hwm => (
is => 'ro',
- isa => 'Int',
+ isa => Int,
builder => '_build_socket_hwm',
+ lazy => 1,
);
sub setsockopt {
my ($self, $socket) = @_;
$socket->setsockopt(ZMQ_HWM, $self->socket_hwm);
-};
+}
has socket_bind => (
is => 'ro',
- isa => 'Str',
+ isa => Str,
predicate => '_should_bind',
);
has socket_type => (
- isa => enum([qw[PUB SUB PUSH PULL]]),
+# isa => enum([qw[PUB SUB PUSH PULL]]),
is => 'ro',
builder => '_socket_type',
+ lazy => 1,
);
has connect => (
- isa => 'Str',
+ isa => Str,
is => 'ro',
predicate => '_should_connect',
);
diff --git a/t/pushpull.t b/t/pushpull.t
index 9755420..37d5681 100644
--- a/t/pushpull.t
+++ b/t/pushpull.t
@@ -26,7 +26,6 @@ my $t; $t = AnyEvent->timer(
after => 1,
cb => sub {
$output->consume({});
- diag "Outer callback";
$t = AnyEvent->timer(after => 1, cb => sub { $cv->send });
},
);
--
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