[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 786b4bed3f7dc49e3c87e2aed96baa22630b2400
Author: Tomas Doran <bobtfish at bobtfish.net>
Date: Fri Jun 8 01:24:48 2012 +0100
Add to last commit
diff --git a/lib/Message/Passing/Role/Input.pm b/lib/Message/Passing/Filter/Decoder/JSON.pm
similarity index 65%
copy from lib/Message/Passing/Role/Input.pm
copy to lib/Message/Passing/Filter/Decoder/JSON.pm
index 418118c..4596735 100644
--- a/lib/Message/Passing/Role/Input.pm
+++ b/lib/Message/Passing/Filter/Decoder/JSON.pm
@@ -1,37 +1,28 @@
-package Message::Passing::Role::Input;
-use Moose::Role;
+package Message::Passing::Filter::Decoder::JSON;
+use Moose;
use JSON qw/ from_json /;
-use Message::Passing::Types qw/
- Output_Type
-/;
use namespace::autoclean;
-has output_to => (
- isa => Output_Type,
- is => 'ro',
- required => 1,
- coerce => 1,
-);
+with 'Message::Passing::Role::Filter';
+sub filter { from_json( $_[1], { utf8 => 1 } ) }
+
+__PACKAGE__->meta->make_immutable;
1;
=head1 NAME
-Message::Passing::Role::Input
+Message::Passing::Role::Filter::Decoder::JSON
=head1 DESCRIPTION
-Produces messages.
+Decodes string messages from JSON into data structures.
=head1 ATTRIBUTES
-=head2 output_to
-
-Required, must perform the L<Message::Passing::Role::Output> role.
-
=head1 METHODS
-=head2 decode
+=head2 filter
JSON decodes a message supplied as a parameter.
diff --git a/lib/Message/Passing/Filter/Encoder/JSON.pm b/lib/Message/Passing/Filter/Encoder/JSON.pm
new file mode 100644
index 0000000..f4cfead
--- /dev/null
+++ b/lib/Message/Passing/Filter/Encoder/JSON.pm
@@ -0,0 +1,82 @@
+package Message::Passing::Filter::Encoder::JSON;
+use Moose;
+use JSON qw/ to_json /;
+use Scalar::Util qw/ blessed /;
+use namespace::autoclean;
+
+with 'Message::Passing::Role::Filter';
+
+has pretty => (
+ isa => 'Bool',
+ default => 0,
+ is => 'ro',
+);
+
+sub filter {
+ my ($self, $message) = @_;
+ if (blessed $message) { # FIXME - This should be moved out of here!
+ if ($message->can('pack')) {
+ $message = $message->pack;
+ }
+ elsif ($message->can('to_hash')) {
+ $message = $message->to_hash;
+ }
+ }
+ to_json( $message, { utf8 => 1, $self->pretty ? (pretty => 1) : () } )
+}
+
+__PACKAGE__->meta->make_immutable;
+1;
+
+=head1 NAME
+
+Message::Passing::Role::Filter::Encoder::JSON - Encodes data structures as JSON for output
+
+=head1 DESCRIPTION
+
+This filter takes a hash ref or an object for a message, and serializes it to JSON.
+
+Plain refs work as expected, and classes generated by either:
+
+=over
+
+=item Log::Message::Structures
+
+=item MooseX::Storage
+
+=back
+
+should be correctly serialized.
+
+=head1 METHODS
+
+=head2 filter
+
+Performs the JSON encoding.
+
+=head1 SEE ALSO
+
+=over
+
+=item L<Message::Passing>
+
+=item L<Message::Passing::Manual::Concepts>
+
+=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
+
+1;
+
--
libmessage-passing-perl Debian packaging
More information about the Pkg-perl-cvs-commits
mailing list