1
2# This is a test script of IPC::LDT,
3# using file handles to check the
4# delay feature.
5
6
7# load modules
8use IPC::LDT;
9use FileHandle;
10
11# display number of test
12print "1..1\n";
13
14# build temporary filename
15my $file="/tmp/.$$.ipc.ldt.tmp";
16
17# write messages
18{
19 # open file
20 open(O, ">$file") or die "[Fatal] Could not open $file for writing.\n";
21
22 # build LDT object
23 my $ldt=new IPC::LDT(handle=>*O) or die "[Fatal] Could not build LDT object.\n";
24
25 # install delay filter
26 $ldt->delay(sub {$_[0]->[0]%2});
27
28 # send the messages
29 $ldt->send($_) for 1..10;
30
31 # stop delay and send delayed messages
32 $ldt->undelay;
33
34 # close the temporary file
35 close(O);
36}
37
38
39# read messages
40{
41 # open file
42 open(I, $file) or die "[Fatal] Could not open $file for reading.\n";
43
44 # build LDT object
45 my $ldt=new IPC::LDT(handle=>*I) or die "[Fatal] Could not build LDT object.\n";
46
47 # read the messages
48 my @read;
49 $read[$_-1]=$ldt->receive for 1..10;
50
51 # perform the checks
52 print join('-', @read) eq '2-4-6-8-10-1-3-5-7-9' ? 'ok' : 'not ok', "\n";
53
54 # close the temporary file
55 close(I);
56}
57
58# clean up
59unlink $file;
60