[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:41 UTC 2013
The following commit has been merged in the master branch:
commit a9b500e496cd8f723c32689d76cd19f2fc6b0acc
Author: Tomas Doran <bobtfish at bobtfish.net>
Date: Sun Aug 26 21:03:16 2012 +0100
Add error chain support for decoding
diff --git a/Changes b/Changes
index 74a4496..c2c45c1 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,5 @@
- - Add error chain support to the JSON encoder so that an error is
- logged if JSON encoding fails.
+ - Add error chain support to the JSON encoder and decoder so that an
+ error is logged if JSON encoding or decoding fails.
- Make default error chain do JSON encoding on errors so that they're
readable.
diff --git a/lib/Message/Passing/Exception/Encoding.pm b/lib/Message/Passing/Exception/Decoding.pm
similarity index 61%
copy from lib/Message/Passing/Exception/Encoding.pm
copy to lib/Message/Passing/Exception/Decoding.pm
index b5aab94..134a247 100644
--- a/lib/Message/Passing/Exception/Encoding.pm
+++ b/lib/Message/Passing/Exception/Decoding.pm
@@ -1,4 +1,4 @@
-package Message::Passing::Exception::Encoding;
+package Message::Passing::Exception::Decoding;
use Moo;
use Data::Dumper ();
use MooX::Types::MooseLike::Base qw/ Str /;
@@ -9,21 +9,20 @@ with 'Message::Passing::Exception';
has exception => (
is => 'ro',
required => 1,
+ isa => 'Str',
);
-has stringified_data => (
+has packed_data => (
is => 'ro',
isa => Str,
- coerce => sub {
- Data::Dumper::Dumper($_[0]);
- },
+ required => 1,
);
1;
=head1 NAME
-Message::Passing::Exception::Encoding - An issue when encoding data
+Message::Passing::Exception::Decoding - An issue when decoding data
=head1 ATTRIBUTES
@@ -31,9 +30,9 @@ Message::Passing::Exception::Encoding - An issue when encoding data
The exception encountered when trying to encode the message
-=head2 stringified_data
+=head2 packed_data
-The original message, dumped using L<Data::Dumper>.
+The original message.
=head1 AUTHOR, COPYRIGHT AND LICENSE
diff --git a/lib/Message/Passing/Filter/Decoder/JSON.pm b/lib/Message/Passing/Filter/Decoder/JSON.pm
index 2ef20f3..326007d 100644
--- a/lib/Message/Passing/Filter/Decoder/JSON.pm
+++ b/lib/Message/Passing/Filter/Decoder/JSON.pm
@@ -1,12 +1,28 @@
package Message::Passing::Filter::Decoder::JSON;
use Moo;
use JSON qw/ from_json /;
+use Try::Tiny;
+use Message::Passing::Exception::Decoding;
use namespace::clean -except => 'meta';
-with 'Message::Passing::Role::Filter';
-
-sub filter { ref($_[1]) ? $_[1] : from_json( $_[1], { utf8 => 1 } ) }
-
+with qw/
+ Message::Passing::Role::Filter
+ Message::Passing::Role::HasErrorChain
+/;
+
+sub filter {
+ my ($self, $message) = @_;
+ try {
+ ref($message) ? $message : from_json( $message, { utf8 => 1 } )
+ }
+ catch {
+ $self->error->consume(Message::Passing::Exception::Decoding->new(
+ exception => $_,
+ packed_data => $message,
+ ));
+ return; # Explicit return undef
+ };
+}
1;
@@ -41,11 +57,12 @@ JSON decodes a message supplied as a parameter.
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 -
+the SureVoIP API -
<http://www.surevoip.co.uk/support/wiki/api_documentation>
=head1 AUTHOR, COPYRIGHT AND LICENSE
See L<Message::Passing>.
-=cut
\ No newline at end of file
+=cut
+
--
libmessage-passing-perl Debian packaging
More information about the Pkg-perl-cvs-commits
mailing list