blib/lib/Net/Forward.pm

filter: Statementstmt 30.1% 19 / 63 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 28 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 55.5% 5 / 9 Podpod 50.0% 1 / 2 totaltotal 16.8% 25 / 148 CC 26 SCAR 56.7
CC
26
Cov
16%
_pipe
462.0
_listen
30.0
activate
6.0
CRAP 290.3
↑ Summary
1 package Net::Forward;
2 1 ▶use 5.014002;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 1 require Exporter;
6 1 ▶use IO::Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use AutoLoader qw(AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 our @ISA = qw(Exporter IO::Socket);
9 1 our @EXPORT = qw();
10 1 our $VERSION = '0.1';
11 0 ▶sub new{
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
12 0 my ($class,$self) = @_;
13 0 return bless $self, $class;
14 }
15 0 ▶sub activate{
Subroutine activate: not called CC=2 SCAR=17.9
Pod undocumented
16 0 my $self = shift;
17 0 ▶ $self->{Proto} = 'tcp' unless defined $self->{Proto};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"Proto"} 0 0 0
18 0 _listen($self->{LocalHost},$self->{LocalPort},$self->{RemoteHost},$self->{RemotePort},$self->{Proto});
19 }
20 0 ▶sub _listen{
Subroutine _listen: not called CC=5 SCAR=34.0
21 0 my ($local_host,$local_port,$remote_host,$remote_port,$proto) = @_;
22 0 ▶ my $server = new IO::Socket::INET (LocalHost => $local_host,
Condition0%0/2
'IO::Socket::INET'->new('LocalHost', $local_host, 'LocalPort', $local_port, 'Proto', $proto, 'Listen', 1, 'Reuse', 1) || die(qq[Cannot listen on "${local_host}:$local_port"\n])
l!l
00
MC/DC0%0/1
'IO::Socket::INET'->new('LocalHost', $local_host, 'LocalPort', $local_port, 'Proto', $proto, 'Listen', 1, 'Reuse', 1) || die(qq[Cannot listen on "${local_host}:$local_port"\n])
'IO::Socket::INET'->new('LocalHost', $local_host, 'LocalPort', $local_port, 'Proto', $proto, 'Listen', 1, 'Reuse', 1)
Truth table0%0/2
A
A= 'IO::Socket::INET'->new('LocalHost', $local_host, 'LocalPort', $local_port, 'Proto', $proto, 'Listen', 1, 'Reuse', 1)
Aresult
11
00
23 LocalPort => $local_port,
24 Proto => $proto,
25 Listen => 1,
26 Reuse => 1) || die qq,Cannot listen on "$local_host:$local_port"\n,;
27 0 ▶ while (my $client = $server->accept()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $client = $server->accept) 0 0 0
28 0 $client->autoflush(1);
29 0 ▶ if(fork()){
Branch: 1 branch
BranchTrueFalseTotal
if (fork) { } 0 0 0
30 0 $client->close();
31 }else{
32 0 $server->close();
33 0 ▶ _pipe($server,$client,IO::Socket::INET->new(PeerAddr => $remote_host, PeerPort => $remote_port, Proto => $proto, Type => SOCK_STREAM) || die qq,Cannot connect to "$remote_host:$remote_port"\n,);
Condition0%0/2
'IO::Socket::INET'->new('PeerAddr', $remote_host, 'PeerPort', $remote_port, 'Proto', $proto, 'Type', 1) || die(qq[Cannot connect to "${remote_host}:$remote_port"\n])
l!l
00
MC/DC0%0/1
'IO::Socket::INET'->new('PeerAddr', $remote_host, 'PeerPort', $remote_port, 'Proto', $proto, 'Type', 1) || die(qq[Cannot connect to "${remote_host}:$remote_port"\n])
'IO::Socket::INET'->new('PeerAddr', $remote_host, 'PeerPort', $remote_port, 'Proto', $proto, 'Type', 1)
Truth table0%0/2
A
A= 'IO::Socket::INET'->new('PeerAddr', $remote_host, 'PeerPort', $remote_port, 'Proto', $proto, 'Type', 1)
Aresult
11
00
34 0 exit();
35 }
36 }
37 }
38 0 ▶sub _pipe{
Subroutine _pipe: not called CC=21 SCAR=61.4
39 0 my($server,$client,$remote) = @_;
40 0 $remote->autoflush();
41 0 ▶ while($client || $remote) {
Branch: 1 branch
BranchTrueFalseTotal
if ($client or $remote) 0 0 0
Condition0%0/3
$client or $remote
l!l&&r!l&&!r
000
MC/DC0%0/2
$client or $remote
$client $remote
Truth table0%0/3
A or B
A= $clientB= $remote
ABresult
1X1
011
000
42 0 my $rin = "";
43 0 ▶ vec($rin, fileno($client), 1) = 1 if $client;
Branch: 1 branch
BranchTrueFalseTotal
if $client 0 0 0
44 0 ▶ vec($rin, fileno($remote), 1) = 1 if $remote;
Branch: 1 branch
BranchTrueFalseTotal
if $remote 0 0 0
45 0 my($rout, $eout);
46 0 select($rout = $rin, undef, $eout = $rin, 120);
47 0 ▶ if (!$rout && !$eout) { return; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($rout or $eout) 0 0 0
Condition0%0/3
$rout or $eout
l!l&&r!l&&!r
000
MC/DC0%0/2
$rout or $eout
$rout $eout
Truth table0%0/3
A or B
A= $routB= $eout
ABresult
1X1
011
000
48 0 my $cbuffer = "";
49 0 my $tbuffer = "";
50 0 ▶ if ($client && (vec($eout, fileno($client), 1) || vec($rout, fileno($client), 1))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($client and vec($eout, fileno $client, 1) || vec($rout, fileno $client, 1)) 0 0 0
Condition0%0/6
$client and vec($eout, fileno $client, 1) || vec($rout, fileno $client, 1)
!ll&&!rl&&r
000
vec $eout, fileno $client, 1 or vec $rout, fileno $client, 1
l!l&&r!l&&!r
000
MC/DC0%0/3
$client and vec($eout, fileno $client, 1) || vec($rout, fileno $client, 1)
$client vec $eout, fileno $client, 1 vec $rout, fileno $client, 1
Truth table0%0/4
A and B or C
A= $clientB= vec $eout, fileno $client, 1C= vec $rout, fileno $client, 1
ABCresult
0XX0
1000
11X1
1011
51 0 my $result = sysread($client, $tbuffer, 1024);
52 0 ▶ if (!defined($result) || !$result) { return; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $result and $result) 0 0 0
Condition0%0/3
defined $result and $result
!ll&&!rl&&r
000
MC/DC0%0/2
defined $result and $result
defined $result $result
Truth table0%0/3
A and B
A= defined $resultB= $result
ABresult
0X0
100
111
53 }
54 0 ▶ if ($remote && (vec($eout, fileno($remote), 1) || vec($rout, fileno($remote), 1))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remote and vec($eout, fileno $remote, 1) || vec($rout, fileno $remote, 1)) 0 0 0
Condition0%0/6
$remote and vec($eout, fileno $remote, 1) || vec($rout, fileno $remote, 1)
!ll&&!rl&&r
000
vec $eout, fileno $remote, 1 or vec $rout, fileno $remote, 1
l!l&&r!l&&!r
000
MC/DC0%0/3
$remote and vec($eout, fileno $remote, 1) || vec($rout, fileno $remote, 1)
$remote vec $eout, fileno $remote, 1 vec $rout, fileno $remote, 1
Truth table0%0/4
A and B or C
A= $remoteB= vec $eout, fileno $remote, 1C= vec $rout, fileno $remote, 1
ABCresult
0XX0
1000
11X1
1011
55 0 my $result = sysread($remote, $cbuffer, 1024);
56 0 ▶ if (!defined($result) || !$result) { return; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $result and $result) 0 0 0
Condition0%0/3
defined $result and $result
!ll&&!rl&&r
000
MC/DC0%0/2
defined $result and $result
defined $result $result
Truth table0%0/3
A and B
A= defined $resultB= $result
ABresult
0X0
100
111
57 }
58  
59 0 ▶ while (my $len = length($tbuffer)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $len = length $tbuffer) 0 0 0
60 0 my $res = syswrite($remote, $tbuffer, $len);
61 0 ▶ if ($res > 0) { $tbuffer = substr($tbuffer, $res); } else { return; }
Branch: 1 branch
BranchTrueFalseTotal
if ($res > 0) { } 0 0 0
62 }
63 0 ▶ while (my $len = length($cbuffer)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $len = length $cbuffer) 0 0 0
64 0 my $res = syswrite($client, $cbuffer, $len);
65 0 ▶ if ($res > 0) { $cbuffer = substr($cbuffer, $res); } else { return; }
Branch: 1 branch
BranchTrueFalseTotal
if ($res > 0) { } 0 0 0
66 }
67 }
68 }
69 1 1;
70 __END__
↑ Summary