Lumberjack/Reader.pm

filter: Statementstmt 39.1% 18 / 46 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 66.6% 4 / 6 Podpod 0.0% 0 / 2 totaltotal 27.8% 22 / 79 CC 12 SCAR 44.6
CC
12
Cov
26%
read_data
132.0
send_ack
6.0
BEGIN
1.0
CRAP 86.4
« Lumberjack/Client.pm ↑ Summary Lumberjack/Writer.pm »
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
BranchTrueFalseTotal
if (defined $conn) { } 0 0 0
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
BranchTrueFalseTotal
if (my $frame = "Net::Lumberjack::Frame"->new_from_fh($conn)) 0 0 0
36 0 ▶ if( $frame->can('data') ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($frame->can('data')) { } 0 0 0
elsif (not $substream and ref $frame eq 'Net::Lumberjack::Frame::Compressed') { } 0 0 0
elsif (ref $frame eq 'Net::Lumberjack::Frame::WindowSize') { } 0 0 0
37 0 push(@data, $frame->data);
38 ▶ } elsif( ! $substream
Condition0%0/3
not $substream and ref $frame eq "Net::Lumberjack::Frame::Compressed"
!ll&&!rl&&r
000
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (my(@subdata) = $self->read_data($io_compressed)) 0 0 0
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
BranchTrueFalseTotal
if ($frame->can("seq")) 0 0 0
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
BranchTrueFalseTotal
if ($self->unacked_frames >= $self->window_size) 0 0 0
53 0 $self->send_ack;
54 }
55 0 ▶ if( @data ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) 0 0 0
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
BranchTrueFalseTotal
unless ($self->unacked_frames) 0 0 0
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
« Lumberjack/Client.pm ↑ Summary Lumberjack/Writer.pm »