Async/URL.pm

filter: Statementstmt 26.1% 33 / 126 Branchbran 0.0% 0 / 106 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 66.6% 10 / 15 Podpod 100% 5 / 5 totaltotal 16.8% 48 / 285 CC 64 SCAR 71.8
CC
64
Cov
13%
url_connect
2162.0
url_listen
210.0
url_absolute
20.0
CRAP 1314.2
↑ Summary Async/Coderef.pm »
1 package RPC::Async::URL;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '1.05';
6  
7 =head1 NAME
8  
9 RPC::Async::URL - Utility functions to handle URLs
10  
11 =head1 SYNOPSIS
12  
13 use RPC::Async::URL;
14  
15 my $socket1 = url_connect("tcp://1.2.3.4:5678");
16 my $socket2 = url_connect("open://dir/file.pl", "--my-option");
17 my ($stdout, $stderr) = url_connect("open2://dir/file.pl", "--my-option");
18 my ($socket3) = url_connect("unix://mysocket.sock");
19 my ($socket4) = url_connect("perl://perlsrvd.pl");
20  
21 =cut
22  
23 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 ▶use Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use English;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use Privileges::Drop;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 1 ▶use base "Exporter";
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 our @EXPORT = qw(url_connect url_disconnect url_listen url_explode
32 url_absolute);
33  
34 1 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 1 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 =head1 METHODS
38  
39 =cut
40  
41 =head2 B<url_connect($url)>
42  
43 Turns an URL into a socket. Currently supported schemes are:
44 * (tcp|udp)://HOST:PORT, Returns a udp of tcp socket.
45 * (unix|unix_dgram)://path/file.sock, Returns a unix domain socket connection.
46 * (perl|perlroot|perl2|perlroot2)(header)?://path/file.pl, Starts a new perl
47 and loads a default header unless it ends in header, then first argument is
48 used as header. It also connects a socket between the two and returns that.
49 Urls with 2 in the end also returns $pid, stdout and stderr. Urls with root
50 in them does not drop root privilages after starting the process the others
51 will.
52 * open2://file, run file and return stdout, stderr and the $pid.
53  
54 =cut
55  
56 0 ▶sub url_connect {
Subroutine url_connect: not called CC=46 SCAR=76.8
Pod documented
57 0 my ($url, @args) = @_;
58  
59 0 ▶ if(ref $url ne '') {
Branch: 7 branches
BranchTrueFalseTotal
if (ref $url ne '') { } 0 0 0
elsif ($url =~ m[^tcp://(\d+\.\d+\.\d+\.\d+):(\d+)$]) { } 0 0 0
elsif ($url =~ m[^unix(?:_(dgram))?://(.+)$]) { } 0 0 0
elsif ($url =~ m[^udp://(\d+\.\d+\.\d+\.\d+)?:?(\d+)?$]) { } 0 0 0
elsif ($url =~ m[^(perl|perlroot|perl2|perlroot2)(header)?://(.+)$]) { } 0 0 0
elsif ($url =~ m[^(open2)://(.+)$]) { } 0 0 0
elsif ($url =~ m[^cfd://(\d+)$]) { } 0 0 0
60 0 return $url;
61
62 } elsif ($url =~ m{^tcp://(\d+\.\d+\.\d+\.\d+):(\d+)$}) {
63 0 my ($ip, $port, $option, $timeout) = ($1, $2, @args);
64
65 # Check if option and timeout is set at the same time
66 0 ▶ if($option and $timeout) {
Branch: 1 branch
BranchTrueFalseTotal
if ($option and $timeout) 0 0 0
Condition0%0/3
$option and $timeout
!ll&&!rl&&r
000
MC/DC0%0/2
$option and $timeout
$option $timeout
Truth table0%0/3
A and B
A= $optionB= $timeout
ABresult
0X0
100
111
67 0 croak "Can't both have non-blocking and timeout";
68 }
69
70 0 ▶ return (IO::Socket::INET->new(
Branch: 1 branch
BranchTrueFalseTotal
$option ? : 0 0 0
Condition0%0/2
'IO::Socket::INET'->new('Proto', 'tcp', 'PeerAddr', $ip, 'PeerPort', $port, 'Blocking', $option ? 0 : 1, 'Timeout', $timeout) || croak("Connecting to ${url}: $!")
l!l
00
MC/DC0%0/1
'IO::Socket::INET'->new('Proto', 'tcp', 'PeerAddr', $ip, 'PeerPort', $port, 'Blocking', $option ? 0 : 1, 'Timeout', $timeout) || croak("Connecting to ${url}: $!")
'IO::Socket::INET'->new('Proto', 'tcp', 'PeerAddr', $ip, 'PeerPort', $port, 'Blocking', $option ? 0 : 1, 'Timeout', $timeout)
Truth table0%0/2
A
A= 'IO::Socket::INET'->new('Proto', 'tcp', 'PeerAddr', $ip, 'PeerPort', $port, 'Blocking', $option ? 0 : 1, 'Timeout', $timeout)
Aresult
11
00
71 Proto => 'tcp',
72 PeerAddr => $ip,
73 PeerPort => $port,
74 Blocking => ($option?0:1),
75 Timeout => $timeout,
76 ) or croak "Connecting to $url: $!");
77  
78 } elsif ($url =~ m{^unix(?:_(dgram))?://(.+)$}) {
79 0 my ($dgram, $file, $nonblocking) = ($1, $2, @args);
80 0 ▶ return (IO::Socket::UNIX->new(
Branch: 2 branches
BranchTrueFalseTotal
$dgram ? : 0 0 0
$nonblocking ? : 0 0 0
Condition0%0/2
'IO::Socket::UNIX'->new($dgram ? ('Type', 2) : (), 'Blocking', $nonblocking ? 0 : 1, 'Peer', $file) || croak("Connecting to ${url}: $!")
l!l
00
MC/DC0%0/1
'IO::Socket::UNIX'->new($dgram ? ('Type', 2) : (), 'Blocking', $nonblocking ? 0 : 1, 'Peer', $file) || croak("Connecting to ${url}: $!")
'IO::Socket::UNIX'->new($dgram ? ('Type', 2) : (), 'Blocking', $nonblocking ? 0 : 1, 'Peer', $file)
Truth table0%0/2
A
A= 'IO::Socket::UNIX'->new($dgram ? ('Type', 2) : (), 'Blocking', $nonblocking ? 0 : 1, 'Peer', $file)
Aresult
11
00
81 ($dgram?(Type => SOCK_DGRAM):()),
82 Blocking => ($nonblocking?0:1),
83 Peer => $file,
84 ) or croak "Connecting to $url: $!");
85
86 } elsif ($url =~ m{^udp://(\d+\.\d+\.\d+\.\d+)?:?(\d+)?$}) {
87 0 my ($ip, $port, $option) = ($1, $2, @args);
88 0 ▶ return (IO::Socket::INET->new(
Branch: 3 branches
BranchTrueFalseTotal
$ip ? : 0 0 0
$port ? : 0 0 0
$option ? : 0 0 0
Condition0%0/2
'IO::Socket::INET'->new('Proto', 'udp', 'Type', 2, $ip ? ('PeerAddr', $ip) : (), $port ? ('PeerPort', $port) : (), 'Blocking', $option ? 0 : 1) || croak("Connecting to ${url}: $!")
l!l
00
MC/DC0%0/1
'IO::Socket::INET'->new('Proto', 'udp', 'Type', 2, $ip ? ('PeerAddr', $ip) : (), $port ? ('PeerPort', $port) : (), 'Blocking', $option ? 0 : 1) || croak("Connecting to ${url}: $!")
'IO::Socket::INET'->new('Proto', 'udp', 'Type', 2, $ip ? ('PeerAddr', $ip) : (), $port ? ('PeerPort', $port) : (), 'Blocking', $option ? 0 : 1)
Truth table0%0/2
A
A= 'IO::Socket::INET'->new('Proto', 'udp', 'Type', 2, $ip ? ('PeerAddr', $ip) : (), $port ? ('PeerPort', $port) : (), 'Blocking', $option ? 0 : 1)
Aresult
11
00
89 Proto => 'udp',
90 Type => SOCK_DGRAM,
91 ($ip?(PeerAddr => $ip):()),
92 ($port?(PeerPort => $port):()),
93 Blocking => ($option?0:1),
94 ) or croak "Connecting to $url: $!");
95  
96
97 } elsif ($url =~ m{^(perl|perlroot|perl2|perlroot2)(header)?://(.+)$}) {
98 0 my ($type, $path, $header, @callargs) = ($1, $3, $2, @args);
99
100 0 ▶ if(!defined $header) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $header) { } 0 0 0
101 # TODO: rename process to something a little more elegant then this.
102 0 $header = q(
103 use warnings;
104 use strict;
105
106 my $fd = shift;
107 my $module = shift;
108 if (not defined $fd) { die "Usage: $0 FILE_DESCRIPTOR MODULE_FILE [ ARGS ]"; }
109
110 open my $sock, "+<&=", $fd or die "Cannot open fd $fd\n";
111
112 sub init_clients {
113 my ($rpc) = @_;
114 $rpc->add_client($sock);
115 return $sock;
116 }
117
118 $0="$module";
119
120 do $module or die "Cannot load $module or $module did not return 1: $@\n";
121 );
122 } else {
123 0 $header = shift @args;
124 }
125  
126 0 ▶ -e "$path" or die "File $path does not exist\n";
Branch: 1 branch
BranchTrueFalseTotal
-e "$path" or die "File $path does not exist\n" 0 0 0
127 0 my ($parent, $child);
128 {
129 0 local $^F = 1024; # avoid close-on-exec flag being set
130 0 ▶ socketpair($parent, $child, AF_UNIX, SOCK_STREAM, PF_UNSPEC)
Branch: 1 branch
BranchTrueFalseTotal
socketpair $parent, $child, 1, 1, 0 or die "socketpair: $!" 0 0 0
131 or die "socketpair: $!";
132 }
133
134 0 my ($readerOUT, $readerERR, $writerOUT, $writerERR);
135 0 ▶ if($type =~ /open2/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /open2/) 0 0 0
136 0 ▶ pipe $readerOUT, $writerOUT or die;
Branch: 1 branch
BranchTrueFalseTotal
pipe $readerOUT, $writerOUT or die 0 0 0
137 0 ▶ pipe $readerERR, $writerERR or die;
Branch: 1 branch
BranchTrueFalseTotal
pipe $readerERR, $writerERR or die 0 0 0
138 }
139  
140 0 my $client_pid = fork;
141 0 ▶ if ($client_pid == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($client_pid == 0) 0 0 0
142 # child process
143 0 close $parent;
144 0 ▶ if($type =~ /open2/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /open2/) 0 0 0
145 0 ▶ close $readerOUT or die;
Branch: 1 branch
BranchTrueFalseTotal
close $readerOUT or die 0 0 0
146 0 ▶ close $readerERR or die;
Branch: 1 branch
BranchTrueFalseTotal
close $readerERR or die 0 0 0
147 0 ▶ open STDOUT, ">&", $writerOUT or die;
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">&", $writerOUT or die 0 0 0
148 0 ▶ open STDERR, ">&", $writerERR or die;
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">&", $writerERR or die 0 0 0
149 }
150
151 0 ▶ if($type !~ /perlroot/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type =~ /perlroot/) 0 0 0
152 # FIXME: This should be done by drop_privileges function
153 0 ▶ if($UID == 0 or $GID == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($RPC::Async::URL::UID == 0 or $RPC::Async::URL::GID == 0) 0 0 0
Condition0%0/3
$RPC::Async::URL::UID == 0 or $RPC::Async::URL::GID == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$RPC::Async::URL::UID == 0 or $RPC::Async::URL::GID == 0
$RPC::Async::URL::UID == 0 $RPC::Async::URL::GID == 0
Truth table0%0/3
A or B
A= $RPC::Async::URL::UID == 0B= $RPC::Async::URL::GID == 0
ABresult
1X1
011
000
154 my $user = $ENV{SUDO_USER} || $ENV{RPC_ASYNC_URL_USER}
155 0 ▶ or die "RPC_ASYNC_URL_USER environment variable not set";
Branch: 1 branch
BranchTrueFalseTotal
my $user = $ENV{"SUDO_USER"} || $ENV{"RPC_ASYNC_URL_USER"} or die "RPC_ASYNC_URL_USER environment variable not set" 0 0 0
Condition0%0/3
$ENV{'SUDO_USER'} || $ENV{'RPC_ASYNC_URL_USER'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'SUDO_USER'} || $ENV{'RPC_ASYNC_URL_USER'}
$ENV{'SUDO_USER'} $ENV{'RPC_ASYNC_URL_USER'}
Truth table0%0/3
A || B
A= $ENV{'SUDO_USER'}B= $ENV{'RPC_ASYNC_URL_USER'}
ABresult
1X1
011
000
156 0 drop_privileges($user);
157 }
158 }
159  
160 0 my ($file, $dir) = fileparse $path;
161  
162 0 chdir $dir;
163 # TODO: Do diff against default and only add what is not std.
164 0 exec $^X, (map { '-I'.$_ } @INC), "-we", $header,
165 fileno($child),
166 $file, @callargs;
167 0 die "executing perl: $!\n";
168 }
169 0 close $child;
170 0 ▶ if($type =~ /open2/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /open2/) 0 0 0
171 0 close $writerOUT;
172 0 close $writerERR;
173 }
174  
175 0 fcntl $parent, F_SETFD, FD_CLOEXEC;
176  
177 0 ▶ if(wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
178 0 return ($parent, $client_pid, $readerOUT, $readerERR);
179 } else {
180 0 return $parent;
181 }
182  
183 } elsif ($url =~ m{^(open2)://(.+)$}) {
184 0 my ($dir, $file) = ($1, $2);
185 0 my ($type, $cmd, @callargs) = ($1, $2, @args);
186
187 0 ▶ pipe my $readerOUT, my $writerOUT or die;
Branch: 1 branch
BranchTrueFalseTotal
pipe my $readerOUT, my $writerOUT or die 0 0 0
188 0 ▶ pipe my $readerERR, my $writerERR or die;
Branch: 1 branch
BranchTrueFalseTotal
pipe my $readerERR, my $writerERR or die 0 0 0
189  
190 0 my $pid = fork;
191 0 ▶ if ($pid == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 0) 0 0 0
192 0 ▶ close $readerOUT or die;
Branch: 1 branch
BranchTrueFalseTotal
close $readerOUT or die 0 0 0
193 0 ▶ close $readerERR or die;
Branch: 1 branch
BranchTrueFalseTotal
close $readerERR or die 0 0 0
194
195 0 ▶ open STDOUT, ">&", $writerOUT or die;
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">&", $writerOUT or die 0 0 0
196 0 ▶ open STDERR, ">&", $writerERR or die;
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">&", $writerERR or die 0 0 0
197 0 exec $cmd, @callargs;
198 0 die;
199 }
200  
201 0 close $writerOUT;
202 0 close $writerERR;
203 0 return ($readerOUT, $readerERR, $pid);
204
205 } elsif ($url =~ m{^cfd://(\d+)$}) {
206 0 my ($fd) = ($1);
207  
208 0 ▶ open my $sock, "+<&=", $fd
Branch: 1 branch
BranchTrueFalseTotal
open my $sock, "+<&=", $fd or die "Listening on ${url}: $!" 0 0 0
209 or die "Listening on $url: $!";
210 0 return $sock;
211
212 } else {
213 0 croak "Cannot parse url: $url";
214 }
215 }
216  
217 =head2 B<url_absolute($cwd, @urls)>
218  
219 Make urls paths absolute, by adding $cwd to all urls.
220  
221 =cut
222  
223 0 ▶sub url_absolute {
Subroutine url_absolute: not called CC=4 SCAR=30.0
Pod documented
224 0 my ($cwd, @urls) = @_;
225
226 0 my @results;
227 0 foreach my $url (@urls) {
228 0 ▶ if($url =~ /^([^:]+\:\/\/)(.+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ m[^([^:]+\://)(.+)$]) { } 0 0 0
229 0 push(@results, "$1$cwd/$2");
230 } else {
231 0 return;
232 }
233 }
234
235 0 ▶ if(wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
236 0 return @results;
237 } else {
238 0 return $results[0];
239 }
240 }
241  
242 =head2 B<url_disconnect($cwd, @urls)>
243  
244 Wait for url to disconnect
245  
246 =cut
247  
248 0 ▶sub url_disconnect {
Subroutine url_disconnect: not called CC=2 SCAR=17.9
Pod documented
249 0 my ($fh, $pid) = @_;
250 0 ▶ waitpid $pid, 0 if $pid;
Branch: 1 branch
BranchTrueFalseTotal
if $pid 0 0 0
251 }
252  
253 =head2 B<url_explode($cwd, @urls)>
254  
255 Explode URL components into smaller bits, only supports tcp and udp.
256  
257 =cut
258  
259 0 ▶sub url_explode {
Subroutine url_explode: not called CC=2 SCAR=17.9
Pod documented
260 0 my ($url) = @_;
261  
262 0 ▶ if ($url =~ m{^(tcp|udp)://(\d+\.\d+\.\d+\.\d+)?:?(\d+)?$}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ m[^(tcp|udp)://(\d+\.\d+\.\d+\.\d+)?:?(\d+)?$]) { } 0 0 0
263 0 return ($1,$2,$3);
264 } else {
265 0 return;
266 }
267 }
268  
269 =head2 B<url_listen($cwd, @urls)>
270  
271 Same as connect, just returns a listening socket instead. Only tcp://, udp://
272 and unix:// supported.
273  
274 =cut
275  
276 0 ▶sub url_listen {
Subroutine url_listen: not called CC=14 SCAR=53.5
Pod documented
277 0 my ($url, $nonblocking) = @_;
278
279 0 ▶ if ($url =~ m{^tcp://(\d+\.\d+\.\d+\.\d+):(\d+)$}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($url =~ m[^tcp://(\d+\.\d+\.\d+\.\d+):(\d+)$]) { } 0 0 0
elsif ($url =~ m[^unix(?:_(dgram))?://(.+)$]) { } 0 0 0
elsif ($url =~ m[^udp://(\d+\.\d+\.\d+\.\d+)?:?(\d+)?$]) { } 0 0 0
280 0 my ($ip, $port) = ($1, $2);
281 0 ▶ return (IO::Socket::INET->new(
Branch: 1 branch
BranchTrueFalseTotal
$nonblocking ? : 0 0 0
Condition0%0/2
'IO::Socket::INET'->new('Proto', 'tcp', 'LocalAddr', $ip, 'LocalPort', $port, 'Blocking', $nonblocking ? 0 : 1, 'ReuseAddr', 1, 'Listen', 4096) || croak("Listening to ${url}: $!")
l!l
00
MC/DC0%0/1
'IO::Socket::INET'->new('Proto', 'tcp', 'LocalAddr', $ip, 'LocalPort', $port, 'Blocking', $nonblocking ? 0 : 1, 'ReuseAddr', 1, 'Listen', 4096) || croak("Listening to ${url}: $!")
'IO::Socket::INET'->new('Proto', 'tcp', 'LocalAddr', $ip, 'LocalPort', $port, 'Blocking', $nonblocking ? 0 : 1, 'ReuseAddr', 1, 'Listen', 4096)
Truth table0%0/2
A
A= 'IO::Socket::INET'->new('Proto', 'tcp', 'LocalAddr', $ip, 'LocalPort', $port, 'Blocking', $nonblocking ? 0 : 1, 'ReuseAddr', 1, 'Listen', 4096)
Aresult
11
00
282 Proto => 'tcp',
283 LocalAddr => $ip,
284 LocalPort => $port,
285 Blocking => ($nonblocking?0:1),
286 ReuseAddr => 1,
287 Listen => SOMAXCONN,
288 ) or croak "Listening to $url: $!");
289  
290 } elsif ($url =~ m{^unix(?:_(dgram))?://(.+)$}) {
291 0 my ($dgram, $file) = ($1, $2);
292 0 unlink($file);
293 0 ▶ return (IO::Socket::UNIX->new(
Branch: 3 branches
BranchTrueFalseTotal
$dgram ? : 0 0 0
!$dgram ? : 0 0 0
$nonblocking ? : 0 0 0
Condition0%0/2
'IO::Socket::UNIX'->new($dgram ? ('Type', 2) : (), !$dgram ? ('Listen', 4096) : (), 'Blocking', $nonblocking ? 0 : 1, 'Local', $file) || croak("Listening to ${url}: $!")
l!l
00
MC/DC0%0/1
'IO::Socket::UNIX'->new($dgram ? ('Type', 2) : (), !$dgram ? ('Listen', 4096) : (), 'Blocking', $nonblocking ? 0 : 1, 'Local', $file) || croak("Listening to ${url}: $!")
'IO::Socket::UNIX'->new($dgram ? ('Type', 2) : (), !$dgram ? ('Listen', 4096) : (), 'Blocking', $nonblocking ? 0 : 1, 'Local', $file)
Truth table0%0/2
A
A= 'IO::Socket::UNIX'->new($dgram ? ('Type', 2) : (), !$dgram ? ('Listen', 4096) : (), 'Blocking', $nonblocking ? 0 : 1, 'Local', $file)
Aresult
11
00
294 ($dgram?(Type => SOCK_DGRAM):()),
295 (!$dgram?(Listen => SOMAXCONN):()),
296 Blocking => ($nonblocking?0:1),
297 Local => $file,
298 ) or croak "Listening to $url: $!");
299  
300 } elsif ($url =~ m{^udp://(\d+\.\d+\.\d+\.\d+)?:?(\d+)?$}) {
301 0 my ($ip, $port) = ($1, $2);
302 0 ▶ return (IO::Socket::INET->new(
Branch: 3 branches
BranchTrueFalseTotal
$ip ? : 0 0 0
$port ? : 0 0 0
$nonblocking ? : 0 0 0
Condition0%0/2
'IO::Socket::INET'->new('Proto', 'udp', $ip ? ('LocalAddr', $ip) : (), $port ? ('LocalPort', $port) : (), 'Blocking', $nonblocking ? 0 : 1, 'ReuseAddr', 1) || croak("Listening to ${url}: $!")
l!l
00
MC/DC0%0/1
'IO::Socket::INET'->new('Proto', 'udp', $ip ? ('LocalAddr', $ip) : (), $port ? ('LocalPort', $port) : (), 'Blocking', $nonblocking ? 0 : 1, 'ReuseAddr', 1) || croak("Listening to ${url}: $!")
'IO::Socket::INET'->new('Proto', 'udp', $ip ? ('LocalAddr', $ip) : (), $port ? ('LocalPort', $port) : (), 'Blocking', $nonblocking ? 0 : 1, 'ReuseAddr', 1)
Truth table0%0/2
A
A= 'IO::Socket::INET'->new('Proto', 'udp', $ip ? ('LocalAddr', $ip) : (), $port ? ('LocalPort', $port) : (), 'Blocking', $nonblocking ? 0 : 1, 'ReuseAddr', 1)
Aresult
11
00
303 Proto => 'udp',
304 ($ip?(LocalAddr => $ip):()),
305 ($port?(LocalPort => $port):()),
306 Blocking => ($nonblocking?0:1),
307 ReuseAddr => 1,
308 ) or croak "Listening to $url: $!");
309
310 } else {
311 0 croak "Cannot parse url: $url";
312 }
313 }
314  
315 1 1;
316  
317 =head1 AUTHOR
318  
319 Jonas Jensen <jonas@infopro.dk>, Troels Liebe Bentsen <troels@infopro.dk>
320  
321 =cut
322  
323 =head1 COPYRIGHT
324  
325 Copyright(C) 2005-2007 Troels Liebe Bentsen
326  
327 Copyright(C) 2005-2007 Jonas Jensen
328  
329 This library is free software; you can redistribute it and/or modify
330 it under the same terms as Perl itself.
331  
332 =cut
333  
334 # vim: et sw=4 sts=4 tw=80
↑ Summary Async/Coderef.pm »