package Tak::JSONChannel;
use JSON::PP qw(encode_json decode_json);
use IO::Handle;
use Scalar::Util qw(weaken);
use Log::Contextual qw(:log);
use Moo;
has read_fh => (is => 'ro', required => 1);
ha
ine {
my ($self, $line) = @_;
my $data = eval { decode_json($line) };
unless ($data) {
$self->write_message(mistake => invalid_json => $@||'No data and no exception');
return;
}
unle
b write_message {
my ($self, @msg) = @_;
my $json = eval { encode_json(\@msg) };
unless ($json) {
$self->_raw_write_message(
encode_json(
[ failure => invalid_message => $@||'N
use JSON::PP qw(encode_json decode_json);
use Moo::Role;
requires 'inflate';
requires 'deflate';
has encoder_json => (is => 'lazy');
has decoder_json => (is => 'lazy');
sub _build_encoder_json {
ow_nonref(1)->convert_blessed(1);
}
sub _build_decoder_json {
my $self = shift;
weaken($self);
JSON::PP->new->allow_nonref(1)->filter_json_single_key_object(
__proxied_object__ => sub { $se
ERSAL::TO_JSON = sub { $self->deflate($_[0]) };
decode_json($self->encoder_json->encode($data));
}
sub decode_objects {
my ($self, $data) = @_;
$self->decoder_json->decode(encode_json($data));
mer> - brilliant. beautiful. insane. extensive. excessive. try it.
L<JSON::XS> - no, really. If it's just plain data, JSON is a great option.
=head1 AUTHOR
mst - Matt S. Trout <mst@shad
ore details.
EXPORTER_DECLARE_SPECS
$fatpacked{"JSON/PP.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'JSON_PP';
package JSON::PP;
# JSON-2.0
use 5.005;
use strict;
use base qw(
se Carp ();
use B ();
#use Devel::Peek;
$JSON::PP::VERSION = '2.27203';
@JSON::PP::EXPORT = qw(encode_json decode_json from_json to_json);
# instead of hash-access, i tried index-ac