| 1 | package Net::Lumberjack::Frame::Data; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # ABSTRACT: class for parsing Lumberjack data frames | ||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '1.01'; # VERSION | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | extends 'Net::Lumberjack::Frame'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | has 'type' => ( is => 'ro', isa => 'Str', default => 'D' ); | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | has 'seq' => ( is => 'rw', isa => 'Maybe[Int]' ); | |||||||||||||||||||||||||||
| 13 | 1 | has 'data' => ( is => 'rw', isa => 'Maybe[HashRef]' ); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | has 'payload' => ( | ||||||||||||||||||||||||||||
| 16 | is => 'rw', isa => 'Str', lazy => 1, | ||||||||||||||||||||||||||||
| 17 | default => sub { | ||||||||||||||||||||||||||||
| 18 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 19 | 0 | my $pairs = scalar keys %{$self->data}; | |||||||||||||||||||||||||||
| 20 | 0 | my $data = ''; | |||||||||||||||||||||||||||
| 21 | 0 | foreach my $key ( keys %{$self->data} ) { | |||||||||||||||||||||||||||
| 22 | # skip if emtpy or not a scalar | ||||||||||||||||||||||||||||
| 23 | 0 | ▶ | if( ! defined $self->data->{$key} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $self->data->{$key} or ref $self->data->{$key}
MC/DC0%0/2
not defined $self->data->{$key} or ref $self->data->{$key}
not defined $self->data->{$key}
ref $self->data->{$key}
Truth table0%0/3
not(A) or B
A= not defined $self->data->{$key}B= ref $self->data->{$key}
| |||||||||||||||||||||||||||||
| 24 | || ref($self->data->{$key}) ) { | ||||||||||||||||||||||||||||
| 25 | 0 | next; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | 0 | my $keylen = length($key); | |||||||||||||||||||||||||||
| 28 | 0 | $data .= pack('N', $keylen).$key; | |||||||||||||||||||||||||||
| 29 | 0 | my $valuelen = length( $self->data->{$key} ); | |||||||||||||||||||||||||||
| 30 | 0 | $data .= pack('N', $valuelen).$self->data->{$key}; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | 0 | return pack('NN', $self->seq, $pairs).$data; | |||||||||||||||||||||||||||
| 33 | }, | ||||||||||||||||||||||||||||
| 34 | 1 | ); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | sub _read_payload { | ||||||||||||||||||||||||||||
| 37 | 0 | ▶ | my ( $self, $fh ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_read_payload: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 38 | 0 | my $data = {}; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | $self->seq( $self->_read_uint32($fh) ); | |||||||||||||||||||||||||||
| 41 | 0 | my $pairs = $self->_read_uint32($fh); | |||||||||||||||||||||||||||
| 42 | 0 | ▶ | for( my $i = 0 ; $i < $pairs ; $i++ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | my $key = $self->_read_data($fh); | |||||||||||||||||||||||||||
| 44 | 0 | my $value = $self->_read_data($fh); | |||||||||||||||||||||||||||
| 45 | 0 | $data->{$key} = $value; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | 0 | $self->data( $data ); | |||||||||||||||||||||||||||
| 48 | 0 | return; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 1 | 1; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | __END__ | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =pod | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =head1 NAME | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | Net::Lumberjack::Frame::Data - class for parsing Lumberjack data frames | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =head1 VERSION | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | version 1.01 | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | Markus Benning <ich@markusbenning.de> | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | This software is Copyright (c) 2016 by Markus Benning. | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | This is free software, licensed under: | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | The Apache License, Version 2.0, January 2004 | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =cut | ||||||||||||||||||||||||||||