| 1 | package Net::Lumberjack::Reader; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | # ABSTRACT: class to read lumberjack frame stream | ||||||||||||||||||||
| 6 | 1 | our $VERSION = '1.01'; # VERSION | |||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 1 | ▶ | use Net::Lumberjack::Frame; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use Net::Lumberjack::Frame::Ack; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use IO::String; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 1 | has 'handle' => ( is => 'ro', required => 1 ); | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 1 | has 'unacked_frames' => ( | |||||||||||||||||||
| 15 | is => 'ro', isa => 'Int', default => 0, | ||||||||||||||||||||
| 16 | traits => [ 'Counter' ], | ||||||||||||||||||||
| 17 | handles => { | ||||||||||||||||||||
| 18 | inc_unacked_frames => 'inc', | ||||||||||||||||||||
| 19 | reset_unacked_frames => 'reset', | ||||||||||||||||||||
| 20 | }, | ||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||
| 22 | 1 | has 'last_seq' => ( is => 'rw', isa => 'Int', default => 0 ); | |||||||||||||||||||
| 23 | 1 | has 'window_size' => ( is => 'rw', isa => 'Int', default => 1 ); | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | sub read_data { | ||||||||||||||||||||
| 26 | 0 | ▶ | my ( $self, $conn ) = @_; | ||||||||||||||||||
|
Subroutine
read_data: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||
| 27 | 0 | my $substream = 0; | |||||||||||||||||||
| 28 | 0 | ▶ | if( defined $conn ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | 0 | $substream = 1; | |||||||||||||||||||
| 30 | } else { | ||||||||||||||||||||
| 31 | 0 | $conn = $self->handle; | |||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | 0 | my @data; | |||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 0 | ▶ | while( my $frame = Net::Lumberjack::Frame->new_from_fh($conn) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | 0 | ▶ | if( $frame->can('data') ) { | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 37 | 0 | push(@data, $frame->data); | |||||||||||||||||||
| 38 | ▶ | } elsif( ! $substream | |||||||||||||||||||
|
Condition0%0/3
not $substream and ref $frame eq "Net::Lumberjack::Frame::Compressed"
MC/DC0%0/2
not $substream and ref $frame eq "Net::Lumberjack::Frame::Compressed"
not $substream
ref $frame eq "Net::Lumberjack::Frame::Compressed"
Truth table0%0/3
not(A) and B
A= not $substreamB= ref $frame eq "Net::Lumberjack::Frame::Compressed"
| |||||||||||||||||||||
| 39 | && ref($frame) eq 'Net::Lumberjack::Frame::Compressed' ) { | ||||||||||||||||||||
| 40 | 0 | my $io_compressed = IO::String->new( $frame->stream ); | |||||||||||||||||||
| 41 | 0 | ▶ | while( my @subdata = $self->read_data($io_compressed) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 0 | push(@data, @subdata); | |||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | } elsif( ref($frame) eq 'Net::Lumberjack::Frame::WindowSize' ) { | ||||||||||||||||||||
| 45 | 0 | $self->window_size( $frame->window_size ); | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 0 | ▶ | if( $frame->can('seq') ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | 0 | $self->last_seq( $frame->seq ); | |||||||||||||||||||
| 50 | 0 | $self->inc_unacked_frames(); | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | 0 | ▶ | if( $self->unacked_frames >= $self->window_size ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | 0 | $self->send_ack; | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | 0 | ▶ | if( @data ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 0 | return @data; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | 0 | return; | |||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | sub send_ack { | ||||||||||||||||||||
| 63 | 0 | ▶ | my ( $self ) = @_; | ||||||||||||||||||
|
Subroutine
send_ack: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 64 | 0 | ▶ | if( ! $self->unacked_frames ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | 0 | return; # nothing to ack | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | 0 | my $ack = Net::Lumberjack::Frame::Ack->new( | |||||||||||||||||||
| 68 | 'seq' => $self->last_seq, | ||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||
| 70 | 0 | $self->handle->print( $ack->as_string ); | |||||||||||||||||||
| 71 | 0 | $self->reset_unacked_frames; | |||||||||||||||||||
| 72 | 0 | return; | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 1 | 1; | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | __END__ | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | =pod | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | =encoding UTF-8 | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | =head1 NAME | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | Net::Lumberjack::Reader - class to read lumberjack frame stream | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | =head1 VERSION | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | version 1.01 | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | =head1 AUTHOR | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | Markus Benning <ich@markusbenning.de> | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | This software is Copyright (c) 2016 by Markus Benning. | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | This is free software, licensed under: | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | The Apache License, Version 2.0, January 2004 | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | =cut | ||||||||||||||||||||