e Net::Lumberjack::Frame::JSON;
use Moose;
# ABSTRACT: class for parsing Lumberjack JSON frames
our $VERSION = '1.02'; # VERSION
extends 'Net::Lumberjack::Frame';
use JSON;
has 'type' => ( is =>
lt => sub {
my $self = shift;
my $json_str = encode_json( $self->data );
my $len = length($json_str);
return pack('NN', $self->seq, $len).$json_str;
},
);
sub _read_payload {
my (
$self->data( decode_json($self->_read_data($fh)) );
return;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Net::Lumberjack::Frame::JSON - class for parsing Lumberjack JSON frames
=head1 VERS
d;
use Net::Lumberjack::Frame::Ack;
use Net::Lumberjack::Frame::Data;
use Net::Lumberjack::Frame::JSON;
has 'version' => ( is => 'rw', isa => 'Int', default => 1 );
has 'type' => ( is => 'rw', isa =>
YPES = (
'A' => 'Ack',
'W' => 'WindowSize',
'C' => 'Compressed',
'D' => 'Data',
'J' => 'JSON',
);
sub new_from_fh {
my ( $class, $fh ) = ( shift, shift );
my ( $version, $type );
# EOF
use Net::Lumberjack::Frame;
use Net::Lumberjack::Frame::WindowSize;
use Net::Lumberjack::Frame::JSON;
use Net::Lumberjack::Frame::Compressed;
has 'handle' => ( is => 'ro', required => 1 );
has 'se
isa => 'Str', default => 'json');
has '_frame_class' => (
is => 'ro', isa => 'Str', lazy => 1,
default => sub {
my $self = shift;
if( $self->frame_format eq 'json' || $self->frame_format e
q 'v2' ) {
return "Net::Lumberjack::Frame::JSON";
} elsif( $self->frame_format eq 'data' || $self->frame_format eq 'v1' ) {
return "Net::Lumberjack::Frame::Data";
} else {
di
er
keepalive => 0,
frame_format => 'json',
## for a saftpresse (Log::Saftpresse) server
# keepalive => 1, # or 0
# frame_format => 'json',
## for a lumberjack (v1) server
#
f frames per connection.
=head2 frame_formt (default: 'json')
The following frame formats are supported:
=over
=item 'json', 'v2'
Uses json formatted data frames as defined in lumberjack protocol