Lumberjack/Writer.pm

filter: Statementstmt 42.1% 24 / 57 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 55.5% 5 / 9 Podpod 0.0% 0 / 3 totaltotal 29.2% 29 / 99 CC 13 SCAR 29.4
CC
13
Cov
29%
__ANON__
30.0
send_data
30.0
wait_for_ack
20.0
CRAP 18.9
« Lumberjack/Reader.pm ↑ Summary Lumberjack/Frame/Data.pm »
1 package Net::Lumberjack::Writer;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: class to generate 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::WindowSize;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Net::Lumberjack::Frame::JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Net::Lumberjack::Frame::Compressed;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 has 'handle' => ( is => 'ro', required => 1 );
14  
15 1 has 'seq' => (
16 is => 'ro', isa => 'Int', default => 0,
17 traits => [ 'Counter' ],
18 handles => {
19 next_seq => 'inc',
20 },
21 );
22 1 has 'last_ack' => ( is => 'rw', isa => 'Int', default => 0 );
23 1 has 'max_window_size' => ( is => 'rw', isa => 'Int', default => 2048 );
24  
25 1 has 'current_window_size' => ( is => 'rw', isa => 'Int', default => 0 );
26  
27 1 has 'frame_format' => ( is => 'ro', isa => 'Str', default => 'json');
28 has '_frame_class' => (
29 is => 'ro', isa => 'Str', lazy => 1,
30 default => sub {
31 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=5 SCAR=34.0
32 0 ▶ if( $self->frame_format eq 'json' || $self->frame_format eq 'v2' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->frame_format eq 'json' or $self->frame_format eq 'v2') { } 0 0 0
elsif ($self->frame_format eq 'data' or $self->frame_format eq 'v1') { } 0 0 0
Condition0%0/3
$self->frame_format eq "json" or $self->frame_format eq "v2"
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->frame_format eq "json" or $self->frame_format eq "v2"
$self->frame_format eq "json" $self->frame_format eq "v2"
Truth table0%0/3
A or B
A= $self->frame_format eq "json"B= $self->frame_format eq "v2"
ABresult
1X1
011
000
33 0 return "Net::Lumberjack::Frame::JSON";
34 ▶ } elsif( $self->frame_format eq 'data' || $self->frame_format eq 'v1' ) {
Condition0%0/3
$self->frame_format eq "data" or $self->frame_format eq "v1"
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->frame_format eq "data" or $self->frame_format eq "v1"
$self->frame_format eq "data" $self->frame_format eq "v1"
Truth table0%0/3
A or B
A= $self->frame_format eq "data"B= $self->frame_format eq "v1"
ABresult
1X1
011
000
35 0 return "Net::Lumberjack::Frame::Data";
36 } else {
37 0 die('invalid frame format specified: '.$self->frame_format);
38 }
39 },
40 1 );
41  
42 sub set_window_size {
43 0 ▶ my ( $self, $size ) = @_;
Subroutine set_window_size: not called CC=2 SCAR=17.9
Pod undocumented
44 0 ▶ if( $self->current_window_size != $size ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->current_window_size != $size) 0 0 0
45 0 my $window = Net::Lumberjack::Frame::WindowSize->new(
46 window_size => $size,
47 );
48 0 $self->handle->print( $window->as_string );
49 0 $self->current_window_size( $size );
50 }
51 0 return;
52 }
53  
54 sub send_data {
55 0 ▶ my ( $self, @data ) = @_;
Subroutine send_data: not called CC=5 SCAR=34.0
Pod undocumented
56  
57 0 ▶ if( ! @data ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@data) 0 0 0
58 0 return;
59 }
60  
61 0 ▶ while(@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) 0 0 0
62 0 ▶ my $num_bulk = scalar(@data) > $self->max_window_size ?
Branch: 1 branch
BranchTrueFalseTotal
scalar @data > $self->max_window_size ? : 0 0 0
63 $self->max_window_size : scalar(@data);
64 0 $self->set_window_size( $num_bulk );
65 0 my $stream = '';
66 0 ▶ for( my $i = 0 ; $i < $num_bulk ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $num_bulk) 0 0 0
67 0 my $frame_class = $self->_frame_class;
68 0 my $frame = $frame_class->new(
69 seq => $self->next_seq,
70 data => shift(@data),
71 );
72 0 $stream .= $frame->as_string;
73 }
74 0 my $compressed = Net::Lumberjack::Frame::Compressed->new(
75 stream => $stream,
76 );
77 0 $self->handle->print( $compressed->as_string );
78 0 $self->wait_for_ack( $self->seq );
79 }
80  
81 0 return;
82 }
83  
84 sub wait_for_ack {
85 0 ▶ my ( $self, $wait_for_seq ) = @_;
Subroutine wait_for_ack: not called CC=4 SCAR=30.0
Pod undocumented
86 0 ▶ while( my $frame = Net::Lumberjack::Frame->new_from_fh($self->handle) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $frame = "Net::Lumberjack::Frame"->new_from_fh($self->handle)) 0 0 0
87 0 ▶ if( ref($frame) eq 'Net::Lumberjack::Frame::Ack' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $frame eq "Net::Lumberjack::Frame::Ack") 0 0 0
88 0 $self->last_ack( $frame->seq );
89 }
90 0 ▶ if( $self->last_ack >= $wait_for_seq ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->last_ack >= $wait_for_seq) 0 0 0
91 0 last;
92 }
93 }
94 0 return;
95 }
96  
97 1 1;
98  
99 __END__
100  
101 =pod
102  
103 =encoding UTF-8
104  
105 =head1 NAME
106  
107 Net::Lumberjack::Writer - class to generate lumberjack frame stream
108  
109 =head1 VERSION
110  
111 version 1.01
112  
113 =head1 AUTHOR
114  
115 Markus Benning <ich@markusbenning.de>
116  
117 =head1 COPYRIGHT AND LICENSE
118  
119 This software is Copyright (c) 2016 by Markus Benning.
120  
121 This is free software, licensed under:
122  
123 The Apache License, Version 2.0, January 2004
124  
125 =cut
« Lumberjack/Reader.pm ↑ Summary Lumberjack/Frame/Data.pm »