| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 39 | 0 | return; # no more data? | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if( $txnr !~ /^\d+ $/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $command and $command =~ /^[a-zA-Z]+ $/
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]+ $/
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 55 | 0 | die('error reading data_len'); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if( $digit !~ /\d/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | die('data_len in RELP is not numeric!'); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if( $digit eq '0' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | $data = ''; | |||||||||||||||||||||||||||
| 62 | } else { | ||||||||||||||||||||||||||||
| 63 | 0 | my $left_data_len = $fh->getline; | |||||||||||||||||||||||||||
| 64 | 0 | ▶ | if( ! defined $left_data_len ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
not $data_len or $data_len > 131072
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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
not defined $trailer or $trailer ne "\n"
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"
| |||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||