Lumberjack/Frame.pm

filter: Statementstmt 50.0% 24 / 48 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 54.5% 6 / 11 Podpod 0.0% 0 / 2 totaltotal 42.8% 30 / 70 CC 4 SCAR 19.0
CC
4
Cov
44%
new_from_fh
20.0
_read_payload
2.0
_read_uint32
2.0
CRAP 6.7
« Lumberjack/Frame/Data.pm ↑ Summary Lumberjack/Frame/Ack.pm »
1 package Net::Lumberjack::Frame;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: class for parsing Lumberjack protocol frames
6 1 our $VERSION = '1.01'; # VERSION
7  
8 1 ▶use Net::Lumberjack::Frame::WindowSize;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Net::Lumberjack::Frame::Compressed;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Net::Lumberjack::Frame::Ack;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Net::Lumberjack::Frame::Data;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Net::Lumberjack::Frame::JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 has 'version' => ( is => 'rw', isa => 'Int', default => 1 );
15 1 has 'type' => ( is => 'rw', isa => 'Str', required => 1 );
16 1 has 'payload' => ( is => 'rw', isa => 'Str', lazy => 1, default => '' );
17  
18 1 our %FRAME_TYPES = (
19 'A' => 'Ack',
20 'W' => 'WindowSize',
21 'C' => 'Compressed',
22 'D' => 'Data',
23 'J' => 'JSON',
24 );
25  
26 sub new_from_fh {
27 0 ▶ my ( $class, $fh ) = ( shift, shift );
Subroutine new_from_fh: not called CC=4 SCAR=30.0
Pod undocumented
28 0 my ( $version, $type );
29 # EOF not supported by IO::Socket::SSL
30 #if( $fh->eof ) {
31 # return;
32 #}
33 0 ▶ if( ! $fh->read( $version, 1 ) || ! $fh->read( $type, 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fh->read($version, 1) and $fh->read($type, 1)) 0 0 0
Condition0%0/3
$fh->read($version, 1) and $fh->read($type, 1)
!ll&&!rl&&r
000
MC/DC0%0/2
$fh->read($version, 1) and $fh->read($type, 1)
$fh->read($version, 1) $fh->read($type, 1)
Truth table0%0/3
A and B
A= $fh->read($version, 1)B= $fh->read($type, 1)
ABresult
0X0
100
111
34 0 die('lost connection');
35 }
36  
37 0 ▶ if( ! defined $FRAME_TYPES{$type} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Net::Lumberjack::Frame::FRAME_TYPES{$type}) 0 0 0
38 0 die('Unknown Lumberjack frame type: '.$type.'('.ord($type).')');
39 }
40  
41 0 my $type_class = $class.'::'.$FRAME_TYPES{$type};
42 0 my $obj = $type_class->new(
43 'version' => $version,
44 'type' => $type,
45 @_
46 );
47 0 $obj->_read_payload($fh);
48 0 return $obj;
49 }
50  
51 sub _read_payload {
52 0 ▶ my ( $self, $fh ) = @_;
Subroutine _read_payload: not called CC=1 SCAR=6.9
53 0 die('NOT IMPLEMENTED');
54 }
55  
56 sub _read_uint32 {
57 0 ▶ my ( $self, $fh ) = @_;
Subroutine _read_uint32: not called CC=1 SCAR=6.9
58 0 my $buf;
59 0 $fh->read( $buf, 4 );
60 0 my $int = unpack 'N', $buf;
61 0 return $int;
62 }
63  
64 sub _read_data {
65 0 ▶ my ( $self, $fh ) = @_;
Subroutine _read_data: not called CC=1 SCAR=6.9
66 0 my $len = $self->_read_uint32( $fh );
67 0 my $data;
68 0 $fh->read( $data, $len );
69 0 return $data;
70 }
71  
72 sub as_string {
73 0 ▶ my $self = shift;
Subroutine as_string: not called CC=1 SCAR=6.9
Pod undocumented
74 0 return pack('CC', ord($self->version), ord($self->type)).$self->payload;
75 }
76  
77 1 1;
78  
79 __END__
80  
81 =pod
82  
83 =encoding UTF-8
84  
85 =head1 NAME
86  
87 Net::Lumberjack::Frame - class for parsing Lumberjack protocol frames
88  
89 =head1 VERSION
90  
91 version 1.01
92  
93 =head1 AUTHOR
94  
95 Markus Benning <ich@markusbenning.de>
96  
97 =head1 COPYRIGHT AND LICENSE
98  
99 This software is Copyright (c) 2016 by Markus Benning.
100  
101 This is free software, licensed under:
102  
103 The Apache License, Version 2.0, January 2004
104  
105 =cut
« Lumberjack/Frame/Data.pm ↑ Summary Lumberjack/Frame/Ack.pm »