| 1 | package DBGp::Client::AsyncStream; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 7 | 0 | my ($class, %args) = @_; | |||||||||
| 8 | my $self = bless { | ||||||||||
| 9 | socket => $args{socket}, | ||||||||||
| 10 | 0 | buffer => '', | |||||||||
| 11 | on_line => undef, | ||||||||||
| 12 | }, $class; | ||||||||||
| 13 | |||||||||||
| 14 | 0 | return $self; | |||||||||
| 15 | } | ||||||||||
| 16 | |||||||||||
| 17 | 0 | ▶ | sub on_line { $_[0]->{on_line} = $_[1] } | ||||||||
|
Subroutine
on_line: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 18 | |||||||||||
| 19 | 0 | ▶ | sub add_data { | ||||||||
|
Subroutine
add_data: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 20 | 0 | my ($self, $bytes) = @_; | |||||||||
| 21 | |||||||||||
| 22 | 0 | $self->{buffer} .= $bytes; | |||||||||
| 23 | |||||||||||
| 24 | 0 | ▶ | while (defined(my $line = $self->_try_line)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 0 | $self->{on_line}->($line); | |||||||||
| 26 | } | ||||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 0 | ▶ | sub put_line { | ||||||||
|
Subroutine
put_line: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 30 | 0 | my ($self, @items) = @_; | |||||||||
| 31 | 0 | my $cmd = join(" ", @items); | |||||||||
| 32 | |||||||||||
| 33 | 0 | syswrite $self->{socket}, $cmd . "\x00"; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 0 | ▶ | sub _try_line { | ||||||||
|
Subroutine
_try_line: not called CC=4 SCAR=30.0
| |||||||||||
| 37 | 0 | my ($self) = @_; | |||||||||
| 38 | 0 | my $buffer = \$self->{buffer}; | |||||||||
| 39 | |||||||||||
| 40 | 0 | my $len_end = index($$buffer, "\x00"); | |||||||||
| 41 | 0 | ▶ | return if $len_end == -1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | |||||||||||
| 43 | 0 | my $len = 0 + substr $$buffer, 0, $len_end; | |||||||||
| 44 | 0 | ▶ | return if length($$buffer) < $len_end + $len + 2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | |||||||||||
| 46 | 0 | ▶ | die "Packat is not null-terminated" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | unless substr($$buffer, $len_end + $len + 1, 1) eq "\x00"; | ||||||||||
| 48 | |||||||||||
| 49 | 0 | my $line = substr $$buffer, $len_end + 1, $len; | |||||||||
| 50 | 0 | substr $$buffer, 0, $len_end + $len + 2, ''; | |||||||||
| 51 | |||||||||||
| 52 | 0 | return $line; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 2 | 1; | |||||||||