[SCM] libmessage-passing-perl Debian packaging branch, master, updated. debian/0.111-3-14-g44f6e88

Tomas Doran bobtfish at bobtfish.net
Mon May 6 11:56:58 UTC 2013


The following commit has been merged in the master branch:
commit efad16dc56f2cdf82dc07920122b1a71d5611404
Author: Tomas Doran <bobtfish at bobtfish.net>
Date:   Wed May 23 03:10:35 2012 +0100

    And connection manager tests / fixes

diff --git a/lib/Log/Stash/Role/ConnectionManager.pm b/lib/Log/Stash/Role/ConnectionManager.pm
index 8c13fd6..f5a9b31 100644
--- a/lib/Log/Stash/Role/ConnectionManager.pm
+++ b/lib/Log/Stash/Role/ConnectionManager.pm
@@ -33,7 +33,7 @@ has _connect_subscribers => (
 
 sub __clean_subs {
     my $self = shift;
-    my $subs = [ grep { defined $_ } @{$self->_connect_subscribers} ];
+    my $subs = [ grep { weaken($_); defined $_ } @{$self->_connect_subscribers} ];
     $self->_set_connect_subscribers($subs);
 }
 
@@ -44,10 +44,8 @@ sub subscribe_to_connect {
     $self->__clean_subs;
     my $subs = $self->_connect_subscribers;
     push(@$subs, $subscriber);
-    weaken(@{$subs}[-1]);
     if ($self->connected) {
-        warn "Already connected";
-        $subscriber->connect($self->connection);
+        $subscriber->connected($self->connection);
     }
 }
 
diff --git a/t/role_connectionmanager.t b/t/role_connectionmanager.t
new file mode 100644
index 0000000..51f7b84
--- /dev/null
+++ b/t/role_connectionmanager.t
@@ -0,0 +1,72 @@
+use strict;
+use warnings;
+use Test::More;
+
+{
+    package Connection::Subscriber;
+    use Moose;
+    use namespace::clean -except => 'meta';
+
+    has am_connected => ( is => 'rw' );
+
+    sub connected {
+        shift->am_connected(1);
+    }
+
+    sub disconnected {
+        shift->am_connected(0);
+    }
+}
+{
+    package Some::Shonky::Async::Code;
+    use Moose;
+    use namespace::clean -except => 'meta';
+
+}
+
+{
+    package My::Connection::Wrapper;
+    use Moose;
+    use Scalar::Util qw/ weaken /;
+    use namespace::clean -except => 'meta';
+
+    with 'Log::Stash::Role::ConnectionManager';
+
+    sub _build_connection {
+        my $self = shift;
+        weaken($self);
+        my $client = Some::Shonky::Async::Code->new;
+        # Real code now has something like:
+        # $client->add_connect_callback(sub {
+        #   $self->_set_connected(1);
+        # });
+        # instead we'll simulate that below..
+        return $client;
+    }
+}
+
+my $sub = Connection::Subscriber->new;
+ok !exists($sub->{am_connected});
+
+my $i = My::Connection::Wrapper->new;
+ok $i;
+ok $i->{connection};
+isa_ok $i->{connection}, 'Some::Shonky::Async::Code';
+
+$i->subscribe_to_connect($sub);
+ok !exists($sub->{am_connected});
+
+$i->_set_connected(1);
+ok exists($sub->{am_connected});
+ok $sub->{am_connected};
+Scalar::Util::weaken($sub);
+
+my $sub2 = Connection::Subscriber->new;
+$i->subscribe_to_connect($sub2);
+ok $sub2->{am_connected};
+
+is_deeply $i->_connect_subscribers, [$sub2];
+ok !$sub;
+
+done_testing;
+

-- 
libmessage-passing-perl Debian packaging



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