[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:47 UTC 2013


The following commit has been merged in the master branch:
commit aa5a3f4ca54bbb8450d976fc225714ab41baee93
Author: Tomas Doran <bobtfish at bobtfish.net>
Date:   Thu Mar 22 23:56:50 2012 +0000

    Add a delay filter for testing

diff --git a/README b/README
index 319f3fa..efa8530 100644
--- a/README
+++ b/README
@@ -112,7 +112,7 @@ SPONSORSHIP
     This module exists due to the wonderful people at Suretec Systems Ltd.
     <http://www.suretecsystems.com/> who sponsored it's development for its
     VoIP division called SureVoIP <http://www.surevoip.co.uk/> for use with
-    the SureVoIP API - 
+    the SureVoIP API -
     <http://www.surevoip.co.uk/support/wiki/api_documentation>
 
 COPYRIGHT
diff --git a/lib/Log/Stash/Filter/Null.pm b/lib/Log/Stash/Filter/Delay.pm
similarity index 65%
copy from lib/Log/Stash/Filter/Null.pm
copy to lib/Log/Stash/Filter/Delay.pm
index 6f9c40b..4ad3adc 100644
--- a/lib/Log/Stash/Filter/Null.pm
+++ b/lib/Log/Stash/Filter/Delay.pm
@@ -1,12 +1,30 @@
-package Log::Stash::Filter::Null;
+package Log::Stash::Filter::Delay;
 use Moose;
+use AnyEvent;
+use Scalar::Util qw/ weaken /;
 use namespace::autoclean;
 
-with 'Log::Stash::Role::Filter';
+with qw/
+    Log::Stash::Role::Input
+    Log::Stash::Role::Output
+/;
 
-sub filter {
+has delay_for => (
+    isa => 'Num',
+    is => 'ro',
+    required => 1,
+);
+
+sub consume {
     my ($self, $message) = @_;
-    $message;
+    weaken($self);
+    my $t; $t = AnyEvent->timer(
+        after => $self->delay_for,
+        cb => sub {
+            undef $t;
+            $self->output_to->consume($message);
+        },
+    );
 }
 
 __PACKAGE__->meta->make_immutable;
diff --git a/t/00_compile.t b/t/00_compile.t
index 1bc4c6e..9d69218 100644
--- a/t/00_compile.t
+++ b/t/00_compile.t
@@ -10,6 +10,7 @@ use_ok('Log::Stash::Output::Null');
 use_ok('Log::Stash::Output::Test');
 use_ok('Log::Stash::Filter::Null');
 use_ok('Log::Stash::Filter::All');
+use_ok('Log::Stash::Filter::Delay');
 
 done_testing;
 
diff --git a/t/filter.t b/t/filter.t
index eb0b656..20a4f23 100644
--- a/t/filter.t
+++ b/t/filter.t
@@ -8,6 +8,7 @@ use Log::Stash::Output::Test;
 use Log::Stash::Filter::All;
 use Log::Stash::Filter::T;
 use Log::Stash::Filter::Key;
+use Log::Stash::Filter::Delay;
 
 my $called = 0;
 
@@ -119,5 +120,35 @@ try { $ob->consume({foo => { inner => { inner => 'bar' } }, baz => 'quux'}) }
 
 is_deeply [$test->messages], [{foo => { inner => { inner => 'bar' } }, baz => 'quux'}];
 
+$ob = try {
+    $test = Log::Stash::Output::Test->new();
+    Log::Stash::Filter::Delay->new(
+        delay_for => 0.1,
+        output_to => $test,
+    );
+}
+catch { fail "Failed to construct $_" };
+ok $test;
+
+$ob->consume({});
+is_deeply [$test->messages], [];
+my $cv = AnyEvent->condvar;
+my $idle; $idle = AnyEvent->idle(cb => sub {
+    $cv->send;
+    undef $idle;
+});
+$cv->recv;
+is_deeply [$test->messages], [];
+$cv = AnyEvent->condvar;
+my $timer; $timer = AnyEvent->timer(
+    after => 0.2,
+    cb => sub {
+        $cv->send;
+        undef $timer;
+    },
+);
+$cv->recv;
+is_deeply [$test->messages], [{}];
+
 done_testing;
 

-- 
libmessage-passing-perl Debian packaging



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