Saftpresse/Input/RELP/Frame.pm

filter: Statementstmt 17.3% 8 / 46 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 25.0% 1 / 4 Podpod 0.0% 0 / 3 totaltotal 10.2% 9 / 88 SCAR 50.4
CC
14
Cov
11%
new_from_fh
182.0
as_string
6.0
new_next_frame
2.0
CRAP 153.7
« Saftpresse/Plugin/Postfix/Tls.pm ↑ Summary Saftpresse/Plugin/Syslog.pm »
1 package Log::Saftpresse::Input::RELP::Frame;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '1.5'; # VERSION
6 # ABSTRACT: class for parsing and generating RELP frames
7  
8 1 has 'txnr' => ( is => 'rw', isa => 'Int', required => 1 );
9 1 has 'command' => ( is => 'rw', isa => 'Str', required => 1 );
10 1 has 'data' => ( is => 'rw', isa => 'Str', default => '',
11 traits => [ 'String' ],
12 handles => {
13 data_len => 'length',
14 },
15 );
16  
17 sub as_string {
18 0 ▶ my $self = shift;
Subroutine as_string: not called CC=2 SCAR=17.9
Pod undocumented
19 0 ▶ return join(' ', $self->txnr, $self->command, $self->data_len,
Branch: 1 branch
BranchTrueFalseTotal
$self->data_len ? : 0 0 0
20 $self->data_len ? $self->data : () )."\n";
21 }
22  
23 sub new_next_frame {
24 0 ▶ my ( $class, $prev ) = ( shift, shift );
Subroutine new_next_frame: not called CC=1 SCAR=6.9
Pod undocumented
25 0 my $obj = $class->new(
26 'txnr' => $prev->txnr,
27 @_
28 );
29 0 return $obj;
30 }
31  
32 sub new_from_fh {
33 0 ▶ my ( $class, $fh ) = ( shift, shift );
Subroutine new_from_fh: not called CC=13 SCAR=52.0
Pod undocumented
34  
35 0 local $/ = ' ';
36  
37 0 my $txnr = $fh->getline;
38 0 ▶ if( ! defined $txnr ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $txnr) 0 0 0
39 0 return; # no more data?
40 }
41 0 ▶ if( $txnr !~ /^\d+ $/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($txnr =~ /^\d+ $/) 0 0 0
42 0 die('invalid txnr in RELP frame: '.$txnr);
43 }
44 0 chomp( $txnr );
45  
46 0 my $command = $fh->getline;
47 0 ▶ if( ! defined $command || $command !~ /^[a-zA-Z]+ $/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $command and $command =~ /^[a-zA-Z]+ $/) 0 0 0
Condition0%0/3
defined $command and $command =~ /^[a-zA-Z]+ $/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $command and $command =~ /^[a-zA-Z]+ $/
defined $command $command =~ /^[a-zA-Z]+ $/
Truth table0%0/3
A and B
A= defined $commandB= $command =~ /^[a-zA-Z]+ $/
ABresult
0X0
100
111
48 0 die('invalid command in RELP frame: '.$command);
49 }
50 0 chomp( $command );
51  
52 0 my $digit;
53 my $data;
54 0 ▶ if( ! $fh->read( $digit, 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fh->read($digit, 1)) 0 0 0
55 0 die('error reading data_len');
56 }
57 0 ▶ if( $digit !~ /\d/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($digit =~ /\d/) 0 0 0
58 0 die('data_len in RELP is not numeric!');
59 }
60 0 ▶ if( $digit eq '0' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($digit eq '0') { } 0 0 0
61 0 $data = '';
62 } else {
63 0 my $left_data_len = $fh->getline;
64 0 ▶ if( ! defined $left_data_len ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $left_data_len) 0 0 0
65 0 die('error reading more digits of data_len');
66 }
67 0 chomp( $left_data_len );
68 0 my $data_len = int( $digit . $left_data_len );
69 0 ▶ if( ! $data_len || $data_len > 131072 ) { # 128k
Branch: 1 branch
BranchTrueFalseTotal
if (not $data_len or $data_len > 131072) 0 0 0
Condition0%0/3
not $data_len or $data_len > 131072
l!l&&r!l&&!r
000
MC/DC0%0/2
not $data_len or $data_len > 131072
not $data_len $data_len > 131072
Truth table0%0/3
not(A) or B
A= not $data_lenB= $data_len > 131072
ABresult
1X1
011
000
70 0 die('invalid data_len in RELP frame');
71 }
72 0 $fh->read( $data, $data_len );
73 }
74 0 my $trailer;
75 0 $fh->read( $trailer, 1 );
76 0 ▶ if( ! defined $trailer || $trailer ne "\n" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $trailer or $trailer ne "\n") 0 0 0
Condition0%0/3
not defined $trailer or $trailer ne "\n"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $trailer or $trailer ne "\n"
not defined $trailer $trailer ne "\n"
Truth table0%0/3
not(A) or B
A= not defined $trailerB= $trailer ne "\n"
ABresult
1X1
011
000
77 0 die('no trailer (LF) present. possible framing error.');
78 }
79  
80 0 my $obj = $class->new(
81 'txnr' => $txnr,
82 'command' => $command,
83 'data' => $data,
84 @_
85 );
86 0 return $obj;
87 }
88  
89 1 1;
90  
91 __END__
92  
93 =pod
94  
95 =encoding UTF-8
96  
97 =head1 NAME
98  
99 Log::Saftpresse::Input::RELP::Frame - class for parsing and generating RELP frames
100  
101 =head1 VERSION
102  
103 version 1.5
104  
105 =head1 AUTHOR
106  
107 Markus Benning <ich@markusbenning.de>
108  
109 =head1 COPYRIGHT AND LICENSE
110  
111 This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning.
112  
113 This is free software, licensed under:
114  
115 The GNU General Public License, Version 2, June 1991
116  
117 =cut
« Saftpresse/Plugin/Postfix/Tls.pm ↑ Summary Saftpresse/Plugin/Syslog.pm »