[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:40 UTC 2013
The following commit has been merged in the master branch:
commit 6ab94c78d3dd8c490d5c43a3e712963473de1afd
Author: Tomas Doran <bobtfish at bobtfish.net>
Date: Sun Aug 26 10:38:59 2012 +0100
Add proper exception classes
diff --git a/lib/Message/Passing/Exception.pm b/lib/Message/Passing/Exception.pm
new file mode 100644
index 0000000..beb0656
--- /dev/null
+++ b/lib/Message/Passing/Exception.pm
@@ -0,0 +1,14 @@
+package Message::Passing::Exception;
+use Moo::Role;
+use namespace::clean -except => 'meta';
+
+sub as_hash {
+ { %{ $_[0] }, class => ref($_[0]) }
+}
+
+sub pack {
+ $_[0]->as_hash;
+}
+
+1;
+
diff --git a/lib/Message/Passing/Exception/Encoding.pm b/lib/Message/Passing/Exception/Encoding.pm
new file mode 100644
index 0000000..1c8cb56
--- /dev/null
+++ b/lib/Message/Passing/Exception/Encoding.pm
@@ -0,0 +1,23 @@
+package Message::Passing::Exception::Encoding;
+use Moo;
+use Data::Dumper ();
+use MooX::Types::MooseLike::Base qw/ Str /;
+use namespace::clean -except => 'meta';
+
+with 'Message::Passing::Exception';
+
+has exception => (
+ is => 'ro',
+ required => 1,
+);
+
+has stringified_data => (
+ is => 'ro',
+ isa => Str,
+ coerce => sub {
+ Data::Dumper::Dumper($_[0]);
+ },
+);
+
+1;
+
diff --git a/lib/Message/Passing/Filter/Encoder/JSON.pm b/lib/Message/Passing/Filter/Encoder/JSON.pm
index 3980775..2552319 100644
--- a/lib/Message/Passing/Filter/Encoder/JSON.pm
+++ b/lib/Message/Passing/Filter/Encoder/JSON.pm
@@ -4,7 +4,7 @@ use MooX::Types::MooseLike::Base qw/ Bool /;
use JSON qw/ to_json /;
use Scalar::Util qw/ blessed /;
use Try::Tiny;
-use Data::Dumper ();
+use Message::Passing::Exception::Encoding;
use namespace::clean -except => 'meta';
with qw/
@@ -33,11 +33,10 @@ sub filter {
to_json( $message, { utf8 => 1, $self->pretty ? (pretty => 1) : () } )
}
catch {
- $self->error->consume({
- class => 'Message::Passing::Exception::Encoding',
+ $self->error->consume(Message::Passing::Exception::Encoding->new(
exception => $_,
- stringified_data => Data::Dumper::Dumper($message),
- });
+ stringified_data => $message,
+ ));
return; # Explicitly drop the message from normal processing
}
}
diff --git a/t/errorchain.t b/t/errorchain.t
new file mode 100644
index 0000000..54dcb58
--- /dev/null
+++ b/t/errorchain.t
@@ -0,0 +1,26 @@
+use strict;
+use warnings;
+
+use Test::More 0.88;
+
+use_ok 'Message::Passing::Filter::Encoder::JSON';
+use_ok 'Message::Passing::Output::Test';
+
+my $test = Message::Passing::Output::Test->new;
+my $test_e = Message::Passing::Output::Test->new;
+my $encoder = Message::Passing::Filter::Encoder::JSON->new(
+ output_to => $test,
+ error => $test_e,
+);
+$encoder->consume({ foo => bless {}, 'Bar' });
+is $test->message_count, 0;
+is $test_e->message_count, 1;
+my ($m) = $test_e->messages;
+#{"exception":"encountered object 'Bar=HASH(0x7fab21236f30)', but neither allow_blessed nor convert_blessed settings are enabled at /Users/t0m/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/JSON.pm line 154.\n","class":"Message::Passing::Exception::Encoding","stringified_data":"$VAR1 = {\n 'foo' => bless( {}, 'Bar' )\n };\n"}
+is ref($m), 'HASH';
+is $m->{'class'}, 'Message::Passing::Exception::Encoding';
+ok exists $m->{'exception'};
+ok exists $m->{'stringified_data'};
+
+done_testing;
+
--
libmessage-passing-perl Debian packaging
More information about the Pkg-perl-cvs-commits
mailing list