| 1 | package Net::Lumberjack::Frame::JSON; | ||
| 2 | |||
| 3 | 1 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | # ABSTRACT: class for parsing Lumberjack JSON frames | ||
| 6 | 1 | our $VERSION = '1.01'; # VERSION | |
| 7 | |||
| 8 | 1 | extends 'Net::Lumberjack::Frame'; | |
| 9 | |||
| 10 | 1 | ▶ | use JSON; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | 1 | has 'type' => ( is => 'ro', isa => 'Str', default => 'J' ); | |
| 13 | 1 | has 'version' => ( is => 'rw', isa => 'Int', default => 2 ); | |
| 14 | |||
| 15 | 1 | has 'seq' => ( is => 'rw', isa => 'Maybe[Int]' ); | |
| 16 | 1 | has 'data' => ( is => 'rw', isa => 'Maybe[HashRef]' ); | |
| 17 | |||
| 18 | has 'payload' => ( | ||
| 19 | is => 'rw', isa => 'Str', lazy => 1, | ||
| 20 | default => sub { | ||
| 21 | 0 | ▶ | my $self = shift; |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 22 | 0 | my $json_str = encode_json( $self->data ); | |
| 23 | 0 | my $len = length($json_str); | |
| 24 | 0 | return pack('NN', $self->seq, $len).$json_str; | |
| 25 | }, | ||
| 26 | 1 | ); | |
| 27 | |||
| 28 | sub _read_payload { | ||
| 29 | 0 | ▶ | my ( $self, $fh ) = @_; |
|
Subroutine
_read_payload: not called CC=1 SCAR=6.9
| |||
| 30 | |||
| 31 | 0 | $self->seq( $self->_read_uint32($fh) ); | |
| 32 | 0 | $self->data( decode_json($self->_read_data($fh)) ); | |
| 33 | |||
| 34 | 0 | return; | |
| 35 | } | ||
| 36 | |||
| 37 | |||
| 38 | 1 | 1; | |
| 39 | |||
| 40 | __END__ | ||
| 41 | |||
| 42 | =pod | ||
| 43 | |||
| 44 | =encoding UTF-8 | ||
| 45 | |||
| 46 | =head1 NAME | ||
| 47 | |||
| 48 | Net::Lumberjack::Frame::JSON - class for parsing Lumberjack JSON frames | ||
| 49 | |||
| 50 | =head1 VERSION | ||
| 51 | |||
| 52 | version 1.01 | ||
| 53 | |||
| 54 | =head1 AUTHOR | ||
| 55 | |||
| 56 | Markus Benning <ich@markusbenning.de> | ||
| 57 | |||
| 58 | =head1 COPYRIGHT AND LICENSE | ||
| 59 | |||
| 60 | This software is Copyright (c) 2016 by Markus Benning. | ||
| 61 | |||
| 62 | This is free software, licensed under: | ||
| 63 | |||
| 64 | The Apache License, Version 2.0, January 2004 | ||
| 65 | |||
| 66 | =cut | ||