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


The following commit has been merged in the master branch:
commit 54cc05373cd34fb07003d9ec53bb48311ff9342f
Author: Tomas Doran <bobtfish at bobtfish.net>
Date:   Sat Mar 3 20:14:43 2012 +0000

    Get filtering and options working properly in the script

diff --git a/lib/Log/Stash.pm b/lib/Log/Stash.pm
index 27ee251..d757152 100644
--- a/lib/Log/Stash.pm
+++ b/lib/Log/Stash.pm
@@ -6,6 +6,7 @@ use MooseX::Types::LoadableClass qw/ LoadableClass /;
 use String::RewritePrefix;
 use AnyEvent;
 use JSON::XS;
+use Try::Tiny;
 use namespace::autoclean;
 use 5.8.4;
 
@@ -37,17 +38,54 @@ foreach my $name (keys %things ) {
         required => $things{$name},
         coerce => 1,
     );
+
+    has lc($name) . '_instance' => (
+        is => 'ro',
+        lazy => 1,
+        does => "Log::Stash::Role::$name",
+        builder => '_build_' . lc($name) . '_instance',
+    );
+}
+
+has '+filter' => (
+    default => 'Null',
+);
+
+sub _build_input_instance {
+    my $self = shift;
+    $self->input->new($self->input_options, output_to => $self->filter_instance);
+}
+
+sub _build_filter_instance {
+    my $self = shift;
+    $self->filter->new($self->filter_options, output_to => $self->output_instance);
+}
+
+sub _build_output_instance {
+    my $self = shift;
+    $self->output->new($self->output_options);
+}
+
+sub start {
+    my $self = shift;
+    $self->input_instance;
 }
 
 my $json_type = subtype
-  as "Str",
-  where { ref( eval { JSON::XS->new->relaxed->decode($_) } ) ne '' },
-  message { "Must be at least relaxed JSON" };
+  as "HashRef";
+
+coerce $json_type,
+  from NonEmptySimpleStr,
+  via { try { JSON::XS->new->relaxed->decode($_) } };
 
-foreach my $name (map { lc($_) . "_filter"  } keys %things) {
+foreach my $name (map { lc($_) . "_options"  } keys %things) {
     has $name => (
         isa => $json_type,
-        is => 'ro'
+        traits    => ['Hash'],
+        default => sub { {} },
+        handles => {
+            lc($name) => 'elements',
+        },
     );
 }
 
diff --git a/lib/Log/Stash/Input/STDIN.pm b/lib/Log/Stash/Input/STDIN.pm
index 0ad1475..fd67cf1 100644
--- a/lib/Log/Stash/Input/STDIN.pm
+++ b/lib/Log/Stash/Input/STDIN.pm
@@ -9,7 +9,9 @@ with 'Log::Stash::Role::Input';
 sub BUILD {
     my $self = shift;
     my $r; $r = AnyEvent->io(fh => \*STDIN, poll => 'r', cb => sub {
-        chomp (my $input = <STDIN>);
+        my $input = <STDIN>;
+        return unless defined $input;
+        chomp($input);
         my $data = try { $self->decode($input) }
             catch { warn $_ };
         return unless $data;
diff --git a/script/logstash b/script/logstash
index 64090f5..b178da1 100755
--- a/script/logstash
+++ b/script/logstash
@@ -7,8 +7,7 @@ use AnyEvent;
 use Log::Stash;
 
 my $self = Log::Stash->new_with_options;
-my $out = $self->output->new;
-my $in = $self->input->new(output_to => $out);
+$self->start;
 
 AnyEvent->condvar->recv;
 

-- 
libmessage-passing-perl Debian packaging



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