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


The following commit has been merged in the master branch:
commit 63e7679d3e156920bf1fef8fadc4a7b347832afa
Author: Tomas Doran <bobtfish at bobtfish.net>
Date:   Sun Jun 10 11:06:52 2012 +0100

    Add configfile

diff --git a/Changes b/Changes
index 5378d76..753299d 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,9 @@
+  - Documentation in the message-pass script
+
+  - Add --configfile option to default script, allowing
+    you to load config from a file, rather than supplying
+    it on command line.
+
   - Make JSON encoder pass non refs straight through,
     so that if a previous filter generates a scalar,
     then this gets sent as-is.
diff --git a/Makefile.PL b/Makefile.PL
index dec6eb3..00be1d4 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -16,6 +16,8 @@ resources(
 requires 'Moose';
 requires 'namespace::autoclean';
 requires 'AnyEvent';
+requires 'MooseX::ConfigFromFile';
+requires 'Config::Any';
 requires 'MooseX::Types';
 requires 'MooseX::Types::Common';
 requires 'MooseX::Types::LoadableClass';
diff --git a/README b/README
index 0da7075..bc55460 100644
--- a/README
+++ b/README
@@ -67,6 +67,7 @@ COMPONENTS
     Message::Passing::Input::STOMP
     Message::Passing::Input::AMQP
     Message::Passing::Input::Syslog
+    Message::Passing::Input::Redis
     Message::Passing::Input::Test
 
     You can easily write your own input, just use AnyEvent, and consume
@@ -99,6 +100,7 @@ COMPONENTS
     Message::Passing::Output::WebHooks
     Message::Passing::Output::ElasticSearch - COMING SOON
     (<https://github.com/suretec/Message-Passing-Output-ElasticSearch>)
+    Message::Passing::Output::Redis
     Message::Passing::Output::Test
 
 SEE ALSO
diff --git a/lib/Message/Passing.pm b/lib/Message/Passing.pm
index 1441090..4655097 100644
--- a/lib/Message/Passing.pm
+++ b/lib/Message/Passing.pm
@@ -1,6 +1,7 @@
 package Message::Passing;
 use Moose;
 use Getopt::Long qw(:config pass_through);
+use Config::Any;
 use namespace::autoclean;
 use 5.8.4;
 
@@ -8,6 +9,7 @@ use Message::Passing::DSL;
 
 with
     'MooseX::Getopt',
+    'MooseX::ConfigFromFile',
     'Message::Passing::Role::CLIComponent' => { name => 'input' },
     'Message::Passing::Role::CLIComponent' => { name => 'output' },
     'Message::Passing::Role::CLIComponent' => { name => 'filter', default => 'Null' },
@@ -18,6 +20,15 @@ with
 our $VERSION = '0.006';
 $VERSION = eval $VERSION;
 
+sub get_config_from_file {
+    my ($class, $filename) = @_;
+    my ($fn, $cfg) = %{ Config::Any->load_files({
+        files => [$filename],
+        use_ext => 1,
+    })->[0] };
+    return $cfg;
+}
+
 sub build_chain {
     my $self = shift;
         log_chain {
diff --git a/lib/Message/Passing/Role/CLIComponent.pm b/lib/Message/Passing/Role/CLIComponent.pm
index c78bb51..22f6776 100644
--- a/lib/Message/Passing/Role/CLIComponent.pm
+++ b/lib/Message/Passing/Role/CLIComponent.pm
@@ -41,3 +41,5 @@ role {
     );
 };
 
+1;
+
diff --git a/script/message-pass b/script/message-pass
index 63bfadd..34316b6 100755
--- a/script/message-pass
+++ b/script/message-pass
@@ -1,9 +1,133 @@
 #!perl
-use FindBin qw/ $Bin /;
-use lib "$Bin/../lib"; # FIXME
 use strict;
 use warnings;
 use Message::Passing;
 
 Message::Passing->start;
 
+1;
+
+=head1 NAME
+
+message-pass - command line Message::Passing runner script
+
+=head1 SYNOPSIS
+
+  message-pass [options]
+
+  Options:
+   --input           - Input short name (required)
+   --output          - Output short name (required)
+   --filter          - Filter short name (default Null)
+   --decoder         - Decoder short name (default JSON)
+   --encoder         - Encoder short name (default JSON)
+   --input_options   - JSON options string for input
+   --output_options  - JSON options string for output
+   --filter_options  - JSON options string for filter
+   --decoder_options - JSON options string for decoder
+   --encoder_options - JSON options string for encoder
+
+  OR:
+
+   --configfile     - Config file (to load with Config::Any)
+                      supplying the above options
+
+=head1 DESCRIPTION
+
+Builds a simple chain of L<Message::Passing> components, looking like this:
+
+    Input => Decoder => Filter => Encoder => Output
+
+This allows you to input a message from one protocol, decode it, process
+it and then output it again having encoded it.
+
+The simplest example of doing this is:
+
+    message-pass --input STDIN --output STDOUT
+
+Which will echo JSON strings you type back to the terminal.
+
+=head1 CLASS NAME EXPANSION
+
+All short class names undergo expansion as detailed below, except for names
+which are prefixed with a '+', which implies a full class name.
+
+E.g.
+
+    message-pass --input '+My::Example::Input' --output STDOUT
+
+The expansions are:
+
+=over
+
+=item input
+
+Message::Passing::Input::XXX
+
+=item output
+
+Message::Passing::Output::XXX
+
+=item filter
+
+Message::Passing::Filter::XXX
+
+=item encoder
+
+Message::Passing::Filter::Encoder::XXX
+
+=item decoder
+
+Message::Passing::Filter::Decoder::XXX
+
+=back
+
+=head1 CONFIG FILE
+
+If the C<< --configfile >> option is supplied, then a config file will
+be used.
+
+The format of data in this config file matches that required of the
+command line options, e.g.
+
+    {
+        "input":"XXX",
+        "input_options":{},
+        "output":"XXX",
+        "output_options":{},
+        "filter":"XXX",
+        "filter_options":{},
+        "encoder":"XXX",
+        "encoder_options":{},
+        "decoder":"XXX",
+        "decoder_options":{}
+    }
+
+Any config format supported by L<Config::Any> can be used, however JSON
+is the only format which is certain to work without additional dependencies
+which are not required by this module.
+
+=head1 SEE ALSO
+
+=over
+
+=item L<Message::Passing>
+
+=item L<Message::Passing::Manual>
+
+=back
+
+=head1 SPONSORSHIP
+
+This module exists due to the wonderful people at Suretec Systems Ltd.
+<http://www.suretecsystems.com/> who sponsored its development for its
+VoIP division called SureVoIP <http://www.surevoip.co.uk/> for use with
+the SureVoIP API - 
+<http://www.surevoip.co.uk/support/wiki/api_documentation>
+
+=head1 AUTHOR, COPYRIGHT AND LICENSE
+
+See L<Message::Passing>.
+
+=cut
+
diff --git a/t/author/podcoverage.t b/t/author/podcoverage.t
index 70dacbe..6ad5acc 100644
--- a/t/author/podcoverage.t
+++ b/t/author/podcoverage.t
@@ -9,6 +9,7 @@ my @modules = all_modules;
 our @private = ( 'BUILD' );
 foreach my $module (@modules) {
     local @private = (@private, 'expand_class_name', 'make') if $module =~ /^Message::Passing::DSL::Factory$/;
+    local @private = (@private, 'get_config_from_file') if $module =~ /^Message::Passing$/;
 
     pod_coverage_ok($module, {
         also_private   => \@private,
diff --git a/t/configfile.t b/t/configfile.t
new file mode 100644
index 0000000..ebe8303
--- /dev/null
+++ b/t/configfile.t
@@ -0,0 +1,38 @@
+use strict;
+use warnings;
+
+use Test::More 0.88;
+use File::Temp qw/ tempdir /;
+use JSON qw/ encode_json decode_json /;
+use File::Spec;
+
+my $dir = tempdir( CLEANUP => 1 );
+my $path = File::Spec->catfile($dir, 'config.json');
+open(my $fh, '>', $path)
+    or die $!;
+print $fh encode_json({
+    input => 'Null',
+    output => 'Test',
+    input_options => {
+        foo => 'bar',
+    },
+});
+close($fh);
+
+use_ok 'Message::Passing';
+
+my $i;
+{
+    local @ARGV = ('--configfile', $path);
+    $i = Message::Passing->new_with_options;
+}
+
+ok $i;
+is $i->input, 'Null';
+is $i->output, 'Test';
+is_deeply {$i->input_options}, {
+        foo => 'bar',
+    };
+
+done_testing;
+

-- 
libmessage-passing-perl Debian packaging



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