Remote/Server.pm

filter: Statementstmt 30.1% 22 / 73 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 41.1% 7 / 17 Podpod 0.0% 0 / 8 totaltotal 24.7% 29 / 117 CC 11 SCAR 20.2
CC
11
Cov
24%
data
20.0
new_analyzer
12.0
close
12.0
CRAP 7.5
« Remote.pm ↑ Summary Remote/Client.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Net::IMP::Remote::Server;
5 1 ▶use Net::IMP;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Net::IMP::Remote::Protocol;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Net::IMP::Debug;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub new {
12 0 ▶ my ($class,$conn,$factory,%args) = @_;
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
13 0 my $self = bless {
14 conn => $conn,
15 factory => $factory,
16 }, $class;
17  
18 0 weaken( my $wself = $self );
19 0 $conn->nextop({
20 IMPRPC_EXCEPTION+0 => [ \&exception, $wself ],
21 IMPRPC_GET_INTERFACE+0 => [ \&get_interface, $wself ],
22 IMPRPC_SET_INTERFACE+0 => [ \&set_interface, $wself ],
23 IMPRPC_NEW_ANALYZER+0 => [ \&new_analyzer, $wself ],
24 IMPRPC_DEL_ANALYZER+0 => [ \&del_analyzer, $wself ],
25 IMPRPC_DATA+0 => [ \&data, $wself ],
26 }, -1);
27 0 return $self;
28 }
29  
30 sub get_interface {
31 0 ▶ my ($self,@if) = @_;
Subroutine get_interface: not called CC=1 SCAR=6.9
Pod undocumented
32 0 @if = $self->{factory}->get_interface(@if);
33 0 $self->{conn}->rpc([ IMPRPC_INTERFACE, @if ]);
34 0 return;
35 }
36  
37 sub set_interface {
38 0 ▶ my ($self,$if) = @_;
Subroutine set_interface: not called CC=2 SCAR=17.9
Pod undocumented
39 0 my $newf = $self->{factory}->set_interface($if);
40 0 ▶ if ( ! $newf ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $newf) { } 0 0 0
41 $self->{conn}->rpc([
42 0 IMPRPC_EXCEPTION,0,
43 "set_interface: unsupported interface"
44 ]);
45 0 return;
46 } else {
47 0 $self->{factory} = $newf;
48 }
49 }
50  
51 sub new_analyzer {
52 0 ▶ my ($self,$id,$ctx) = @_;
Subroutine new_analyzer: not called CC=3 SCAR=24.8
Pod undocumented
53 0 my $conn = $self->{conn};
54 0 ▶ if ( $conn->get_analyzer($id) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conn->get_analyzer($id)) 0 0 0
55 0 $conn->rpc([IMPRPC_EXCEPTION,$id,"analyzer exists already"]);
56 0 return;
57 }
58  
59 0 my $obj = $self->{factory}->new_analyzer(%$ctx);
60 0 ▶ if ( ! $obj ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $obj) { } 0 0 0
61 0 debug("analyzer $id not wanted - using dummy");
62 0 $conn->add_analyzer('dummy',$id);
63 0 $conn->rpc([IMPRPC_RESULT,$id,IMP_PASS,0,IMP_MAXOFFSET]);
64 0 $conn->rpc([IMPRPC_RESULT,$id,IMP_PASS,1,IMP_MAXOFFSET]);
65 0 return;
66 } else {
67 0 debug("created analyzer $id - $obj");
68 0 $conn->add_analyzer($obj,$id);
69 0 weaken( my $wconn = $conn );
70 $obj->set_callback(sub {
71 0 ▶ $wconn->rpc([IMPRPC_RESULT,$id,@$_]) for (@_);
Subroutine __ANON__: not called CC=2 SCAR=17.9
72 0 });
73 }
74 }
75  
76 sub del_analyzer {
77 0 ▶ my ($self,$id) = @_;
Subroutine del_analyzer: not called CC=1 SCAR=6.9
Pod undocumented
78 0 $self->{conn}->del_analyzer($id);
79 }
80  
81 sub data {
82 0 ▶ my ($self,$id,$dir,$offset,$type,$data) = @_;
Subroutine data: not called CC=4 SCAR=30.0
Pod undocumented
83 0 ▶ my $obj = $self->{conn}->get_analyzer($id) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $obj = $self->{"conn"}->get_analyzer($id) or do { debug("no analyzer $id"); $self->{"conn"}->rpc(["exception", $id, "no analyzer $id"]); return } 0 0 0
84 0 debug("no analyzer $id");
85 0 $self->{conn}->rpc([IMPRPC_EXCEPTION,$id,"no analyzer $id"]);
86 0 return;
87 };
88 0 ▶ debug("got data($dir,%s,$type,datalen=%d)",$offset//"<undef>",length($data));
Condition0%0/2
$offset // "<undef>"
l!l
00
MC/DC0%0/1
$offset // "<undef>"
$offset
Truth table0%0/2
A
A= $offset
Aresult
11
00
89 0 ▶ ref($obj) or return; # dummy
Branch: 1 branch
BranchTrueFalseTotal
ref $obj or return 0 0 0
90 0 $obj->data($dir,$data,$offset,$type);
91 }
92  
93 sub exception {
94 0 ▶ my ($self,$id,$msg) = @_;
Subroutine exception: not called CC=2 SCAR=17.9
Pod undocumented
95 0 ▶ if ( $id ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id) { } 0 0 0
96 0 warn "[$id] $msg\n";
97 } else {
98 0 warn "[*] $msg\n";
99 }
100 }
101  
102 sub close {
103 0 ▶ my $self = shift;
Subroutine close: not called CC=3 SCAR=24.8
Pod undocumented
104 0 ▶ my $id = $self->{id} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $id = $self->{"id"} or return 0 0 0
105 0 ▶ my $conn = $self->{conn} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $conn = $self->{"conn"} or return 0 0 0
106 0 $conn->del_analyzer($id);
107 }
108  
109 0 ▶sub DESTROY { goto &close }
Subroutine DESTROY: not called CC=1 SCAR=6.9
110  
111 1 1;
112 __END__
« Remote.pm ↑ Summary Remote/Client.pm »