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


The following commit has been merged in the master branch:
commit b2fa4b22ceee9b9523ba8f48e9c5e02632277241
Author: Tomas Doran <bobtfish at bobtfish.net>
Date:   Fri Jun 8 01:20:02 2012 +0100

    Rip encoding and decoding apart

diff --git a/Changes b/Changes
index 554cbd3..8ebb730 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,8 @@
+  - Rip JSON encoders and decoders out of inputs and
+    outputs, making them optional and/or replaceable.
+    *NOTE* Current Input / Output code will need updating
+    for this change!!
+
 0.005
    - Get connection timeouts and connection reconnects
      working in the generic ConnectionManager role.
diff --git a/lib/Message/Passing.pm b/lib/Message/Passing.pm
index f4f4bd9..494180f 100644
--- a/lib/Message/Passing.pm
+++ b/lib/Message/Passing.pm
@@ -11,6 +11,8 @@ with
     'Message::Passing::Role::CLIComponent' => { name => 'input' },
     'Message::Passing::Role::CLIComponent' => { name => 'output' },
     'Message::Passing::Role::CLIComponent' => { name => 'filter', default => 'Null' },
+    'Message::Passing::Role::CLIComponent' => { name => 'decoder', default => 'JSON' },
+    'Message::Passing::Role::CLIComponent' => { name => 'encoder', default => 'JSON' },
     'Message::Passing::Role::Script';
 
 our $VERSION = '0.005';
@@ -19,19 +21,29 @@ $VERSION = eval $VERSION;
 sub build_chain {
     my $self = shift;
         log_chain {
-            output out => (
+            output output => (
                 $self->output_options,
                 class => $self->output,
             );
+            encoder("encoder",
+                $self->encoder_options,
+                class => $self->encoder,
+                output_to => 'output',
+            );
             filter filter => (
                 $self->filter_options,
                 class => $self->filter,
-                output_to => 'out',
+                output_to => 'encoder',
+            );
+            decoder("decoder",
+                $self->decoder_options,
+                class => $self->decoder,
+                output_to => 'filter',
             );
-            input in => (
+            input input => (
                 $self->input_options,
                 class => $self->input,
-                output_to => 'filter',
+                output_to => 'decoder',
             );
         };
 }
diff --git a/lib/Message/Passing/DSL.pm b/lib/Message/Passing/DSL.pm
index 98cce81..edf62b9 100644
--- a/lib/Message/Passing/DSL.pm
+++ b/lib/Message/Passing/DSL.pm
@@ -9,7 +9,7 @@ use AnyEvent;
 use Moose::Util qw/ does_role /;
 
 Moose::Exporter->setup_import_methods(
-    as_is     => [qw/ run_log_server log_chain input filter output /],
+    as_is     => [qw/ run_log_server log_chain input filter output decoder encoder /],
 );
 
 our $FACTORY;
@@ -70,6 +70,26 @@ sub output {
     );
 }
 
+sub decoder {
+     my ($name, %opts) = @_;
+    _check_factory();
+    $FACTORY->make(
+        %opts,
+        name => $name,
+        type => 'Filter::Decoder',
+    );
+}
+
+sub encoder {
+     my ($name, %opts) = @_;
+    _check_factory();
+    $FACTORY->make(
+        %opts,
+        name => $name,
+        type => 'Filter::Encoder',
+    );
+}
+
 sub run_log_server {
     my $chain = shift;
     AnyEvent->condvar->recv;
@@ -140,6 +160,21 @@ Constructs a named output within a chain.
         ....
     };
 
+Class names will be assumed to prefixed with 'Log::Stash::Output::',
+unless you prefix the class with + e.g. C<< +My::Own::Output::Class >>
+
+=head3 encoder
+
+Constructs a named encoder within a chain.
+
+    log_chain {
+        encoder fooenc => ( output_to => 'out', class => 'JSON' );
+        ....
+    };
+
+Class names will be assumed to prefixed with 'Log::Stash::Filter::Encoder::',
+unless you prefix the class with + e.g. C<< +My::Own::Encoder::Class >>
+
 =head3 filter
 
 Constructs a named filter (which can act as both an output and an input)
@@ -147,20 +182,39 @@ within a chain.
 
     log_chain {
         ...
-        filter bar => ( output_to => 'stdout', class => 'Null' );
+        filter bar => ( output_to => 'fooenc', class => 'Null' );
         ...
     };
 
+Class names will be assumed to prefixed with 'Log::Stash::Filter::',
+unless you prefix the class with + e.g. C<< +My::Own::Filter::Class >>
+
+=head3 decoder
+
+Constructs a named decoder within a chain.
+
+    log_chain {
+        decoder zmq_decode => ( output_to => 'filter', class => 'JSON' );
+        ....
+    };
+
+Class names will be assumed to prefixed with 'Log::Stash::Filter::Decoder::',
+unless you prefix the class with + e.g. C<< +My::Own::Encoder::Class >>
+
+
 =head3 input
 
 The last thing in a chain - produces data which gets consumed.
 
     log_chain {
         ...
-        input zmq => ( output_to => 'bar', class => 'ZeroMQ', bind => '...' );
+        input zmq => ( output_to => 'zmq_decode', class => 'ZeroMQ', bind => '...' );
         ....
     }
 
+Class names will be assumed to prefixed with 'Log::Stash::Output::',
+unless you prefix the class with + e.g. C<< +My::Own::Output::Class >>
+
 =head3 run_log_server
 
 This enters the event loop and causes log events to be consumed and
diff --git a/lib/Message/Passing/Input/STDIN.pm b/lib/Message/Passing/Input/STDIN.pm
index 0faec73..1c409db 100644
--- a/lib/Message/Passing/Input/STDIN.pm
+++ b/lib/Message/Passing/Input/STDIN.pm
@@ -12,10 +12,8 @@ sub BUILD {
         my $input = <STDIN>;
         return unless defined $input;
         chomp($input);
-        my $data = try { $self->decode($input) }
-            catch { warn $_ };
-        return unless $data;
-        $self->output_to->consume($data);
+        return unless length $input;
+        $self->output_to->consume($input);
         $r;
     });
 }
diff --git a/lib/Message/Passing/Output/File.pm b/lib/Message/Passing/Output/File.pm
index ebc3eea..459b560 100644
--- a/lib/Message/Passing/Output/File.pm
+++ b/lib/Message/Passing/Output/File.pm
@@ -40,7 +40,7 @@ sub consume {
     my $self = shift;
     my $saved = select($self->fh);
     local $|=1;
-    print $self->encode(shift()) . "\n";
+    print shift() . "\n";
     select($saved);
     return 1;
 }
diff --git a/lib/Message/Passing/Output/STDOUT.pm b/lib/Message/Passing/Output/STDOUT.pm
index e09c092..dca652a 100644
--- a/lib/Message/Passing/Output/STDOUT.pm
+++ b/lib/Message/Passing/Output/STDOUT.pm
@@ -7,7 +7,7 @@ with 'Message::Passing::Role::Output';
 sub consume {
     my $self = shift;
     local $|=1;
-    print $self->encode(shift()) . "\n";
+    print shift() . "\n";
 }
 
 __PACKAGE__->meta->make_immutable;
diff --git a/lib/Message/Passing/Role/Input.pm b/lib/Message/Passing/Role/Input.pm
index 191d4bf..418118c 100644
--- a/lib/Message/Passing/Role/Input.pm
+++ b/lib/Message/Passing/Role/Input.pm
@@ -6,8 +6,6 @@ use Message::Passing::Types qw/
 /;
 use namespace::autoclean;
 
-sub decode { from_json( $_[1], { utf8  => 1 } ) }
-
 has output_to => (
     isa => Output_Type,
     is => 'ro',
diff --git a/lib/Message/Passing/Role/Output.pm b/lib/Message/Passing/Role/Output.pm
index cda4b84..0305ccd 100644
--- a/lib/Message/Passing/Role/Output.pm
+++ b/lib/Message/Passing/Role/Output.pm
@@ -10,12 +10,6 @@ has pretty => (
     is => 'ro',
 );
 
-sub encode {
-    my ($self, $message) = @_;
-    $message = $message->pack if blessed($message) && $message->can('pack');
-    to_json( $message, { utf8  => 1, $self->pretty ? (pretty => 1) : () } )
-}
-
 requires 'consume';
 
 1;
diff --git a/t/logstash_script.t b/t/logstash_script.t
index eb6bf49..b5bea35 100644
--- a/t/logstash_script.t
+++ b/t/logstash_script.t
@@ -17,10 +17,14 @@ is_deeply {$i->filter_options}, {"baz" => "quux"};
 is_deeply {$i->output_options}, {"x" => "m"};
 
 my $chain = $i->build_chain;
-my $output = $chain->[0]->output_to;
-$output->consume({ foo => "bar" });
+my $input = $chain->[0];
+my $decoder = $input->output_to;
+my $filter = $decoder->output_to;
+my $encoder = $filter->output_to;
+my $output = $encoder->output_to;
+$filter->consume({ foo => "bar" });
 
-is_deeply [$output->output_to->messages], [{ foo => "bar" }];
+is_deeply [$output->messages], ['{"foo":"bar"}'];
 
 done_testing;
 
diff --git a/t/output_encode.t b/t/output_encode.t
index ff2f925..85e0eff 100644
--- a/t/output_encode.t
+++ b/t/output_encode.t
@@ -12,9 +12,13 @@ use Try::Tiny;
 }
 
 use Message::Passing::Output::Test;
+use Message::Passing::Filter::Encoder::JSON;
 
-my $test = Message::Passing::Output::Test->new();
-my $packed = $test->encode(bless {}, 'Message');
+my $packed;
+my $test = Message::Passing::Output::Test->new(cb => sub { $packed = shift });
+my $encoder = Message::Passing::Filter::Encoder::JSON->new(output_to => $test);
+
+$encoder->consume(bless {}, 'Message');
 
 is $packed, '{"foo":"bar"}';
 

-- 
libmessage-passing-perl Debian packaging



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