| 1 | package Object::Remote::ReadChannel; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 24 | ▶ | use Scalar::Util qw(weaken openhandle); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 24 | ▶ | use Object::Remote::Logging qw(:log :dlog router ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 12 | ▶ | BEGIN { router()->exclude_forwarding } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | has fh => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | is => 'ro', required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 20 | ▶ | trigger => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 20 | my ($self, $fh) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 20 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 20 | ▶ | log_trace { "Watching filehandle via trigger on 'fh' attribute in Object::Remote::ReadChannel" }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | Object::Remote->current_loop | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | ->watch_io( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | handle => $fh, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 188 | ▶ | on_read_ready => sub { $self->_receive_data_from($fh) } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 20 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | has on_close_call => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 17 | ▶ | is => 'rw', default => sub { sub {} }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | has on_line_call => (is => 'rw'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 20 | ▶ | has _receive_data_buffer => (is => 'ro', default => sub { my $x = ''; \$x }); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 188 | ▶ | sub _receive_data_from { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_receive_data_from: called CC=6 SCAR=25.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | ▶ | my ($self, $fh) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_receive_data_from: called CC=6 SCAR=25.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | Dlog_trace { "Preparing to read data from $_" } $fh; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my $rb = $self->_receive_data_buffer; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my $len = sysread($fh, $$rb, 32768, length($$rb)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | my $err = defined($len) ? 'eof' : ": $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if (defined($len) and $len > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
defined $len and $len > 0
defined $len and $len > 0
MC/DC0%0/2
defined $len and $len > 0
defined $len
$len > 0
MC/DC50%1/2
defined $len and $len > 0
defined $len
$len > 0
Truth table0%0/3
A and B
A= defined $lenB= $len > 0
Truth table66%2/3
A and B
A= defined $lenB= $len > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | log_trace { "Read $len bytes of data" }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | while (my $cb = $self->on_line_call and $$rb =~ s/^(.*)\n//) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
my $cb = $self->on_line_call and $$rb =~ s/^(.*)\n//
my $cb = $self->on_line_call and $$rb =~ s/^(.*)\n//
MC/DC0%0/2
my $cb = $self->on_line_call and $$rb =~ s/^(.*)\n//
my $cb = $self->on_line_call
$$rb =~ s/^(.*)\n//
MC/DC50%1/2
my $cb = $self->on_line_call and $$rb =~ s/^(.*)\n//
my $cb = $self->on_line_call
$$rb =~ s/^(.*)\n//
Truth table0%0/3
A and B
A= my $cb = $self->on_line_callB= $$rb =~ s/^(.*)\n//
Truth table66%2/3
A and B
A= my $cb = $self->on_line_callB= $$rb =~ s/^(.*)\n//
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $cb->(my $line = $1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | log_trace { "Got EOF or error, this read channel is done" }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | Object::Remote->current_loop | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ->unwatch_io( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | handle => $self->fh, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | on_read_ready => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | log_trace { "Invoking on_close_call() for dead read channel" }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $self->on_close_call->($err); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | sub DEMOLISH { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | ▶ | my ($self, $gd) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DEMOLISH: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | return if $gd; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | log_trace { "read channel is being demolished" }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | Object::Remote->current_loop | |||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | ->unwatch_io( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | handle => $self->fh, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | on_read_ready => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||