/usr/share/perl5/Message/Passing/Filter/Encoder/JSON.pm is in libmessage-passing-perl 0.116-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | package Message::Passing::Filter::Encoder::JSON;
use Moo;
use MooX::Types::MooseLike::Base qw( Bool HasMethods );
use JSON::MaybeXS qw ();
use Scalar::Util qw/ blessed /;
use Try::Tiny;
use Message::Passing::Exception::Encoding;
use namespace::clean -except => 'meta';
with qw/
Message::Passing::Role::Filter
Message::Passing::Role::HasErrorChain
/;
has pretty => (
isa => Bool,
default => sub { 0 },
is => 'ro',
);
has _json => (
is => 'lazy',
isa => HasMethods [qw( encode )],
default => sub {
my $self = shift;
return JSON::MaybeXS->new( utf8 => 1, pretty => $self->pretty );
},
);
sub filter {
my ($self, $message) = @_;
try {
return $message unless ref($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;
}
}
$self->_json->encode( $message );
}
catch {
$self->error->consume(Message::Passing::Exception::Encoding->new(
exception => $_,
stringified_data => $message,
));
return; # Explicitly drop the message from normal processing
}
}
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.
=head2 pretty
Attribute controlling if JSON is pretty printed.
=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
|