Lambda/Socket.pm

filter: Statementstmt 70.7% 63 / 89 Branchbran 29.1% 14 / 48 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 82.3% 14 / 17 Podpod n/a totaltotal 58.1% 93 / 160 CC 27 SCAR 23.3
CC
27
Cov
56%
__ANON__
30.0
connect
20.0
__ANON__
20.0
CRAP 10.3
« Lambda/HTTP/Authen/NTLM.pm ↑ Summary Lambda/DNS.pm »
1 # $Id: Socket.pm,v 1.12 2010/03/26 20:45:45 dk Exp $
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4
5 package IO::Lambda::Socket;
6 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use IO::Lambda qw(:all :dev);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Time::HiRes qw(time);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 @ISA = qw(Exporter);
13 3 %EXPORT_TAGS = (all => \@EXPORT_OK);
14 3 @EXPORT_OK = qw(connect accept send recv);
15 3 ▶use subs qw(connect accept send recv);
Subroutine BEGIN: called CC=1 SCAR=0.0
16
17 sub connect(&)
18 {
19 return this-> override_handler('connect', \&connect, shift)
20 0 ▶ if this-> {override}->{connect};
Subroutine connect: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
if this()->{"override"}{"connect"} 0 0 0
21
22 0 my $cb = _subname connect => shift;
23 0 my ($socket, $deadline) = context;
24
25 0 ▶ return this-> add_constant( $cb, \&connect, "Bad socket") unless $socket;
Branch: 1 branch
BranchTrueFalseTotal
unless $socket 0 0 0
26
27 0 my $w32 = $^O eq 'MSWin32';
28
29 this-> watch_io(
30 IO_WRITE | ( $w32 ? IO_EXCEPTION : 0),
31 $socket, $deadline,
32 sub {
33 0 ▶ shift-> set_frame( \&connect, $cb, $socket, $deadline);
Subroutine __ANON__: not called CC=5 SCAR=34.0
34
35 0 my @param;
36 0 ▶ unless ( $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]) { } 0 0 0
37 0 @param = ('timeout');
38 } else {
39 0 ▶ my $e = $w32 ? \ $^E : \ $!;
Branch: 1 branch
BranchTrueFalseTotal
$w32 ? : 0 0 0
40 0 $$e = unpack('i', getsockopt( $socket, SOL_SOCKET, SO_ERROR));
41 0 ▶ @param = ($$e) if $$e;
Branch: 1 branch
BranchTrueFalseTotal
if $$e 0 0 0
42 }
43 0 local *__ANON__ = "IO::Lambda::Socket::connect::callback";
44 0 ▶ $cb ? $cb-> (@param) : @param;
Branch: 1 branch
BranchTrueFalseTotal
$cb ? : 0 0 0
45 }
46 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$w32 ? : 0 0 0
47 }
48
49 sub accept(&)
50 {
51 return this-> override_handler('accept', \&accept, shift)
52 1 ▶ if this-> {override}->{accept};
Subroutine accept: called CC=3 SCAR=18.0
Branch: 1 branch
BranchTrueFalseTotal
if this()->{"override"}{"accept"} 0 1 1
53
54 1 my $cb = _subname accept => shift;
55 1 my ($socket, $deadline) = context;
56
57 1 ▶ return this-> add_constant( $cb, \&connect, "Bad socket") unless $socket;
Branch: 1 branch
BranchTrueFalseTotal
unless $socket 0 1 1
58
59 this-> watch_io(
60 IO_READ, $socket, $deadline,
61 sub {
62 0 ▶ shift-> set_frame( \&accept, $cb, $socket, $deadline);
Subroutine __ANON__: not called CC=4 SCAR=30.0
63
64 0 my @param;
65 0 ▶ unless ( $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]) { } 0 0 0
66 0 @param = ('timeout');
67 } else {
68 0 my $h = IO::Handle-> new;
69 0 ▶ @param = (
Branch: 1 branch
BranchTrueFalseTotal
CORE::accept($h, $socket) ? : 0 0 0
70 CORE::accept( $h, $socket) ?
71 ($h) : ($!)
72 );
73 }
74 0 local *__ANON__ = "IO::Lambda::Socket::accept::callback";
75 0 ▶ $cb ? $cb-> (@param) : @param;
Branch: 1 branch
BranchTrueFalseTotal
$cb ? : 0 0 0
76 }
77 1 );
78 }
79
80 # recv($fh, $length, $flags, $deadline) -> (address,msg|undef,error)
81 sub recv(&)
82 {
83 return this-> override_handler('recv', \&recv, shift)
84 5 ▶ if this-> {override}->{recv};
Subroutine recv: called CC=3 SCAR=11.8
Branch: 1 branch
BranchTrueFalseTotal
if this()->{"override"}{"recv"} 0 5 5
85
86 5 my $cb = _subname( recv => shift );
87 5 my ($socket, $length, $flags, $deadline) = context;
88
89 5 ▶ return this-> add_constant( $cb, \&recv, undef, "Bad socket")
Branch: 1 branch
BranchTrueFalseTotal
unless $socket 0 5 5
90 unless $socket;
91
92 this-> watch_io(
93 IO_READ, $socket, $deadline,
94 sub {
95 5 ▶ shift-> set_frame( \&recv, $cb, $socket, $length, $flags, $deadline);
Subroutine __ANON__: called CC=6 SCAR=19.9
96
97 5 my @param;
98 5 ▶ unless ( $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]) { } 5 0 5
99 0 @param = ('timeout');
100 } else {
101 5 my $buf = '';
102 5 ▶ my $r = CORE::recv(
Condition50%1/2
$flags || 0
l!l
05
MC/DC0%0/1
$flags || 0
$flags
Truth table50%1/2
A
A= $flags
Aresult
11
00
103 $socket, $buf, $length,
104 $flags || 0
105 );
106 5 ▶ if ( defined($r)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $r) { } 5 0 5
107 5 ▶ @param = defined($r) ? ($r,$buf) : (undef,$!);
Branch: 1 branch
BranchTrueFalseTotal
defined $r ? : 5 0 5
108 } else {
109 0 @param = ( undef, $!);
110 }
111 }
112 5 local *__ANON__ = "IO::Lambda::Socket::recv::callback";
113 5 ▶ $cb ? $cb-> (@param) : @param;
Branch: 1 branch
BranchTrueFalseTotal
$cb ? : 5 0 5
114 }
115 5 );
116 }
117
118 # send($fh, $msg, $flags, $to, $deadline) -> ioresult
119 sub send(&)
120 {
121 return this-> override_handler('send', \&send, shift)
122 5 ▶ if this-> {override}->{send};
Subroutine send: called CC=3 SCAR=11.7
Branch: 1 branch
BranchTrueFalseTotal
if this()->{"override"}{"send"} 0 5 5
123
124 5 my $cb = _subname send => shift;
125 5 my ($socket, $msg, $flags, $to, $deadline) = context;
126
127 5 ▶ return this-> add_constant( $cb, \&send, undef, "Bad socket")
Branch: 1 branch
BranchTrueFalseTotal
unless $socket 0 5 5
128 unless $socket;
129
130 this-> watch_io(
131 IO_WRITE, $socket, $deadline,
132 sub {
133 5 ▶ shift-> set_frame( \&recv, $cb, $socket, $msg, $flags, $to, $deadline);
Subroutine __ANON__: called CC=6 SCAR=19.6
134
135 5 my @param;
136 5 ▶ unless ( $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]) { } 5 0 5
137 0 @param = ('timeout');
138 } else {
139 5 ▶ $flags ||= 0;
Condition50%1/2
$flags ||= 0
l!l
05
MC/DC0%0/1
$flags ||= 0
$flags
Truth table50%1/2
A
A= $flags
Aresult
11
00
140 5 ▶ my $r = defined($to) ?
Branch: 1 branch
BranchTrueFalseTotal
defined $to ? : 0 5 5
141 CORE::send($socket, $msg, $flags, $to) :
142 CORE::send($socket, $msg, $flags);
143 5 ▶ @param = defined($r) ? ($r) : (undef,$!);
Branch: 1 branch
BranchTrueFalseTotal
defined $r ? : 5 0 5
144 }
145 5 local *__ANON__ = "IO::Lambda::Socket::send::callback";
146 5 ▶ $cb ? $cb-> (@param) : @param;
Branch: 1 branch
BranchTrueFalseTotal
$cb ? : 5 0 5
147 }
148 5 );
149 }
150
151 3 1;
152
153 __DATA__
« Lambda/HTTP/Authen/NTLM.pm ↑ Summary Lambda/DNS.pm »