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


The following commit has been merged in the master branch:
commit 0d42ea9a1f37598187a490a7d58a7478f7d669bd
Author: Tomas Doran <bobtfish at bobtfish.net>
Date:   Sun Apr 15 16:57:25 2012 +0100

    Coerce outputs from inputs as needed.
    
    Not as pretty as the DSL, but much more useful in cases where
    you may not want to use the DSL, such as setting up the config for
    your Log::Stash output class with application config, having
    used the Log::Dispatch input.

diff --git a/lib/Log/Stash/Role/Input.pm b/lib/Log/Stash/Role/Input.pm
index b381ff9..9dfa58b 100644
--- a/lib/Log/Stash/Role/Input.pm
+++ b/lib/Log/Stash/Role/Input.pm
@@ -1,14 +1,26 @@
 package Log::Stash::Role::Input;
 use Moose::Role;
 use JSON qw/ from_json /;
+use Moose::Util::TypeConstraints;
 use namespace::autoclean;
 
 sub decode { from_json( $_[1], { utf8  => 1 } ) }
 
+role_type 'Log::Stash::Role::Output';
+coerce 'Log::Stash::Role::Output',
+    from 'HashRef',
+    via {
+        my %stuff = %$_;
+        my $class = delete($stuff{class});
+        Class::MOP::load_class($class);
+        $class->new(%stuff);
+    };
+
 has output_to => (
     does => 'Log::Stash::Role::Output',
     is => 'ro',
     required => 1,
+    coerce => 1,
 );
 
 1;
diff --git a/t/input_output_coerce.t b/t/input_output_coerce.t
new file mode 100644
index 0000000..c507680
--- /dev/null
+++ b/t/input_output_coerce.t
@@ -0,0 +1,17 @@
+use strict;
+use warnings;
+use Test::More 0.88;
+
+use Log::Stash::Input::STDIN;
+
+my $i = Log::Stash::Input::STDIN->new(
+    output_to => {
+        class => 'Log::Stash::Output::Test',
+    },
+);
+
+ok $i;
+isa_ok($i->output_to, 'Log::Stash::Output::Test');
+
+done_testing;
+

-- 
libmessage-passing-perl Debian packaging



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