Client/AnyEvent/Connection.pm

filter: Statementstmt 38.7% 19 / 49 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 42.8% 6 / 14 Podpod 0.0% 0 / 3 totaltotal 30.8% 25 / 81 CC 7 SCAR 17.0
CC
7
Cov
31%
__ANON__
12.0
close
12.0
__ANON__
6.0
CRAP 5.5
« Plugin/InProcess.pm ↑ Summary InProcess.pm »
1 package Devel::REPL::Client::AnyEvent::Connection;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use AnyEvent::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Term::ReadKey;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 EOT => "\x04",
12 1 };
13  
14 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
15 0 my ($class, %args) = @_;
16 0 my $self = bless {
17 handle => undef,
18 input => undef,
19 on_close => undef,
20 }, $class;
21 0 my $weak_self = $self;
22 0 weaken($weak_self);
23 my $handle = AnyEvent::Handle->new(
24 fh => $args{socket},
25 0 ▶ on_error => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
26 0 my ($handle, $fatal, $message) = @_;
27  
28 0 $weak_self->{handle} = $weak_self->{watch} = undef;
29 0 $handle->destroy;
30 $weak_self->{on_close}->($weak_self)
31 0 ▶ if $weak_self->{on_close};
Branch: 1 branch
BranchTrueFalseTotal
if $weak_self->{"on_close"} 0 0 0
32 },
33 0 ▶ on_read => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
34 0 my ($handle) = @_;
35  
36 0 syswrite *STDOUT, $handle->{rbuf};
37 0 substr $handle->{rbuf}, 0, length($handle->{rbuf}), '';
38 },
39 0 ▶ on_eof => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
40 0 my ($handle) = @_;
41  
42 0 $weak_self->{handle} = $weak_self->{watch} = undef;
43 0 $handle->destroy;
44 $weak_self->{on_close}->($weak_self)
45 0 ▶ if $weak_self->{on_close};
Branch: 1 branch
BranchTrueFalseTotal
if $weak_self->{"on_close"} 0 0 0
46 },
47 0 );
48 my $watch = AnyEvent->io(
49 fh => \*STDIN,
50 poll => 'r',
51 0 ▶ cb => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
52 0 ▶ while (defined(my $key = ReadKey -1, \*STDIN)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $key = ReadKey(-1, \*STDIN))) 0 0 0
53 0 $handle->push_write($key);
54 0 ▶ if ($key eq EOT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "\4") 0 0 0
55 0 print STDOUT "^D\n";
56 0 $handle->push_shutdown;
57 }
58 }
59 },
60 0 );
61  
62 0 $self->{handle} = $handle;
63 0 $self->{watch} = $watch;
64  
65 0 return $self;
66 }
67  
68 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
69 0 my ($self) = @_;
70  
71 0 $self->close;
72 }
73  
74 0 ▶sub on_close { $_[0]->{on_close} = $_[1] }
Subroutine on_close: not called CC=1 SCAR=6.9
Pod undocumented
75  
76 0 ▶sub close {
Subroutine close: not called CC=3 SCAR=24.8
Pod undocumented
77 0 my ($self) = @_;
78  
79 0 ▶ $self->{handle}->destroy if $self->{handle} && !$self->{handle}->destroyed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"handle"} and not $self->{"handle"}->destroyed 0 0 0
Condition0%0/3
$self->{"handle"} and not $self->{"handle"}->destroyed
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"handle"} and not $self->{"handle"}->destroyed
$self->{"handle"} not $self->{"handle"}->destroyed
Truth table0%0/3
A and not(B)
A= $self->{"handle"}B= not $self->{"handle"}->destroyed
ABresult
0X0
100
111
80 }
81  
82 1 1;
« Plugin/InProcess.pm ↑ Summary InProcess.pm »