Remote.pm

filter: Statementstmt 49.5% 50 / 101 Branchbran 3.3% 1 / 30 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 55.5% 15 / 27 Podpod 100% 5 / 5 totaltotal 39.6% 71 / 179 CC 21 SCAR 29.3
CC
21
Cov
36%
_reconnect
56.0
validate_cfg
30.0
_factory
30.0
CRAP 18.7
« Remote/Connection.pm ↑ Summary Remote/Server.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;
5 1 ▶use base 'Net::IMP::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use fields qw(factory pid interface);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Net::IMP::Remote::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Net::IMP::Remote::Connection;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Net::IMP::Remote::Protocol;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use IO::Socket::UNIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Net::IMP::Debug;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 our $VERSION = '0.009';
17  
18 1 my $INETCLASS = 'IO::Socket::INET';
19 BEGIN {
20 1 ▶ for(qw(IO::Socket::IP IO::Socket::INET6)) {
Subroutine BEGIN: called CC=3 SCAR=11.1
21 1 ▶ eval "require $_" or next;
Branch: 1 branch
BranchTrueFalseTotal
eval "require $_" or next 0 1 1
22 1 $INETCLASS = $_;
23 1 last;
24 }
25 }
26  
27 sub validate_cfg {
28 0 ▶ my ($class,%args) = @_;
Subroutine validate_cfg: not called CC=5 SCAR=34.0
Pod documented
29 0 my @err;
30 0 ▶ push @err,"no address given" if ! delete $args{addr};
Branch: 1 branch
BranchTrueFalseTotal
unless delete $args{"addr"} 0 0 0
31 push @err,"invalid value for 'fail'"
32 0 ▶ if ( delete $args{fail} // 'hard' ) !~m{^(soft|hard)$};
Branch: 1 branch
BranchTrueFalseTotal
unless (delete $args{"fail"} // "hard") =~ /^(soft|hard)$/ 0 0 0
Condition0%0/2
delete $args{"fail"} // "hard"
l!l
00
MC/DC0%0/1
delete $args{"fail"} // "hard"
delete $args{"fail"}
Truth table0%0/2
A
A= delete $args{"fail"}
Aresult
11
00
33 0 ▶ eval { Net::IMP::Remote::Protocol->load_implementation(delete $args{impl})}
Branch: 1 branch
BranchTrueFalseTotal
eval { do { "Net::IMP::Remote::Protocol"->load_implementation(delete $args{"impl"}) } } or push @err, $@ 0 0 0
34 or push @err,$@;
35 0 return (@err,$class->SUPER::validate_cfg(%args));
36 }
37  
38 sub new_factory {
39 0 ▶ my ($class,%args) = @_;
Subroutine new_factory: not called CC=1 SCAR=6.9
Pod documented
40 0 my $self = $class->SUPER::new_factory(%args);
41 0 $self->_factory();
42 0 return $self;
43 }
44  
45 sub set_interface {
46 0 ▶ my ($self,$if) = @_;
Subroutine set_interface: not called CC=1 SCAR=6.9
Pod documented
47 0 $self->{interface} = $if; # store for reconnects
48 0 return $self->_factory->set_interface($if);
49 }
50  
51 sub get_interface {
52 0 ▶ my $self = shift;
Subroutine get_interface: not called CC=1 SCAR=6.9
Pod documented
53 0 return $self->_factory->get_interface(@_);
54 }
55  
56 sub new_analyzer {
57 0 ▶ my ($self,%args) = @_;
Subroutine new_analyzer: not called CC=1 SCAR=6.9
Pod documented
58 0 return $self->_factory->new_analyzer(%args);
59 }
60  
61 sub _factory {
62 0 ▶ my $self = shift;
Subroutine _factory: not called CC=5 SCAR=34.0
63  
64 # close and reconnect after fork
65 0 my $f = $self->{factory};
66 0 ▶ $f = undef if $f and $self->{pid} != $$;
Branch: 1 branch
BranchTrueFalseTotal
if $f and $self->{"pid"} != $$ 0 0 0
Condition0%0/3
$f and $self->{"pid"} != $$
!ll&&!rl&&r
000
MC/DC0%0/2
$f and $self->{"pid"} != $$
$f $self->{"pid"} != $$
Truth table0%0/3
A and B
A= $fB= $self->{"pid"} != $$
ABresult
0X0
100
111
67 0 ▶ if ( ! $f ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($f) 0 0 0
68 0 $f = $self->{factory} = $self->_reconnect();
69 0 $self->{pid} = $$;
70 }
71 # successful connected to IMP server
72 0 ▶ return $f if $f;
Branch: 1 branch
BranchTrueFalseTotal
if $f 0 0 0
73  
74 # return dummy factory object which supports no interface
75 # and where each analyzer just issues IMP_FATAL
76 0 return Net::IMP::Remote::_Fail->new_factory(%{ $self->{factory_args}});
77 }
78  
79 sub _reconnect {
80 0 ▶ my $self = shift;
Subroutine _reconnect: not called CC=7 SCAR=40.3
81 0 ▶ my $addr = $self->{factory_args}{addr} or croak("no addr given");
Branch: 1 branch
BranchTrueFalseTotal
my $addr = $self->{"factory_args"}{"addr"} or croak("no addr given") 0 0 0
82 0 ▶ my $ev = $self->{factory_args}{eventlib} or croak(
Branch: 1 branch
BranchTrueFalseTotal
my $ev = $self->{"factory_args"}{"eventlib"} or croak("data provider does not offer integration into its event loop with eventlib argument") 0 0 0
83 "data provider does not offer integration into its event loop with eventlib argument");
84 0 ▶ my $fd = $addr =~m{/}
Branch: 2 branches
BranchTrueFalseTotal
my $fd = $addr =~ m[/] ? "IO::Socket::UNIX"->new("Peer", $addr, "Type", 1, "Timeout", 10) : $INETCLASS->new("PeerAddr", $addr, "Timeout", 10) or return 0 0 0
$addr =~ m[/] ? : 0 0 0
85 ? IO::Socket::UNIX->new(Peer => $addr, Type => SOCK_STREAM, Timeout => 10)
86 : $INETCLASS->new( PeerAddr => $addr, Timeout => 10)
87 or return;
88 0 $fd->blocking(0);
89 0 debug("connected to $addr");
90 my $conn = Net::IMP::Remote::Connection->new($fd,0,
91 impl => $self->{factory_args}{impl},
92 0 eventlib => $ev,
93 );
94 0 weaken(my $wself=$self);
95 $conn->onClose(sub {
96 0 ▶ my $why = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
97 0 $wself->{factory} = undef; # reconnect on new_analyzer
98 0 });
99 my $factory = Net::IMP::Remote::Client->new_factory(
100 0 ▶ %{ $self->{factory_args}},
Branch: 1 branch
BranchTrueFalseTotal
my $factory = "Net::IMP::Remote::Client"->new_factory(%{$$self{"factory_args"};}, "conn", $conn) or die "cannot create factory" 0 0 0
101 conn => $conn,
102 ) or die "cannot create factory";
103  
104 # set last used interface again
105 $factory = $factory->set_interface($self->{interface})
106 0 ▶ if $self->{interface};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"interface"} 0 0 0
107 0 return $factory;
108 }
109  
110  
111 {
112 package Net::IMP::Remote::_Fail;
113 1 ▶ use base 'Net::IMP::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
114 1 ▶ use Net::IMP qw(:DEFAULT :log);
Subroutine BEGIN: called CC=1 SCAR=0.0
115 0 ▶ sub set_interface { return shift } # no change factory
Subroutine set_interface: not called CC=1 SCAR=6.9
116 0 ▶ sub get_interface { return () } # we don't support anything
Subroutine get_interface: not called CC=1 SCAR=6.9
117 0 ▶ sub data { return }
Subroutine data: not called CC=1 SCAR=6.9
118  
119 sub new_analyzer {
120 0 ▶ my $class = shift;
Subroutine new_analyzer: not called CC=5 SCAR=34.0
121 0 ▶ my $self = $class->SUPER::new_analyzer(@_) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $self = $class->SUPER::new_analyzer(@_) or return 0 0 0
122 0 ▶ my $fail = $self->{factory_args}{fail} || 'hard';
Condition0%0/2
$self->{'factory_args'}{'fail'} || 'hard'
l!l
00
MC/DC0%0/1
$self->{'factory_args'}{'fail'} || 'hard'
$self->{'factory_args'}{'fail'}
Truth table0%0/2
A
A= $self->{'factory_args'}{'fail'}
Aresult
11
00
123 0 ▶ my $err = $self->{factory_args}{connect_error} || $!;
Condition0%0/3
$self->{'factory_args'}{'connect_error'} || $!
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'factory_args'}{'connect_error'} || $!
$self->{'factory_args'}{'connect_error'} $!
Truth table0%0/3
A || B
A= $self->{'factory_args'}{'connect_error'}B= $!
ABresult
1X1
011
000
124 0 ▶ $self->run_callback(
Branch: 1 branch
BranchTrueFalseTotal
$fail eq 'soft' ? : 0 0 0
125 $fail eq 'soft' ? (
126 [ IMP_LOG,0,0,0,IMP_LOG_ERR,
127 "connect to IMP server failed ($err): pass all" ],
128 [ IMP_PASS,0,IMP_MAXOFFSET ],
129 [ IMP_PASS,1,IMP_MAXOFFSET ],
130 ):(
131 [ IMP_FATAL,"connect to IMP server failed ($err)" ]
132 )
133 );
134 0 return $self;
135 }
136 }
137  
138 1 1;
139 __END__
« Remote/Connection.pm ↑ Summary Remote/Server.pm »