Packets.pm

filter: Statementstmt 62.4% 78 / 125 Branchbran 45.0% 18 / 40 Conditioncond 41.6% 5 / 12 MC/DCmcdc 37.5% 3 / 8 Subroutinesub 83.3% 10 / 12 Podpod n/a totaltotal 57.8% 114 / 197 CC 26 SCAR 27.6
CC
26
Cov
57%
__ANON__
26.1
input_event
26.1
__ANON__
6.2
CRAP 15.7
« SRSMessage.pm ↑ Summary Command/PayloadClass.pm »
1  
2 package SRS::EPP::Packets;
3  
4 # encapsulate the packetization part of RFC3734
5 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use MooseX::Method::Signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 with 'MooseX::Log::Log4perl::Easy';
9  
10 1 has input_state =>
11 is => "rw",
12 default => "expect_length",
13 ;
14  
15 has input_buffer =>
16 is => "ro",
17 2 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
18 1 ;
19  
20 2 ▶use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 2 ▶method input_buffer_size() {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=2 SCAR=6.9
23 140 my $size = 0;
24 140 for ( @{ $self->input_buffer } ) {
25 249 $size += length $_;
26 }
27 140 $size;
28 1 }
29  
30 2 ▶method input_buffer_read( Int $size where { $_ > 0 } ) {
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine __ANON__: not called CC=4 SCAR=18.2
Subroutine input_buffer_read: called CC=4 SCAR=18.2
31 0 my $buffer = $self->input_buffer;
32 0 my @rv;
33 0 ▶ while ( $size and @$buffer ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($size and @$buffer) 0 0 0
if ($size and @$buffer) 89 9 98
Condition33%2/6
$size and @$buffer
!ll&&!rl&&r
000
$size and @$buffer
!ll&&!rl&&r
9089
MC/DC0%0/2
$size and @$buffer
$size @$buffer
MC/DC50%1/2
$size and @$buffer
$size @$buffer
Truth table0%0/3
A and B
A= $sizeB= @$buffer
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= $sizeB= @$buffer
ABresult
0X0
100
111
34 0 my $chunk = shift @$buffer;
35 0 ▶ if ( length $chunk > $size ) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $chunk > $size) { } 0 0 0
if (length $chunk > $size) { } 50 39 89
36 0 push @rv, substr $chunk, 0, $size;
37 0 unshift @$buffer, substr $chunk, $size;
38 0 last;
39 }
40 else {
41 0 push @rv, $chunk;
42 0 $size -= length $chunk;
43 }
44 }
45 0 join "", @rv;
46 1 }
47  
48 1 has 'input_expect' =>
49 is => "rw",
50 isa => "Int",
51 default => 4,
52 ;
53  
54 1 has 'session' =>
55 handles => [qw(input_packet read_input input_ready yield empty_read)],
56 ;
57  
58 2 ▶method input_event( Str $data? ) {
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine __ANON__: not called CC=10 SCAR=32.6
Subroutine input_event: called CC=10 SCAR=32.6
59 0 ▶ $self->log_trace(
Branch: 2 branches
BranchTrueFalseTotal
defined $data ? : 0 0 0
defined $data ? : 18 22 40
60 "input event: "
61 .(defined($data)?length($data)." byte(s)":"will read")
62 );
63 0 ▶ if ( defined $data and $data ne "") {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $data and $data ne "") 0 0 0
if (defined $data and $data ne "") 17 23 40
Condition50%3/6
defined $data and $data ne ""
!ll&&!rl&&r
000
defined $data and $data ne ""
!ll&&!rl&&r
22117
MC/DC0%0/2
defined $data and $data ne ""
defined $data $data ne ""
MC/DC100%2/2
defined $data and $data ne ""
defined $data $data ne ""
Truth table0%0/3
A and B
A= defined $dataB= $data ne ""
ABresult
0X0
100
111
Truth table100%3/3
A and B
A= defined $dataB= $data ne ""
ABresult
0X0
100
111
64 0 push @{ $self->input_buffer }, $data;
65  
66 }
67  
68 0 my $ready = $self->input_buffer_size;
69 0 my $expected = $self->input_expect;
70  
71 0 ▶ if ( !defined $data ) {
Branch: 2 branches
BranchTrueFalseTotal
unless (defined $data) 0 0 0
unless (defined $data) 22 18 40
72 0 $data = $self->read_input($expected - $ready);
73 0 $self->log_trace(
74 "input_event read ".length($data)." byte(s)"
75 );
76 0 ▶ if ( length($data) == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $data == 0) { } 0 0 0
if (length $data == 0) { } 0 22 22
77 0 $self->empty_read;
78 }
79 else {
80 0 push @{ $self->input_buffer }, $data;
81 }
82 }
83  
84 0 my $got_chunk;
85  
86 0 ▶ while ( $self->input_buffer_size >= $expected ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->input_buffer_size >= $expected) 0 0 0
if ($self->input_buffer_size >= $expected) 60 40 100
87 0 ▶ my $data = $expected
Branch: 2 branches
BranchTrueFalseTotal
$expected ? : 0 0 0
$expected ? : 59 1 60
88 ? $self->input_buffer_read($expected)
89 : "";
90 0 ▶ if ( $self->input_state eq "expect_length" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->input_state eq 'expect_length') { } 0 0 0
if ($self->input_state eq 'expect_length') { } 30 30 60
91 0 $self->input_state("expect_data");
92 0 $self->input_expect(unpack("N", $data)-4);
93 0 $self->log_trace(
94 "expecting ".$self->input_expect." byte(s)"
95 );
96 }
97 else {
98 0 $self->log_trace(
99 "got complete packet, calling input_packet"
100 );
101 0 $self->input_state("expect_length");
102 0 $self->input_packet($data);
103 0 $self->input_expect(4);
104 0 $self->log_trace(
105 "now expecting length packet"
106 );
107 }
108 0 $expected = $self->input_expect;
109 0 $got_chunk = 1;
110 }
111  
112 0 ▶ if ( $self->input_ready ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->input_ready) 0 0 0
if ($self->input_ready) 0 40 40
113 0 $self->log_trace(
114 "done input_event, but more input ready - yielding input_event"
115 );
116 0 $self->yield("input_event");
117 }
118  
119 0 return $got_chunk;
120 1 }
121  
122 1 1;
123  
124 __END__
« SRSMessage.pm ↑ Summary Command/PayloadClass.pm »